polars-bio
できること
このツールは、ゲノム配列(DNA上の遺伝子など)を比較したり操作したりするためのものです。重なり合う配列や最も近い配列を見つけたり、連続する配列を結合したり、カバレッジを計算したりといった操作ができます。
使う場面
- ✓遺伝子のリストを比較して、共通するものを見つけたいとき。
- ✓シーケンシングでカバーされなかったDNA領域を見つけたいとき。
- ✓重なり合うゲノム配列の断片を結合したいとき。
スキルのリンク
https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/polars-bio/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“リストAの遺伝子のうち、リストBの遺伝子と重なるものはどれですか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
このツールは、BED、VCF、BAMなど分子生物学で一般的に使われる形式のゲノムデータを読み込み、表の形に整理します。その後、これらのゲノム配列の位置を比較する数学的な演算を適用します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
polars-bio
Use this skill for genomic interval arithmetic and bioinformatics file I/O through Polars and DataFusion. It targets polars-bio 0.36.0, tested with Polars 1.44.2 on Python 3.13. The upstream package requires Polars >=1.37.1, PyArrow >=23.0.1,<25, DataFusion >=53,<54 and polars-config-meta >=0.3.2,<1. Keep this environment separate from packages needing incompatible Arrow or DataFusion releases.
uv pip install "polars-bio==0.36.0" "polars==1.44.2"
# Optional pandas interoperability (requires pandas >=3):
uv pip install "polars-bio[pandas]==0.36.0" "polars==1.44.2"
Verify new releases against the official release notes and package requirements. The examples below with named files are templates: substitute actual files and check their schemas. The synthetic interval example and small local format round trips were executed during this review.
Workflow
- Record the assembly, contig naming, coordinate convention, strand policy and unit of analysis. Identical contig names do not prove identical assemblies.
- Choose readers by format; BCF has its own reader. Inspect schemas and source metadata before selecting attributes or genotypes.
- Normalize all inputs to one coordinate system and validate their bounds.
- Choose pair output, hit counts, covered bases or read depth deliberately.
- Filter and project lazily, then inspect a small result before scaling up.
- Validate output counts and boundaries against a hand-computable fixture; preserve IDs, coordinate metadata and provenance when saving results.
Coordinate contract
The default is 1-based closed, including converted BED reads. Use
use_zero_based=True on genomic readers for 0-based half-open output.
This argument converts positions; it is not only a metadata label. For example,
BED [0,10) becomes [1,10] by default and remains [0,10) with the override.
SAM text POS is 1-based, whereas BAM stores its alignment position internally
as 0-based. Both readers expose the requested output convention.
For manually constructed DataFrames, metadata labels existing numbers and
does not convert them. Converting closed [s,e] to half-open means s-1,e.
Set metadata only after conversion. Never convert twice.
import polars as pl
import polars_bio as pb
pb.set_option("datafusion.bio.coordinate_system_zero_based", True)
pb.set_option("datafusion.bio.coordinate_system_check", True)
query = pl.DataFrame({
"query_id": ["q1", "q2", "q3"],
"chrom": ["chr1", "chr1", "chr2"],
"start": [0, 10, 0], "end": [10, 20, 10],
})
target = pl.DataFrame({
"chrom": ["chr1", "chr1"], "start": [5, 8], "end": [12, 15],
})
for frame in (query, target):
frame.config_meta.set(coordinate_system_zero_based=True)
pairs = pb.overlap(query, target).collect()
counts = pb.count_overlaps(query, target).collect().sort("query_id")
covered = pb.coverage(query, target).collect().sort("query_id")
assert pairs.height == 4
assert counts["count"].to_list() == [2, 2, 0]
assert covered["coverage"].to_list() == [5, 5, 0]
Require non-null contigs, integer positions and valid positive-length intervals
(0 <= start < end in half-open form), within the chosen assembly. Do not silently
turn points/insertions into nonempty intervals: choose the biological convention.
Mismatched input metadata raises CoordinateSystemMismatchError; missing metadata
warns and uses the global setting by default, or raises MissingCoordinateSystemError
in strict mode. Inspect pb.get_metadata(frame) after transformations and SQL.
See configuration.
Choose the operation
| Question | Operation | Interpretation |
|---|---|---|
| Which interval pairs intersect? | overlap(a, b) |
Inner pair join; a query can appear repeatedly |
| Which query rows have any hit? | overlap(a, b, overlap_output="left", distinct_output=True) |
One hit per original query row; duplicate input rows retain identity |
| How many target intervals intersect each query? | count_overlaps(a, b) |
Target-record count, including zero for no hit |
| How many query bases are covered? | coverage(a, b) |
Length of the union of target intersections; not read depth |
| Which targets are closest? | nearest(a, b, k=1) |
Up to k neighbors, with nullable target/distance for no candidate |
…
よくある質問
「ゲノムインターバル」とは何ですか?
染色体やより大きな配列上で、開始点と終了点によって定められたDNAの区間のことです。
対応しているファイル形式は何ですか?
BED、VCF、BAM、GFF、GTF、FASTA、FASTQなど、分子生物学で使われるさまざまな形式に対応しています。
位置の数え方(0から始めるか1から始めるか)はどう扱われますか?
初期設定では1-based(閉区間)の方式を使用します。必要に応じて0-based(半開区間)の方式に設定することもできます。これは一部のツールで一般的な方式です。
詳細
作者による元の説明
Performs genomic interval overlap, nearest, merge, coverage, complement and subtraction on Polars DataFrames, and reads or writes BED, VCF, BCF, BAM, CRAM, GFF, GTF, FASTA and FASTQ data. Use for coordinate-aware genomic joins, read-depth analysis, lazy bioinformatics I/O, SQL queries or migration from bioframe.
人気
- GitHubのスター
- 51k
- ランキング
- #3529
- ライセンス
- MIT
- 更新日
- 2026/10/15
コメント
- …
このリポジトリの他のスキル
13c-metabolic-flux
51k炭素13同位体トレーシングのデータを使って代謝フラックスを推定します。細胞の代謝や生化学経路の分析に役立ちます。
adaptyv
51kAdaptyv APIを使ってタンパク質の特性評価実験を設計します。コストの見積もり、配列の提出、ラボの結果の監視を支援します。
aeon
51k時系列データに対して機械学習のタスクを実行します。逐次データの分類、予測、異常検知、パターンの発見に役立ちます。
alphagenome
51k遺伝的変異に対して、事前に計算されたゲノム上の効果を検索します。スコアと説明を提供し、変異がゲノムに与える影響を理解するのに役立ちます。