Communitygithub.com

gtars

使用 Gtars 在 Python、Rust 和 CLI 中進行本地基因組區間模型、集合代數、重疊與計數、共識與覆蓋率、分詞、片段處理以及 refget/BEDbase 規劃。

gtars 是什麼?

本技能詳細說明了如何使用 Gtars 套件(0.9.x 版)在本地執行基因組區間與參考序列的運算。它涵蓋了 Python 綁定、Rust 原生函式庫以及 CLI 工具,特別強調數據合約、套件驗證與安全的工作流程。核心功能包括基於 BED 格式的區間集合代數(如 reduce、setdiff、union、jaccard)、覆蓋率計算、分詞器(tokenizer)用於將區間編碼,以及 refget 序列儲存與擷取。此技能也內建了本地檢查腳本(如 bed_validator.py),並嚴格規範了輸入資料的座標系統(0-based half-open)、組裝版本、contig 名稱比較與排序順序。使用前必須先通過信任門檻驗證 PyPI/crates.io 上發行的確切版本與 SHA-256 雜湊,並在隔離環境中執行。此外,本技能明確指出了 0.9.2 版中尚未公開的 API(如 Python 中的 uniwig)以及已棄用的舊 API 名稱,提醒使用者依據文件與實際運行時期的簽名進行測試。它亦屬於 Scientific Agent Skills 的一部分,若在研究中有實質貢獻,應引用相關論文。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/K-Dense-AI/scientific-agent-skills/tree/main/skills/gtars

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

gtars 是做什麼的?

Gtars 提供了原生的 Rust 實現、Python 綁定以及一個以功能閘控(feature-gated)的 gtars 二進位檔,用於基因組區間和參考序列相關工作。請從內建的本地檢查工具開始;只有在資料合約、來源出處、資源限制和副作用都明確之後,才呼叫上游程式碼。

已驗證的快照(2026-07-23)

  • Python: gtars==0.9.2,發佈於 2026-06-17,Requires-Python >=3.10。
  • Rust 元套件(meta-crate): gtars=0.9.0,發佈於 2026-06-15。其預設功能集為空。
  • CLI 套件/二進位檔: gtars-cli=0.9.0;安裝後的二進位檔名稱為 gtars。
  • 直接 refget 套件: gtars-refget=0.9.1,發佈於 2026-06-17。gtars=0.9.0 本身鎖定了其元件發佈集,其中包含 refget 0.9.0。
  • 上游有意將工作區套件、Python 綁定和 CLI 獨立進行版本管理。不要假設匹配的版本號碼代表匹配的成品。
  • 已發佈的文件變更記錄(changelog)停留在 0.5.1 版。此處的 API 範例已針對 0.9.2 的 Python stub/runtime 以及 v0.9.0 的 CLI/Rust 原始碼進行過驗證。

license: MIT 欄位涵蓋此技能。已發佈的 gtars 套件聲明為 MIT,而 GitHub 儲存庫的根目錄目前顯示為 BSD-2-Clause;請在重新散佈前,驗證確切成品的授權條款。

原生程式碼信任閘門與精確鎖定

Python wheel 包含一個 PyO3 原生擴充。Cargo 安裝會編譯一個原生二進位檔,並可能執行相依套件的建置腳本。將這兩種路徑都視為程式碼執行:

  1. 確認官方 PyPI/crates.io/GitHub 擁有者與不可變版本。
  2. 檢視檔案名稱、平台標籤、發佈來源出處、授權條款和 SHA-256。GitHub 的 v0.9.0 二進位檔發佈包含每個壓縮檔的 .sha256 側車檔案(sidecars)。
  3. 絕不執行未經信任的預建二進位檔、wheel、原始碼樹、Cargo 建置腳本或壓縮檔安裝程式。請使用隔離環境以及 CPU/RAM/磁碟/時間限制。
  4. 將鎖定檔和成品雜湊值與分析清單一同保留。

完成該審查後,建立一個隔離的 Python 環境:

uv venv --python 3.11 .venv-gtars
uv pip install --dry-run --python .venv-gtars/bin/python "gtars==0.9.2"
uv pip install --python .venv-gtars/bin/python "gtars==0.9.2"
.venv-gtars/bin/python -c \
  "import gtars; assert gtars.__version__ == '0.9.2'; print(gtars.__version__)"

對於已審查的 CLI 原始碼發佈:

cargo install gtars-cli --version 0.9.0 --locked
gtars --version
gtars --help

對於 Rust 專案,確切鎖定包裝套件,並僅啟用所需功能:

[dependencies]
gtars = { version = "=0.9.0", default-features = false, features = [
  "core", "overlaprs", "uniwig", "tokenizers", "refget"
] }

僅在需要較新的直接元件 API 且相容性已測試過時,才直接使用 gtars-refget = "=0.9.1"。不要將這些鎖定取代為 Git 分支或未經審查的發佈版本。

基因組資料合約

在每次操作前套用此合約:

  1. 座標: BED 區間是 0 基底且半開的:[start, end)。要求 0 <= start < end <= contig_length。Gtars 座標是 u32,因此拒絕大於 4,294,967,295 的值。
  2. 組裝(Assembly): 記錄組裝的 accession/version 以及確切染色體大小(chromosome-sizes)或 refget 序列收集元數據的 SHA-256。絕不從檔案名稱或 chr 前綴推斷組裝。
  3. Contigs: 精確比較名稱。1 和 chr1、交替位點(alternate loci)、誘餌序列(decoys)以及粒線體別名(mitochondrial aliases)不可互換。僅可作為單獨審查的轉換進行重新命名或 liftover。
  4. 排序: 保留原始檔案,然後在操作需要時,依據染色體大小順序和數值 start/end 對副本進行排序。Python 的 RegionSet(path) 目前在載入時會按字典順序對 contig 和 start 進行排序;之後請勿依賴原始行順序。
  5. 鏈(Strand): BED6 使用 +、- 或 .。Region.rest 會保留結尾的 BED 欄位,但基於檔案的 Python RegionSet 目前會將其獨立的 strands 向量初始化為 *。數個集合操作會丟棄鏈資訊。當鏈在科學上有意義時,請在外部保留並驗證鏈。
  6. 重複/相鄰: 明確選擇策略。reduce() 和 consensus 會合併重疊以及相鄰的區間;普通的半開重疊不會將 [0,10) 和 [10,20) 視為重疊。

首先執行本地驗證器:

python3 -B scripts/bed_validator.py \
  --input data.bed.gz \
  --assembly GRCh38.p14 \
  --chrom-sizes GRCh38.p14.chrom.sizes \
  --require-sorted

安全的本地工作流程

  1. 盤點本地檔案、校驗和、組裝、contig 字典、座標系統、鏈策略、患者/重複組以及預期輸出。
  2. 驗證 BED/片段並估算工作量。先用一個小的合成檔案進行試驗。
  3. 從文件說明的表面範圍中選擇 Python、CLI 或 Rust;不要憑猜測翻譯 API 名稱。
  4. 設定輸入位元組/記錄/檔案、執行緒/任務、記憶體、暫存磁碟、輸出大小和運行時間的硬性限制。
  5. 在專用輸出目錄中執行。除非明確批准覆寫,否則拒絕衝突。
  6. 重新驗證輸出的排序、邊界、行數、校驗和與來源出處。

當前的 Python 核心

導入應來自子模組,而非 gtars 頂層:

from gtars.models import Region, RegionSet

query = RegionSet.from_regions(
    [
        Region(chr="chr1", start=100, end=200, rest=None),
        Region(chr="chr1", start=300, end=400, rest=None),
    ],
    strands=["+", "-"],
)
universe = RegionSet.from_vectors(
    ["chr1", "chr1"],
    [150, 500],
    [350, 600],
)

counts = query.count_overlaps(universe)       # 每個查詢區間一個計數
flags = query.any_overlaps(universe)          # 每個查詢區間一個布林值
indices = query.find_overlaps(universe)       # 指向 universe 的索引
pieces = query.intersect_all(universe)        # 所有交集片段
fraction = query.coverage(universe)           # 查詢鹼基對被覆蓋的比例

RegionSet.sort() 會變動自身並回傳 None。集合代數包括 reduce、setdiff、pintersect(按索引配對)、concat、union、jaccard、coverage、overlap_coefficient、intersect_all、closest、cluster 和 gaps。在依賴排序或鏈之前,請閱讀 references/python-api.md。

共識(Consensus)是另一個模組中的 Python 綁定:

from gtars.genomic_distributions import consensus

rows = consensus([query, universe])
# rows: [{"chr": ..., "start": ..., "end": ..., "count": ...}, ...]

訊號追蹤(Signal-track)生成並未以 gtars.uniwig 的形式在 Python 0.9.2 中公開;請使用已審查的 CLI 或 Rust API。RegionSet.coverage() 是一個鹼基對集合度量,而不是 WIG/bigWig 生成器。

分詞器、片段與參考儲存

預設僅使用本地建構器:

from gtars.models import RegionSet
from gtars.tokenizers import Tokenizer

tokenizer = Tokenizer.from_bed("reviewed-universe.bed")
regions = RegionSet("local-query.bed")
tokens = tokenizer.tokenize(regions)
encoding = tokenizer(regions)
ids = encoding["input_ids"]

當參數不是既有的本地目錄時,Tokenizer.from_pretrained(name) 會聯絡 Hugging Face 並寫入其快取;它沒有公開 revision 或 cache 參數。請取得明確批准,透過已審查的機制擷取一個不可變的 revision,驗證校驗和,然後傳遞本地快照目錄。請參閱 references/tokenizers.md。

對於 refget,優先使用 RefgetStore.in_memory() 或 RefgetStore.open_local(path)。open_remote(cache_path, remote_url) 會聯絡遠端服務、建立/使用本地快取,並執行按需的範圍讀取。請參閱 references/refget.md。

網路與快取閘門

此技能中不包含隱含的下載或快取寫入。在進行任何具備網路能力的上游呼叫之前:

  • 針對確切的主機、端點、資料和快取,取得明確的使用者批准;
  • 將 HTTPS 主機加入允許清單,並拒絕未經審查的重定向;
  • 記錄不可變的 revision/識別碼、擷取時間、預期的 SHA-256 和領域摘要、組裝 accession、大小配額與來源出處;
  • 揭露可能離開已批准環境的敏感 BED 座標、條碼、樣本標籤和參考選擇;
  • 在使用前將下載的內容視為不受信任並進行驗證。

重要的副作用:

  • RegionSet(path) 支援 HTTP;一個不存在的本地字串可能會被視為 URL。在建構前,請檢查本地路徑是否存在。
  • Tokenizer.from_pretrained 可能將 universe.bed.gz 下載到 Hugging Face 快取中。
  • RefgetStore.on_disk 會建立/寫入一個儲存體。open_remote 會載入遠端元資料,並預設啟用持久化。
  • 即使在建構客戶端時,gtars bbcache 也會建立快取目錄。快取/下載命令使用 BBCLIENT_CACHE(預設為 ~/.bbcache)和 BEDBASE_API(預設為 https://api.bedbase.org)。

敏感元數據與洩漏

基因組區間、稀有位點、條碼、樣本名稱、表現型和組裝選擇可能具有識別性。將完整路徑和原始座標排除在日誌之外;預設的捆綁報告會將路徑匿名化,僅輸出計數/校驗和。

首先按患者/捐贈者凍結分割(split),然後將所有技術和生物重複保留在同一個分割中。僅在訓練資料上擬合共識集、宇宙(universe)、分詞器、縮放、閾值和 QC 規則。不要從所有樣本建立一個宇宙然後再分割:這會洩漏驗證/測試位點的支援資訊(locus support)。請分別記錄排除的樣本和重複彙總。

內建確定性 CLI

所有六個輔助工具都拒絕 URL、遍歷、符號連結和特殊檔案;套用了位元組、記錄、檔案、座標和工作線程的上限;不使用網路或匯入 gtars;也不寫入輸出檔案。計畫(Plans)包含固定的 argv 模板,且從不實際啟動它們。

python3 -B scripts/bed_validator.py --help
python3 -B scripts/execution_plan.py --help
python3 -B scripts/tokenizer_manifest.py --help
python3 -B scripts/refget_digest_plan.py --help
python3 -B scripts/coverage_preflight.py --help
python3 -B scripts/artifact_inspector.py --help

在不產生位元組碼的情況下執行合成測試:

PYTHONDONTWRITEBYTECODE=1 python3 -B -m unittest discover \
  -s tests/gtars -p 'test_*.py' -v

1.1 版中已移除的遷移陷阱

不要使用包含 gtars.RegionSet、RegionSet.from_bed、TreeTokenizer、gtars.igd.build_index、gtars.uniwig.coverage_from_bed、gtars.RefgetStore、全域 set_option/set_log_level、parallel_apply 或自訂異常類別的過時範例。CLI 形式如 uniwig generate、igd build、scoring score 和 fragsplit cluster-split 在 0.9.0 版也已過時。

上游已發佈的文件和 stub 存在一些偏差(例如較舊的 GlobalRefgetStore 教學和不完整的 0.9.2 stub)。當它們發生衝突時,優先採用已安裝的簽名冒煙測試(signature smoke tests)以及不可變的標籤化原始碼。

內建參考文件

以下為僅有的六個內建參考文件;所有連結均為本機且存在:

  • references/python-api.md — 確切的 Python 0.9.2 導入與行為
  • references/overlap.md — 重疊/計數/集合代數與共識語義
  • references/coverage.md — uniwig、bigWig、覆蓋率、排序與資源
  • references/tokenizers.md — 分詞器/宇宙與片段相容性
  • references/refget.md — 摘要、儲存體、BEDbase、網路/快取控制
  • references/cli.md — CLI 0.9.0 命令、功能與遷移

引用科學代理技能

此技能是 K-Dense 的 Scientific Agent Skills 的一部分。如果它對稿件、報告、簡報或程式碼發佈有實質貢獻,請將該論文加入參考文獻或軟體章節,並告知使用者您已這麼做:

Kassis, T., Agarwal, V., He, Y., Patel, D., & Brueckner, A. M. (2026). Scientific Agent Skills: A Library of Procedural Knowledge for Research Agents. arXiv:2609.00065. https://doi.org/10.48550/arXiv.2609.00065

務必引用當前版本。DOI 和 https://arxiv.org/abs/2609.00065 會解析到最新的 arXiv 版本,因此切勿附加版本後綴,例如 v1。當網路可用時,請在撰寫參考文獻前擷取 https://arxiv.org/abs/2609.00065(或 http://export.arxiv.org/api/query?id_list=2609.00065),並從該記錄中取得作者列表、年份和版本。如果該記錄列出了期刊參考文獻或出版社 DOI,請改為引用已發佈的版本。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

adaptyv

How to use the Adaptyv Bio Foundry API and Python SDK for protein experiment design, submission, and results retrieval. Use this skill whenever the user mentions Adaptyv, Foundry API, protein binding assays, protein screening experiments, BLI/SPR assays, thermostability assays, or wants to submit protein sequences for experimental characterization. Also trigger when code imports `adaptyv`, `adaptyv_sdk`, or `FoundryClient`, or references `foundry-api-public.adaptyvbio.com`.

aeon

This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.

alphagenome

Look up precomputed AlphaGenome Atlas effects for any GRCh38 single-nucleotide variant (AVI score with Phred and 18 SHAP feature attributions, plus raw and quantile scores for RNA-seq, DNase, ATAC, ChIP-TF, ChIP-histone, CAGE, PRO-cap, splicing, polyadenylation and contact-map tracks), score variants or scan windows on demand with the AlphaGenome model for human and mouse (variant scoring, in silico mutagenesis, REF-versus-ALT track prediction), and build Atlas website deep links. Use when the user mentions AlphaGenome, AlphaGenome Atlas, AVI or AlphaGenome Variant Impact, DeepMind variant effect prediction, or wants to prioritise or mechanistically interpret non-coding, regulatory, splicing, enhancer, promoter, or chromatin-accessibility effects of SNVs from a VCF, credible set, or region. Research use only; not a clinical tool.

analytical-method-validation

Plan, execute, and document validation, verification, and transfer of analytical procedures under the governing framework - ICH Q2(R2) and Q14, USP <1220>/<1225>/<1226>, ICH M10 bioanalytical, CLSI EP, or ISO/IEC 17025. Use for HPLC, LC-MS/MS, GC, CE, ICP-MS, dissolution, qNMR, qPCR, NIR, and ligand binding or cell-based assays whenever the question is whether a procedure is fit for its intended purpose. Triggers include

anndata

Data structure for annotated matrices in single-cell analysis. Use when working with .h5ad files or integrating with the scverse ecosystem. This is the data format skill—for analysis workflows use scanpy; for probabilistic models use scvi-tools; for population-scale queries use cellxgene-census.

arbor

Autonomously improve a real artifact (code, training recipe, agent harness, data pipeline, prompt) against an objective and an evaluator, using Hypothesis Tree Refinement (HTR) from the Arbor paper. Use this whenever someone wants to iteratively optimize something over many experiments without overfitting — e.g.

arboreto

Infer gene regulatory networks (GRNs) from gene expression data using scalable algorithms (GRNBoost2, GENIE3). Use when analyzing transcriptomics data (bulk RNA-seq, single-cell RNA-seq) to identify transcription factor-target gene relationships and regulatory interactions. Supports distributed computation for large-scale datasets.

astropy

Core Python library for astronomy and astrophysics workflows that need Astropy APIs, including units/quantities, coordinates, FITS I/O, tables, time systems, WCS, and cosmology. Use when implementing or debugging astronomical data analysis code with Astropy.

autoskill

Observe the user

benchling-integration

Benchling Python SDK and REST API integration for registry entities, inventory, ELN entries, workflows, Benchling Apps, and Data Warehouse queries. Use when automating lab data with benchling-sdk or the v2 API.

bgpt-paper-search

Search scientific papers and retrieve structured experimental data extracted from full-text studies via the BGPT MCP server. Returns 25+ fields per paper including methods, results, sample sizes, quality scores, and conclusions. Use for literature reviews, evidence synthesis, and finding experimental details not available in abstracts alone.

bids

>

biopython

Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use bioservices.

bioservices

Unified Python interface to 40+ bioinformatics services. Use when querying multiple databases (UniProt, KEGG, ChEMBL, Reactome) in a single workflow with consistent API. Best for cross-database analysis, ID mapping across services. For quick single-database lookups use gget; for sequence/file manipulation use biopython.

bulk-rnaseq

End-to-end bulk RNA-seq orchestrator — takes raw FASTQ reads through QC and trimming (FastQC, fastp/Trim Galore), alignment and quantification (STAR, Salmon, featureCounts), assembles a gene-level counts matrix, then hands off to differential expression (pydeseq2), pathway/GSEA enrichment (pathway-enrichment), and publication figures (scientific-visualization). Use whenever the user has bulk RNA-seq reads or quant output and wants a complete, reproducible differential-expression workflow — e.g.

cellxgene-census

Query the CZ CELLxGENE Census programmatically for versioned public single-cell and spatial transcriptomics data. Use when you need population-scale cell metadata, gene expression slices, Census summary counts, source H5AD URIs/downloads, embeddings, spatial Census data, or reference atlas comparisons across organisms, tissues, diseases, assays, and cell types. For analyzing your own local single-cell data use scanpy, anndata, or scvi-tools.

cirq

Google quantum computing framework. Use when targeting Google Quantum AI hardware, designing noise-aware circuits, or running quantum characterization experiments. Best for Google hardware, noise modeling, and low-level circuit design. For IBM hardware use qiskit; for quantum ML with autodiff use pennylane; for physics simulations use qutip.

citation-management

Comprehensive citation management for academic research. Search OpenAlex, PubMed, and Google Scholar for papers, extract accurate metadata, validate citations, and generate properly formatted BibTeX entries. This skill should be used when you need to find papers, verify citation information, convert DOIs to BibTeX, or ensure reference accuracy in scientific writing.

clinical-decision-support

Prepare and validate research-only clinical decision-support evaluation, evidence-profile, cohort, survival, biomarker/model, privacy, and governance artifacts. Use for aggregate or synthetic research documentation and traceability—not patient care or live clinical operation.

clinical-reports

Create safety-bounded draft structures and run local deterministic checks for clinical case, diagnostic, trial, safety, and aggregate research reports. Use only with synthetic, de-identified, or aggregate inputs and verified source-fact manifests; every output requires qualified review.

相關技能