pysam

Parse and analyze NGS alignment, variant, and sequence files with pysam.

4|Updated Mar 2, 2026
One-click install
npx skills add https://github.com/shushuzn/Rairos --skill pysam-shushuzn
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pysam
Source: https://github.com/shushuzn/Rairos/tree/main/skills/pysam
Command: npx skills add https://github.com/shushuzn/Rairos --skill pysam-shushuzn

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Pysam streamlines NGS analysis by giving a Pythonic interface to read, query, and write genomic alignment, variant, and sequence data without stitching together many separate command-line tools.

Core Features & Use Cases

  • Alignment (SAM/BAM/CRAM) handling: Fetch reads by genomic region, filter by mapping attributes, compute coverage, and run pileup-style analyses for depth and per-position statistics.
  • Variant (VCF/BCF) handling: Iterate and query variants, access INFO/FORMAT fields and genotypes, and filter or write modified VCF/BCF outputs.
  • Sequence (FASTA/FASTQ) handling: Random-access reference FASTA sequences (with indexing) and sequentially process FASTQ reads with quality scores.
  • Integrated workflows: Combine BAM + VCF + FASTA for tasks like validating variants with read support, annotating variants with coverage, and extracting sequence contexts around loci.

Quick Start

Use the pysam skill to compute per-base coverage for chr1 from 1,000,000 to 1,000,500 from a BAM file named tumor.bam.

Frequently Asked Questions about pysam

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

FAQPage Schema
How do I calculate per-base coverage from a BAM file in a specific genomic region?

To calculate per-base coverage from a BAM file, use AlignmentFile to fetch reads by genomic region and run pileup-style analyses. This provides depth and per-position statistics for your specified coordinates.

How do I query and filter VCF variants by genotype and INFO fields?

To query and filter VCF variants, use VariantFile to iterate variants and access INFO/FORMAT fields and genotypes. You can apply filters and write modified VCF/BCF outputs.

What is the best way to extract FASTA sequences with random access by coordinate?

The best way to extract FASTA sequences with random access is by using FastaFile with an indexed reference, enabling programmatic sequence extraction with proper coordinate handling.

Can I integrate BAM, VCF, and FASTA files to validate variants with read support?

Yes, you can integrate BAM, VCF, and FASTA files to validate variants with read support. This workflow also allows annotating variants with coverage and extracting sequence contexts around loci.

Do I need indexed files to retrieve reads from a genomic region in SAM or CRAM format?

Yes, indexed files are required for retrieving reads from a genomic region in SAM or CRAM format. AlignmentFile relies on indexed random access to fetch reads by coordinates.