If you're processing NGS data, this is the Python wrapper around htslib you'll reach for constantly. It handles SAM/BAM/CRAM alignments, VCF/BCF variants, and FASTA/FASTQ sequences with a clean interface for fetching regions, running pileups, and calculating coverage. The 0-based coordinates take a minute to internalize (except when using region strings, which are 1-based like samtools), but once you do, it's straightforward. You'll need index files for random access, which is standard for this domain. It really shines when you're chaining operations across file types, like validating variants against aligned reads or extracting reference context around mutation sites.

skills.sh installs
2K
GitHub stars
56.6K
last updated
Aug 21, 2026

Install

$ npx -y skills add k-dense-ai/scientific-agent-skills --skill pysam --agent claude-code

Installs into .claude/skills of the current project.

Files

pysam

Overview

Use pysam for low-level, streaming access to HTSlib-supported genomic formats:

  • AlignmentFile and AlignedSegment for SAM/BAM/CRAM
  • VariantFile, VariantHeader, and VariantRecord for VCF/BCF
  • FastaFile for indexed FASTA and FastxFile for sequential FASTA/FASTQ
  • TabixFile for BGZF-compressed, tabix-indexed BED/GFF/GTF/custom tables
  • pysam.samtools and pysam.bcftools for wrapped command dispatchers

Current upstream baseline: pysam 0.24.1 (7 September 2026), wrapping HTSlib/samtools/bcftools 1.24. Read references/sources.md before updating version-specific guidance.

Installation

Use the pinned release for reproducible work:

uv pip install "pysam==0.24.1"

Confirm the runtime:

import pysam

print(pysam.__version__)           # 0.24.1
print(pysam.__samtools_version__)  # 1.24

Prebuilt wheels are available for supported macOS and Linux platforms. A source build needs a C compiler and HTSlib build dependencies; read the official installation guide linked from references/sources.md.

First Decide

Before writing code:

Sponsors

Details

Repository
github.com/k-dense-ai/scientific-agent-skills
Categories
Testing & QA, Documentation, AI & Agent Building, Python
First seen
Jun 3, 2026

More from k-dense-ai/scientific-agent-skills

All 137
1minimax-ai avatarflutter-devminimax-ai/skillsFlutter cross-platform development guide covering widget patterns, Riverpod/Bloc state management, GoRouter navigation, performance optimization, and platform-s2Kskills.sh installs
2gracefullight avatarbacktesting-trading-strategiesgracefullight/stock-checkerBacktest crypto and traditional trading strategies against historical data. Calculates performance metrics (Sharpe, Sortino, max drawdown), generates equity cur2Kskills.sh installs
3k-dense-ai avatargtarsk-dense-ai/scientific-agent-skillsUse Gtars for local genomic interval models and set algebra, overlaps and counts, consensus and coverage, tokenization, fragment processing, and refget/BEDbase 2Kskills.sh installs
4k-dense-ai avatarpolars-biok-dense-ai/scientific-agent-skillsHigh-performance genomic interval operations and bioinformatics file I/O on Polars DataFrames. Overlap, nearest, merge, coverage, complement, subtract for BED/V2Kskills.sh installs
5onmax avatarts-libraryonmax/nuxt-skillsUse when authoring TypeScript libraries or npm packages - covers project setup, package.json exports, build tooling (tsdown/unbuild), API design patterns, type 2Kskills.sh installs
6nashsu avatarautoclinashsu/autocli-skillUse autocli CLI to interact with 55+ social/content websites (HackerNews, Reddit, Twitter/X, Bilibili, Zhihu, Weibo, Xiaohongshu, YouTube, Medium, Substack, Dou2Kskills.sh installs