pysam
Skill by davila7
Pysam is a Python module for reading, writing and manipulating genomic files. It covers SAM/BAM/CRAM alignments, VCF/BCF variants and FASTA/FASTQ sequences for NGS data processing pipelines.
Install pysam
Built from the published package, never by AI.
git clone --depth 1 https://github.com/davila7/claude-code-templates /tmp/claude-code-templates && mkdir -p ~/.claude/skills && cp -r /tmp/claude-code-templates/cli-tool/components/skills/scientific/pysam ~/.claude/skills/pysamRun in your terminal. Claude Code loads skills from ~/.claude/skills automatically.
git clone --depth 1 https://github.com/davila7/claude-code-templates /tmp/claude-code-templates && mkdir -p ~/.gemini/antigravity-cli/skills && cp -r /tmp/claude-code-templates/cli-tool/components/skills/scientific/pysam ~/.gemini/antigravity-cli/skills/pysamAntigravity CLI loads skills from ~/.gemini/antigravity-cli/skills, or .agents/skills for one project.
Skills can run scripts on your machine. Some need an API key: check the README.
About
Pysam is a Python module for reading, manipulating, and writing genomic datasets. It handles SAM, BAM and CRAM alignment files, VCF and BCF variant files, and FASTA and FASTQ sequences through a Pythonic interface to htslib. It can also query tabix-indexed files, run pileup analysis for coverage, and execute samtools and bcftools commands.
The skill gives an AI assistant guidance for these tasks, including coordinate conventions, index requirements and common pitfalls. Installation uses uv pip install pysam, and separate reference files cover alignments, variants, sequences and integrated workflows. It is aimed at bioinformatics work on sequencing data, such as alignment processing, variant analysis and quality control. Official documentation is at pysam.readthedocs.io.
Written from the project's SKILL.md and checked against it.
What it can do
- Alignment file operationsOpen and read BAM/SAM/CRAM files, fetch reads by region, filter, and write alignments.
- Variant file operationsRead and write VCF/BCF files, query regions, and access INFO and genotype data.
- Sequence file operationsQuery FASTA reference sequences by coordinates and read FASTQ files with quality scores.
- Integrated workflowsCombine alignment, variant and reference files for coverage and variant validation tasks.
- Coverage and pileup analysisCalculate coverage statistics and run base-by-base pileup analysis on alignments.
- samtools and bcftools accessRun samtools and bcftools commands from Python, such as sort, index, view and bcftools view.
What you need
- Python
- pysam installed with uv pip install pysam
- Index files (.bai, .crai, .fai, .tbi, .csi) for random access
Try asking
- Use pysam to list reads overlapping chr1:1000-2000 in my BAM file
- Write a pysam script that counts variants in a VCF per chromosome
- Extract the reference sequence for chr1 positions 1000-2000 with pysam
Good to know
- Uses 0-based, half-open coordinates, while fetch region strings are 1-based
- Random access needs index files; otherwise use sequential reading with until_eof=True
- Only stdin and stdout are supported for streaming
- Thread safety has not been fully validated
Security check
ANo download-and-run commands, hidden instructions or signs of sending keys out were found.
Checked automatically: cli-tool/components/skills/scientific/pysam/SKILL.md. This looks for known risky patterns and is not a full audit. How grades work
Inside the skill
-
SKILL.md10 KB -
references/alignment_files.md8 KB -
references/common_workflows.md15 KB -
references/sequence_files.md11 KB -
references/variant_files.md9 KB
Alternatives to pysam
All alternatives →Searches arXiv for scientific papers and preprints, extracts their metadata and abstracts, and downloads PDF or HTML full text. Suited to users who need research papers, literature or specific arXiv IDs.
Downloads AlphaFold predicted structures and PAE matrices for a UniProt ID, then reports pLDDT confidence, domain boundaries and disorder. Built for users who already have a UniProt accession.
Queries the QuickGO and Evidence & Conclusion Ontology REST API to map genes to Gene Ontology terms. Built for researchers doing functional annotation and GO hierarchy exploration.
Connects an AI assistant to Peloton to browse fitness classes, check live and archived schedules, and manage workouts. Built for Peloton users who want to plan rides from their assistant.
Queries NCBI Gene through the E-utilities and Datasets API. It helps researchers search genes by symbol or ID, retrieve gene details, and run batch lookups for annotation and functional analysis.
Prepares and launches nf-core/pacsomatic runs for matched tumor-normal PacBio HiFi data starting from unaligned BAM files. It generates samplesheets and pinned launch artifacts, then runs locally or submits to a scheduler.
Compare with literature-search-arxiv, alphafold-database-fetch-and-analyze or quickgo-database
pysam: common questions
Does pysam use 0-based or 1-based coordinates?
Pysam uses 0-based, half-open coordinates in Python. Region strings passed to fetch() follow the 1-based samtools convention.
Which index files does pysam need?
BAM files need a .bai index, CRAM needs .crai, FASTA needs .fai, VCF.gz needs a .tbi tabix index, and BCF needs a .csi index.
Can pysam run samtools and bcftools commands?
Yes. The source shows pysam.samtools and pysam.bcftools calls for sorting, indexing, viewing regions and converting VCF output, with pysam.SamtoolsError for error handling.
How do I install pysam?
Run the command above to copy the skill into ~/.claude/skills/. Claude Code picks it up automatically.
Is pysam free?
The code is published under the MIT licence. The service it connects to may have its own pricing.
Is pysam safe to use?
It scores 94 of 100. Grades: maintenance A, licence A, quality A. Security check: grade A, no risky patterns found in the files checked. Review the code before you install. How grades work.
What are alternatives to pysam?
Similar skills: literature-search-arxiv, alphafold-database-fetch-and-analyze, quickgo-database, peloton.
