pysam

Process SAM/BAM/CRAM, VCF/BCF, and FASTA/FASTQ files via Python.

48|6|Updated Mar 9, 2026
One-click install
npx skills add https://github.com/qinyan-ai/qinyan-academic-skills --skill pysam-qinyan-ai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pysam
Source: https://github.com/qinyan-ai/qinyan-academic-skills/tree/main/skills/05-%E7%94%9F%E7%89%A9%E4%BF%A1%E6%81%AF%E4%B8%8E%E5%9F%BA%E5%9B%A0%E7%BB%84%E5%AD%A6/pysam
Command: npx skills add https://github.com/qinyan-ai/qinyan-academic-skills --skill pysam-qinyan-ai

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Pysam provides a Python interface to read, manipulate, and write genomic data formats (SAM/BAM/CRAM, VCF/BCF, FASTA/FASTQ), enabling researchers to build custom analyses without low-level file parsing.

Core Features & Use Cases

  • Read and write alignment files (SAM/BAM/CRAM), query regions, and compute coverage.
  • Process variant data (VCF/BCF), filter, annotate, and integrate with sequencing data.
  • Retrieve reference sequences and gene regions from indexed FASTA files for context and validation.
  • Use cases include read QC and coverage analysis, variant discovery workflows, and sequence context extraction in research pipelines.

Quick Start

Install pysam and run a simple fetch to retrieve reads from a BAM region to verify setup.

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 read alignments from a BAM file in Python?

You can read and query read alignments from a BAM file in Python by using a dedicated interface to fetch regions and compute coverage. This requires an indexed BAM file to enable efficient region-based retrieval.

What is the best way to filter and annotate VCF variant data in a Python pipeline?

The best way to filter and annotate VCF variant data in a Python pipeline is using a Python interface that directly processes VCF/BCF files. This allows you to filter variants and integrate them with sequencing data without low-level parsing.

Do I need indexed input files to perform region-based sequence retrieval?

Yes, you need indexed input files for region-based sequence retrieval. FASTA files require .fai indices, BAM and VCF files need their respective indices, and Tabix indexing is required to execute region queries efficiently.

How does Python access genomic data in SAM and CRAM formats?

Python accesses genomic data in SAM and CRAM formats by providing a programming interface that reads, manipulates, and writes these alignment files. This enables researchers to build custom read QC and coverage analyses directly in Python.

Can I extract specific gene regions from a FASTA file for sequence validation?

Yes, you can extract specific gene regions from a FASTA file for sequence validation. By interfacing with indexed FASTA files, you can retrieve reference sequences and specific gene regions to provide context within research pipelines.

What are the limitations of using Python for large-scale genomic data pipelines?

Limitations of using Python for large-scale genomic data pipelines include the strict prerequisite of having properly indexed input files. BAM, VCF, and FASTA files must all have valid indices and Tabix indexing to prevent region query failures.