pysam

Read and query SAM/BAM/CRAM, VCF/BCF, and FASTA/FASTQ files programmatically.

21|2|Updated Dec 8, 2025
One-click install
npx skills add https://github.com/silverstein/claude-scientific-skills-desktop --skill pysam-silverstein
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pysam
Source: https://github.com/silverstein/claude-scientific-skills-desktop/tree/main/corpus/pysam
Command: npx skills add https://github.com/silverstein/claude-scientific-skills-desktop --skill pysam-silverstein

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Pysam streamlines genomic data handling by letting you read, query, transform, and write core NGS file formats without stitching together separate tools.

Core Features & Use Cases

  • Alignment processing (SAM/BAM/CRAM): fetch reads by region, compute coverage/pileups, filter by mapping/QC flags, and write updated alignments.
  • Variant processing (VCF/BCF): iterate variants, query by region, inspect INFO/FORMAT/sample genotypes, and create filtered or annotated VCF outputs.
  • Sequence processing (FASTA/FASTQ): extract reference sequences by coordinates and perform sequential FASTQ parsing for downstream QC or preprocessing.
  • Integrated pipelines: combine BAM + VCF + FASTA to validate alleles, calculate depth/DP at variant loci, and extract variant context sequences for reporting.

Quick Start

Use pysam to read an indexed BAM file and fetch reads overlapping chr1:1000-2000, then compute coverage for the same region.

Frequently Asked Questions about pysam

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fetch reads from a BAM file using a specific genomic region?

You can fetch overlapping reads from an indexed BAM file by querying specific genomic coordinates using a unified API, applying correct coordinate conventions to ensure deterministic region-based read extraction.

What is the best way to calculate pileup coverage for NGS pipelines?

Pileup-based coverage estimation is the best way to calculate depth across genomic regions in NGS pipelines, achieved by programmatically reading alignment files and computing per-base coverage directly.

How do I filter VCF variants based on INFO fields and sample genotypes?

To filter VCF variants, iterate through variant records to inspect INFO/FORMAT fields and sample genotypes, then write out a filtered or annotated VCF output using a unified variant file API.

Can I extract reference sequences by coordinates from a FASTA file?

Yes, you can extract reference sequences by coordinates from a FASTA file by using sequence processing abstractions to query specific genomic regions and retrieve the corresponding nucleotide context.

Why do coordinate conventions matter when processing genomic data files?

Coordinate conventions matter because genomic data manipulation requires deterministic file operations, and using incorrect coordinate systems during region-based read extraction or variant queries will return inaccurate alignment or sequence data.

Does random access work when querying CRAM and BCF files in NGS pipelines?

Random access works for querying CRAM and BCF files in NGS pipelines, provided the files are properly indexed, allowing deterministic region-based extraction for both alignment and variant processing tasks.