pysam

pysam is a skill for Claude Code from K-Dense-AI/scientific-agent-skills. It costs 65 tokens per session (3,419 once invoked), scanned A, original, MIT.

A Python interface to HTSlib for working with common genomic files, including DNA sequences, sequencing alignments, genetic variants, and indexed annotation tables. HTSlib is a library used by many genomics command-line tools.

In plain words
What is it for?
Use it to process SAM, BAM, CRAM, VCF, BCF, FASTA, FASTQ, BED, GFF, and GTF files, including coverage calculations, pileups, and region-based queries.
Why use it?
It lets programs stream, query, filter, index, and write large sequencing datasets without implementing each file format from scratch.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Good fit Use it to process SAM, BAM, CRAM, VCF, BCF, FASTA, FASTQ, BED, GFF, and GTF files, including coverage calculations, pileups, and region-based queries.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/k-dense-ai/scientific-agent-skills/pysam
About the project

Scientific Agent Skills is a collection of reusable procedures that give AI agents capabilities for scientific research across areas such as biology, chemistry, medicine, and drug discovery. It is used by researchers and by people building AI scientist workflows with compatible coding agents. The catalogue contains many of the project's skills and supporting instructions.

K-Dense-AI/scientific-agent-skills · 58,946 stars · on GitHub · arxiv.org

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add K-Dense-AI/scientific-agent-skills --skill pysam
Clone the repo
git clone --depth 1 https://github.com/K-Dense-AI/scientific-agent-skills

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for pysam

README.md
[![agentmods](https://agentmods.dev/badge/skills/k-dense-ai/scientific-agent-skills/pysam/github.svg)](https://agentmods.dev/skills/k-dense-ai/scientific-agent-skills/pysam)
Your own site
<a href="https://agentmods.dev/skills/k-dense-ai/scientific-agent-skills/pysam"><img src="https://agentmods.dev/badge/skills/k-dense-ai/scientific-agent-skills/pysam/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for pysam

Your own site · 80×15
<a href="https://agentmods.dev/skills/k-dense-ai/scientific-agent-skills/pysam"><img src="https://agentmods.dev/badge/skills/k-dense-ai/scientific-agent-skills/pysam.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 65 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,419 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • Socket pass 21 Oct 2026
  • Snyk pass 21 Oct 2026
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00065 $0.03419
Opus 5.5 $0.00026 $0.01368
Sonnet 5.5 $0.00013 $0.00684
Haiku 4.5 $0.00006 $0.00342

Measured 1mo ago against content hash afc275bbeb08, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

pysam scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

The scan reads SKILL.md. This mod also ships 4 executable files (scripts/alignment_qc.py, scripts/filter_alignments.py, scripts/inspect_hts.py, …), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

bam.fetch(region="chr1:100-199") # 1-based inclusive
Origin

Copies of this mod

1 near-identical copy found in the catalogue:

  • pysam — 100% identical, 50 lines differ
skills/pysam/SKILL.md · 366 lines

How it starts

The opening of the file, as written. The whole thing — 366 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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:

  1. Identify the real format, compression, sort order, and available index.
  2. Decide whether coordinates are numeric Python coordinates or a region string. Do not mix them.
  3. For CRAM, identify the exact reference assembly and FASTA.
  4. Prefer indexed region access; use sequential iteration only when intended.
  5. Preserve headers when writing and write to a new path by default.
  6. State filtering semantics: mapping/base quality, flags, overlap handling, duplicate handling, and pileup depth cap.

For unfamiliar files, start with the bundled read-only inspector:

python scripts/inspect_hts.py sample.bam
python scripts/inspect_hts.py cohort.vcf.gz
python scripts/inspect_hts.py reference.fa

Bundled Scripts

Script Purpose Typical call
scripts/inspect_hts.py Metadata-only inspection for alignment, variant, FASTA, FASTQ, and tabix files python scripts/inspect_hts.py sample.cram --reference ref.fa
scripts/alignment_qc.py Streaming aggregate read/QC counts as JSON python scripts/alignment_qc.py sample.bam --max-records 100000
scripts/variant_summary.py Streaming variant, FILTER, and genotype summary as JSON python scripts/variant_summary.py cohort.vcf.gz --region chr1:1-1000000
scripts/filter_alignments.py Filter SAM/BAM/CRAM without changing record order python scripts/filter_alignments.py input.bam output.bam --exclude-secondary

Read the full file on GitHub · 366 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago Changed · +14 lines · +1 tokens per session afc275bbeb08
  2. 2mo ago Changed · +4 lines f90843f67c84
  3. 2mo ago First seen · 348 lines · 64 tokens per session scan A 4cbfdbd80b4a

Subscribe to this mod's changes

pysam is a skill published in the GitHub repository K-Dense-AI/scientific-agent-skills (58,946 stars, last pushed 7d ago), licensed MIT. It adds 65 tokens to every session and 3,419 once invoked, about $0.0003 per session on Opus 5.5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

pysam compared with skills from other repositories

pysam next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
pysamK-Dense-AI/scientific-agent-skillsSkill59k7d agoMITA65Claude Code
discovery-toolboxdekan-aleksandr/biodiscovery-skillsSkill113mo agoMITA122Claude Code
rdkit-qsar-pharmacophoreYuliaNuzhnenko/bioinformatics-agent-skillsSkill103mo agoMITA46Claude Code, Codex
discovery-directordekan-aleksandr/biodiscovery-skillsSkill113mo agoMITA114Claude Code
bulk-rnaseq-counts-to-de-deseq2hossainlab/omics-skillsSkill24mo agoMITA141Claude Code, Codex
seurat-skillAgents365-ai/seurat-skillSkill46mo agoMITA167Claude Code, Codex
gene-protein-expression-matrix-normalizationaipoch/medical-research-skillsSkill2.1k10d agoMITA63Claude Code, Codex