pysam
Skill23 starsChanged 10 months agoMITView on GitHub
Python module for reading, manipulating and writing genomic alignment formats (SAM/BAM/CRAM) and variant files (VCF/BCF). Wrapper for htslib.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- BrightGold70/skillstheir own version, first seen Sep 29, 2026
- LeonChaoX/qinyan-academic-skillstheir own version, first seen Mar 13, 2026
- qinyan-ai/qinyan-academic-skillstheir own version, first seen Mar 13, 2026
- yf8578/claude-skills-collectiontheir own version, first seen Mar 1, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- LeonChaoX/qinyan-academic-skills★ 932same name
- qinyan-ai/qinyan-academic-skills★ 80same name
- BrightGold70/skills★ 1same name
- yf8578/claude-skills-collection★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository69 other files it gives its agents.
- aseSkill
- astropySkill
- biopythonSkill
- chempySkill
- cobrapySkill
- dask-optimizationSkill
- daskSkill
- dowhySkill
- duckdbSkill
- example-skillSkill
- fastapi-streamlitSkill
- geopandasSkill
- gmsh-meshioSkill
- h5pySkill
- jax-pdeSkill
- jaxSkill
- lifelinesSkill
- matplotlib-proSkill
- matplotlibSkill
- mdanalysisSkill
- mneSkill
- networkxSkill
- numbaSkill
- numpy-low-levelSkill
- numpySkill
- openbabelSkill
- opencvSkill
- ortoolsSkill
- pandas-performanceSkill
- pennylaneSkill
- photutilsSkill
- plotlySkill
- polarsSkill
- prodySkill
- pydicomSkill
- pymcSkill
- pyomoSkill
- pyprojSkill
- pyscfSkill
- pytorch-deploymentSkill
- pytorch-geometricSkill
- pytorch-researchSkill
- pytorchSkill
- qiskit-hardwareSkill
- qiskitSkill
- qutipSkill
- rasterioSkill
- rdkitSkill
- scanpySkill
- scikit-bioSkill
- scikit-imageSkill
- scikit-learnSkill
- scikit-videoSkill
- scipySkill
- seabornSkill
- shapelySkill
- simpySkill
- sklearn-advancedSkill
- sklearn-explainabilitySkill
- sktime-tsfreshSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 0 are distinctive, and 4 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 72
Always use indexed files: - Create index with pysam.index("file.bam") for fast access.
- Very specific: line 73
Check read flags: - Use read.is_paired, read.is_unmapped to filter reads.
- Very specific: line 75
Close files explicitly: - Use context managers or .close() to avoid resource leaks.
- Very specific: line 79
Don't iterate over entire BAM: - Use fetch() with regions for efficiency.
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Pysam - Genomic Alignments
Used for high-throughput sequencing pipelines. It allows efficient access to billions of DNA fragments aligned to a reference genome.
When to Use
- Processing next-generation sequencing (NGS) data.
- Analyzing genomic variants (SNPs, indels).
- Extracting reads from specific genomic regions.
- Building custom bioinformatics pipelines.
- Quality control of sequencing data.
Core Principles
Indexed Access
BAM files must be indexed (.bai) for efficient random access to genomic regions.
Coordinate System
Genomic coordinates are 0-based (Python-style) for positions, but 1-based for ranges in some contexts.
Read Attributes
Each read contains sequence, quality scores, alignment position, and flags.
Quick Reference
Standard Imports
import pysamBasic Patterns
# 1. Open BAM file
samfile = pysam.AlignmentFile("aligned_reads.bam", "rb")
# 2. Iterate over reads in a specific genomic region
for read in samfile.fetch("chr1", 10000, 10100):
print(f"Read: {read.query_name}, Quality: {read.mapping_quality}")
print(f"Sequence: {read.query_sequence}")
print(f"Position: {read.reference_start}")
# 3. Variant analysis (VCF)
vcf = pysam.VariantFile("mutations.vcf")
for rec in vcf.fetch("chr1", 10000, 10100):
print(f"Pos: {rec.pos}, Ref: {rec.ref}, Alt: {rec.alts}")
print(f"Genotype: {rec.samples['sample1']['GT']}")
# 4. Writing aligned reads
outfile = pysam.AlignmentFile("output.bam", "wb", template=samfile)
for read in samfile:
if read.mapping_quality > 30:
outfile.write(read)
outfile.close()Critical Rules
✅ DO
- Always use indexed files - Create index with
pysam.index("file.bam")for fast access. - Check read flags - Use
read.is_paired,read.is_unmappedto filter reads. - Handle unmapped reads - Unmapped reads have
reference_start = -1. - Close files explicitly - Use context managers or
.close()to avoid resource leaks.
❌ DON'T
- Don't iterate over entire BAM - Use
fetch()with regions for efficiency. - Don't ignore quality scores - Low-quality bases can cause false variants.
- Don't mix coordinate systems - Be consistent with 0-based vs 1-based indexing.
Advanced Patterns
Counting Reads per Gene
# Using a gene annotation file
genes = {} # gene_name -> (chr, start, end)
for read in samfile.fetch():
# Check if read overlaps any gene
for gene, (chr, start, end) in genes.items():
if read.reference_name == chr and start <= read.reference_start < end:
genes[gene]['count'] += 1Variant Filtering
# Filter variants by quality and depth
for rec in vcf.fetch():
depth = rec.samples['sample1']['DP']
qual = rec.qual
if depth > 10 and qual > 20:
# Process high-quality variant
passPysam provides the low-level access needed for genomic data processing, enabling researchers to work directly with the raw data of life itself.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

