pysam

Reads and writes bioinformatics data via a unified, HTSlib-backed Python API.

15|2|Updated Dec 17, 2025
One-click install
npx skills add https://github.com/rubensliv/k-dense-ai --skill pysam-rubensliv
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pysam
Source: https://github.com/rubensliv/k-dense-ai/tree/main/scientific-skills/pysam
Command: npx skills add https://github.com/rubensliv/k-dense-ai --skill pysam-rubensliv

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Pysam provides fast, Pythonic access to genomic data formats for reading, writing, and manipulating sequencing data across SAM/BAM/CRAM, VCF/BCF, and FASTA/FASTQ files.

Core Features & Use Cases

  • Read and write alignment and variant files using a unified Python API to simplify pipelines.
  • Query regions, fetch sequences, and perform pileup or coverage analyses on indexed or non-indexed data.
  • Integrate with command-line tools like samtools/bcftools for end-to-end workflows in bioinformatics.

Quick Start

Install pysam and run a simple script to iterate reads in a BAM 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 write SAM, BAM, and CRAM files in Python?

You can read and write SAM, BAM, and CRAM files in Python using a unified HTSLIB-backed API. This provides fast, Pythonic access to manipulate sequencing data across alignment, variant, and sequence formats.

Can I query specific regions in a BAM file using Python?

Yes, you can query regions in a BAM file using Python with tabix indexing support. This allows you to fetch sequences and perform pileup or coverage analyses directly on indexed datasets.

Does pysam work with VCF and BCF variant files?

Yes, pysam works with VCF and BCF variant files. It provides a unified Python API for variant handling, allowing you to read, write, and manipulate variant data alongside alignment files.

What is the best way to integrate samtools and bcftools workflows in Python?

The best way to integrate samtools and bcftools workflows in Python is by using a unified HTSLIB-backed API. This allows you to build end-to-end bioinformatics pipelines that combine programmatic access with command-line tool functionality.

How do I extract sequences from FASTA and FASTQ files in Python?

You can extract sequences from FASTA and FASTQ files in Python using a unified genomic file API. This approach streamlines pipelines by enabling sequence extraction, region queries, and basic QC within the same environment.

Can I perform pileup and coverage analysis on non-indexed genomic data?

Yes, you can perform pileup and coverage analysis on non-indexed genomic data. The API supports processing both indexed and non-indexed datasets across SAM, BAM, CRAM, and variant formats.