pysam

Read, write, and query SAM/BAM/CRAM and VCF/BCF genomic data in Python.

21|1|Updated Mar 19, 2026
One-click install
npx skills add https://github.com/OwnLabAI/ownlab --skill pysam-ownlabai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pysam
Source: https://github.com/OwnLabAI/ownlab/tree/main/mart/skills/scientific-skills/pysam
Command: npx skills add https://github.com/OwnLabAI/ownlab --skill pysam-ownlabai

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Pysam provides a Pythonic interface to read, manipulate, and write genomic data formats (SAM/BAM/CRAM, VCF/BCF, FASTA/FASTQ), enabling reproducible, end-to-end analysis pipelines without low-level C bindings.

Core Features & Use Cases

  • Read, write, and query SAM/BAM/CRAM alignment data
  • Read and write VCF/BCF variant data; access INFO/FORMAT fields and genotypes
  • Access reference sequences via indexed FASTA/FASTQ via FastaFile and integration with tabix-indexed data
  • Perform region-based queries, pileups, and basic QC across samples and genomes
  • Use as part of integrated workflows (BAM+VCF, FASTA+VCF, etc.)

Quick Start

Install pysam and run a simple example to read a BAM file and fetch reads in a region.

Frequently Asked Questions about pysam

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

FAQPage Schema
How do I read and query SAM or BAM alignment files in Python?

To read and query SAM or BAM alignment files in Python, you can use a Pythonic interface to htslib that enables region-based fetching, indexing, and pileups efficiently without low-level C bindings.

Can I access INFO and FORMAT fields when reading VCF or BCF variant data?

Yes, you can access INFO and FORMAT fields when reading VCF or BCF variant data, allowing you to manipulate genotypes and variant records directly within reproducible Python analysis pipelines.

What is the best way to extract specific regions from an indexed FASTA reference sequence?

The best way to extract specific regions from an indexed FASTA reference sequence is using FastaFile with tabix integration, enabling rapid sequence retrieval and manipulation for genomic workflows.

Does this Python interface to htslib support CRAM files for alignment processing?

Yes, this Python interface to htslib supports CRAM files for alignment processing, allowing you to read, write, and query CRAM data alongside SAM and BAM formats across diverse datasets.

How do I perform pileup analysis and quality control across multiple BAM samples?

You can perform pileup analysis and quality control across multiple BAM samples by applying region-based queries and pileup functions to extract per-base read data for genomic evaluation.