sulfierry/mcp/alignment-indexing
Claude Code and agent skill by sulfierry/mcp
- community
Checking that the SKILL.md file is still in the repository.
Create and use BAI/CSI indices for BAM/CRAM files using samtools and pysam. Use when enabling random access to alignment files or fetching specific genomic regions.
Install
npx vskill@latest install sulfierry/mcp/alignment-indexingSKILL.md
The same SKILL.md was published earlier as sulfierry/mcp/alignment-indexing.
Version Compatibility
Reference examples tested with: pysam 0.22+, samtools 1.19+
Before using code patterns, verify installed versions match. If versions differ:
- Python:
pip show <package>thenhelp(module.function)to check signatures - CLI:
<tool> --versionthen<tool> --helpto confirm flags
If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
Alignment Indexing
Create indices for random access to alignment files using samtools and pysam.
"Index a BAM file" → Create a .bai/.csi index enabling random access to genomic regions.
- CLI:
samtools index file.bam - Python:
pysam.index('file.bam')
Index Types
| Index | Extension | Use Case | |
|---|---|---|---|
| BAI | .bai | Standard BAM index, chromosomes < 512 Mbp | |
| CSI | .csi | Large chromosomes, custom bin sizes | |
| CRAI | .crai | CRAM index |
samtools index
Create BAI Index
Create CSI Index
Specify Output Name
Multi-threaded Indexing
Index CRAM
Index Requirements
Indexing requires coordinate-sorted files:
Using Indices for Region Access
Goal: Extract reads overlapping specific genomic coordinates from an indexed BAM.
Approach: With the index present, samtools view or pysam.fetch() can jump directly to the relevant file offset instead of scanning the entire file.
samtools view with Region
Multiple Regions
Regions from BED File
pysam Python Alternative
Create Index
Create CSI Index
Fetch with Index
Check if Indexed
Fetch Multiple Regions
Count Reads in Region
Get Reads Covering Position
Index File Locations
samtools looks for indices in two locations:
For CRAM:
idxstats - Index Statistics
Get Per-Chromosome Counts
Output format:
Columns: reference name, length, mapped reads, unmapped reads
Sum Total Mapped Reads
pysam idxstats
FASTA Index (faidx)
Related but different - index reference FASTA for random access:
pysam FastaFile
Quick Reference
| Task | samtools | pysam | |
|---|---|---|---|
| Create BAI | samtools index file.bam | pysam.index('file.bam') | |
| Create CSI | samtools index -c file.bam | pysam.index('file.bam', csi=True) | |
| Fetch region | samtools view file.bam chr1:1-1000 | bam.fetch('chr1', 0, 1000) | |
| Count in region | samtools view -c file.bam chr1:1-1000 | bam.count('chr1', 0, 1000) | |
| Index stats | samtools idxstats file.bam | bam.get_index_statistics() | |
| Index FASTA | samtools faidx ref.fa | Automatic with FastaFile |
Common Errors
| Error | Cause | Solution | |
|---|---|---|---|
random alignment retrieval only works for indexed BAM | Missing index | Run samtools index file.bam | |
file is not sorted | Unsorted BAM | Sort first with samtools sort | |
chromosome not found | Wrong chromosome name | Check names with samtools view -H |
Related Skills
- sam-bam-basics - View and convert alignment files
- alignment-sorting - Sort BAM files (required before indexing)
- alignment-filtering - Filter by regions using index
- bam-statistics - Use idxstats for quick counts
- sequence-io/read-sequences - Index FASTA with SeqIO.index_db()
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/alignment-indexing/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/sulfierry/mcp/alignment-indexing)