pysam

Read, manipulate, and write genomic datasets in formats like BAM, VCF, and FASTA using Python.

1|Updated Apr 29, 2026
One-click install
npx skills add https://github.com/cultivarium/hermes-starter-kit --skill pysam-cultivarium
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pysam
Source: https://github.com/cultivarium/hermes-starter-kit/tree/main/skills/pysam
Command: npx skills add https://github.com/cultivarium/hermes-starter-kit --skill pysam-cultivarium

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Pysam provides a Python toolkit for reading, manipulating, and writing genomic datasets (BAM/SAM/CRAM, VCF/BCF, FASTA/FASTQ) with an ergonomic interface to htslib, enabling reproducible, scriptable workflows in genomics research and data analysis.

Core Features & Use Cases

  • Read, filter, and write alignment files (SAM/BAM/CRAM) to support mapping quality checks, coverage analysis, and variant-aware workflows.
  • Read and write variant files (VCF/BCF) for genotype querying, filtering, annotation, and sample-level analyses.
  • Access reference sequences and read from indexed FASTA/FASTQ data, perform region queries, and integrate with tabix-indexed data.
  • Build end-to-end pipelines that combine BAM, VCF, and FASTA data to compute statistics, generate reports, or drive downstream analyses.

Quick Start

Install pysam and run a minimal example to read a BAM file and print basic info.

Frequently Asked Questions about pysam

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

FAQPage Schema
How do I read and filter BAM files in Python for coverage analysis?

Use the AlignmentFile class to read and filter BAM files in Python, enabling mapping quality checks, region queries, and coverage calculations. It provides an ergonomic interface to htslib for scriptable genomics workflows.

What is the best way to query VCF variants by region in Python?

The best way to query VCF variants by region in Python is using the VariantFile class with proper tabix indexing. This enables genotype querying, filtering, annotation, and sample-level analyses for reproducible genomics.

Do I need to index my FASTA and BAM files before running genomic region queries?

Yes, proper indexing is required before running genomic region queries. You must generate BAM/BAI, VCF/BCF tabix, and FASTA fai indexes to enable the core classes to perform region queries and variant-aware processing.

Can I process CRAM alignment files and write manipulated genomic data back?

Yes, you can read, manipulate, and write CRAM alignment files. The toolkit supports reading, filtering, and writing SAM/BAM/CRAM formats to support mapping quality checks, coverage analysis, and variant-aware genomic workflows.

How do I access indexed FASTA sequences for NGS data analysis pipelines?

Access indexed FASTA sequences for NGS pipelines using the FastaFile class. It reads indexed FASTA/FASTQ data, performs region queries, and integrates with tabix-indexed data to support reproducible sequencing workflows.

Why does my BAM file region query fail without a BAI index?

BAM file region queries fail without a BAI index because the toolkit relies on proper indexing to perform region queries. Generating a BAI index enables the AlignmentFile class to execute coverage calculations and variant-aware processing.