pysam

Read, write, and analyze SAM/BAM/CRAM, VCF/BCF, and FASTA/FASTQ genomic data via Python.

1|Updated Jan 26, 2026
One-click install
npx skills add https://github.com/Victory-Hugo/S2-Agent-Skill --skill pysam-victory-hugo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pysam
Source: https://github.com/Victory-Hugo/S2-Agent-Skill/tree/main/skills/genomics/pysam
Command: npx skills add https://github.com/Victory-Hugo/S2-Agent-Skill --skill pysam-victory-hugo

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Pysam provides a Python interface to HTSlib for reading, writing, and manipulating genomic data formats such as SAM/BAM/CRAM, VCF/BCF, and FASTA/FASTQ, enabling reproducible NGS data workflows from Python.

Core Features & Use Cases

  • Read and write SAM/BAM/CRAM alignment data and VCF/BCF variant data for analysis pipelines.
  • Query reference sequences and perform region-based extraction from indexed FASTA/FASTQ, VCF, and BAM files.
  • Build end-to-end genomic pipelines for variant discovery, coverage analysis, and QC tasks using Python.

Quick Start

Use pysam to open a BAM file and fetch reads in a region, printing read names. Install with pip and run a short Python snippet to iterate over the alignments.

Frequently Asked Questions about pysam

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

FAQPage Schema
How do I read and fetch reads from a BAM file in Python?

To read and fetch reads from a BAM file in Python, use pysam to open the file and call fetch on a region. This provides a high-level interface to iterate over alignment data and print read names for NGS analysis.

Can I query VCF and BCF variant data using Python?

You can query VCF and BCF variant data using Python through pysam. It provides a Python interface to HTSlib, allowing you to read, write, and manipulate variant data directly within standard genomic analysis pipelines.

What is the best way to perform region-based extraction from indexed FASTA files?

The best way to perform region-based extraction from indexed FASTA files is using pysam. It enables querying reference sequences and extracting specific regions directly, supporting reproducible NGS data workflows from Python.

Does pysam support CRAM files for sequencing alignment data?

Pysam supports CRAM files for sequencing alignment data alongside SAM and BAM formats. It leverages HTSlib bindings to read, write, and manipulate these genomic data formats efficiently within standard Python environments.

How do I calculate coverage and perform QC tasks for NGS datasets?

To calculate coverage and perform QC tasks for NGS datasets, use pysam to build end-to-end genomic pipelines in Python. It allows region-based queries and coverage calculations across HTS datasets for variant discovery.

Do I need to install HTSlib separately to use pysam?

You do not need to install HTSlib separately to use pysam. The implementation relies on HTSlib bindings and is installed via pip using pysam, designed to run in standard Python environments without external dependencies.