pysam Genomic File Toolkit
Guides correct pysam usage for reading, querying, filtering, and writing SAM/BAM/CRAM, VCF/BCF, FASTA/FASTQ, and tabix data.
Data & AnalyticsAdvanced★ 33,030⑂ 3,248AI score 8/10Last updated: Aug 9, 2026
What it does
Gives Claude a precise playbook for handling HTSlib-backed genomic formats through the Python pysam library.
- SAM/BAM/CRAM access, filtering, pileup, and writing via
AlignmentFile/AlignedSegment - VCF/BCF header safety, sample subsetting, and genotype handling via
VariantFile - Indexed FASTA, streaming FASTQ, and tabix/BGZF interval tables
- Delegation to
pysam.samtools/pysam.bcftoolsfor sort, index, merge, view, quickcheck - Four bundled scripts (
inspect_hts.py,alignment_qc.py,variant_summary.py,filter_alignments.py) that emit JSON summaries and refuse to overwrite outputs
The standout section is the coordinate contract: numeric coordinates are 0-based half-open while samtools-style region strings are 1-based inclusive, plus explicit notes on pileup() defaults (max_depth=8000, base-quality thresholds), CRAM 3.1 defaults, and the removal of automatic EBI reference lookups.
Who it's for
- Bioinformaticians scripting directly against BAM/CRAM/VCF files
- Pipeline engineers automating QC and filtering steps for sequencing runs
- Graduate students comfortable with samtools CLI but new to the pysam API
- Teams upgrading an existing environment to pysam 0.24 and auditing behavior changes
Example uses
- "Count reads over chr1:1,000-2,000 in sample.bam with MAPQ ≥ 30, excluding secondary and supplementary alignments" — produces
fetch()code with the right coordinate base and flag checks. - "Keep only sample_A and sample_B, filter to PASS variants, and write a new VCF" — applies
subset_samples()before record iteration and copies the header safely. - "My CRAM file won't decode" — walks through
reference_filenameand whenREF_PATH/REF_CACHEis actually appropriate.
· · · Install guide · · ·
Install in the Claude app (no terminal)
- Download the ZIP with the button below.
- In Claude, open Settings → Capabilities and turn on 'Code execution and file creation'. (one time)
- Go to Customize → Skills → + → 'Upload a skill' and upload the ZIP.
Install in Claude Code
Let Claude do it — paste this into Claude Code
Install the skill I found on Claude Skill Mart. Copy the skills/pysam folder from the GitHub repo K-Dense-AI/scientific-agent-skills into my ~/.claude/skills/pysam/. When it's done, tell me in one line what this skill can do.
Install with a command instead
git clone https://github.com/K-Dense-AI/scientific-agent-skills.git && mkdir -p ~/.claude/skills && cp -r scientific-agent-skills/skills/pysam ~/.claude/skills/⚠ This is a third-party skill. Check the source repository before installing.
- Open a terminal (Terminal on macOS, WSL recommended on Windows).
- Clone the skills repository:
git clone https://github.com/K-Dense-AI/scientific-agent-skills.git - Create your skills folder and copy just this skill:
mkdir -p ~/.claude/skills cp -r scientific-agent-skills/skills/pysam ~/.claude/skills/ - Install the pinned Python dependency:
uv pip install "pysam==0.24.0" # or: pip install "pysam==0.24.0" - Verify the runtime:
python -c "import pysam; print(pysam.__version__, pysam.__samtools_version__)" - Restart Claude Code and ask something like "inspect this BAM file with pysam" to trigger the skill.
- For CRAM work, have the exact matching reference FASTA (plus its
.faiindex) ready before you start.
View source on GitHub ↗License: MIT