Claude Skill MartBrowse skillsWhat is a Skill?
Back to list

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 & AnalyticsAdvanced33,0303,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.bcftools for 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

  1. "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.
  2. "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.
  3. "My CRAM file won't decode" — walks through reference_filename and when REF_PATH/REF_CACHE is actually appropriate.

· · · Install guide · · ·

Install in the Claude app (no terminal)
  1. Download the ZIP with the button below.
  2. In Claude, open Settings → Capabilities and turn on 'Code execution and file creation'. (one time)
  3. Go to Customize → Skills → + → 'Upload a skill' and upload the ZIP.
Download 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.

  1. Open a terminal (Terminal on macOS, WSL recommended on Windows).
  2. Clone the skills repository:
    git clone https://github.com/K-Dense-AI/scientific-agent-skills.git
    
  3. Create your skills folder and copy just this skill:
    mkdir -p ~/.claude/skills
    cp -r scientific-agent-skills/skills/pysam ~/.claude/skills/
    
  4. Install the pinned Python dependency:
    uv pip install "pysam==0.24.0"   # or: pip install "pysam==0.24.0"
    
  5. Verify the runtime:
    python -c "import pysam; print(pysam.__version__, pysam.__samtools_version__)"
    
  6. Restart Claude Code and ask something like "inspect this BAM file with pysam" to trigger the skill.
  7. For CRAM work, have the exact matching reference FASTA (plus its .fai index) ready before you start.