bio-alignment-filtering
Filter alignments by flags, mapping quality, and regions using samtools view and pysam. Use when extracting specific reads, removing low-quality alignments…
от lilinji★ 18 звёзд на GitHub
Установить bio-alignment-filtering в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
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 Filtering
"Filter my BAM file to keep only high-quality reads" -> Select reads by FLAG bits, mapping quality, and genomic regions using samtools view or pysam.
- CLI:
samtools viewwith-F/-f/-q/-Lflags (samtools) - Python:
pysam.AlignmentFileiteration with attribute filters (pysam)
Filter alignments by flags, quality, and regions using samtools and pysam.
Filter Flags
| Option | Description |
|---|---|
-f FLAG |
Include reads with ALL bits set |
-F FLAG |
Exclude reads with ANY bits set |
-G FLAG |
Exclude reads with ALL bits set |
-q MAPQ |
Minimum mapping quality |
-L BED |
Include reads overlapping regions |
Common FLAG Values
| Flag | Hex | Meaning |
|---|---|---|
| 1 | 0x1 | Paired |
| 2 | 0x2 | Proper pair |
| 4 | 0x4 | Unmapped |
| 8 | 0x8 | Mate unmapped |
| 16 | 0x10 | Reverse strand |
| 32 | 0x20 | Mate reverse strand |
| 64 | 0x40 | First in pair (read1) |
| 128 | 0x80 | Second in pair (read2) |
| 256 | 0x100 | Secondary alignment |
| 512 | 0x200 | Failed QC |
| 1024 | 0x400 | Duplicate |
| 2048 | 0x800 | Supplementary |
Filter by FLAG
Keep Only Mapped Reads
samtools view -F 4 -o mapped.bam input.bam
Keep Only Unmapped Reads
samtools view -f 4 -o unmapped.bam input.bam
Keep Only Properly Paired
samtools view -f 2 -o proper.bam input.bam
Remove Duplicates
samtools view -F 1024 -o nodup.bam input.bam
Remove Secondary and Supplementary
samtools view -F 2304 -o primary.bam input.bam
Keep Only Primary Alignments
samtools view -F 256 -F 2048 -o primary.bam input.bam
# Or combined: -F 2304
Keep Read1 Only
samtools view -f 64 -o read1.bam input.bam
Keep Read2 Only
samtools view -f 128 -o read2.bam input.bam
Forward Strand Only
samtools view -F 16 -o forward.bam input.bam
Reverse Strand Only
samtools view -f 16 -o reverse.bam input.bam
Filter by Mapping Quality
Minimum MAPQ
samtools view -q 30 -o highqual.bam input.bam
MAPQ and Mapped
samtools view -F 4 -q 30 -o filtered.bam input.bam
Aligner-Aware MAPQ Thresholds
MAPQ scales differ by aligner; the same -q 30 filter does different things. See sam-bam-basics for the full MAPQ-by-aligner table. Filtering recommendations:
| Aligner | "Drop ambiguous" | "High confidence" |
|---|---|---|
| BWA-MEM / BWA-MEM2 | -q 1 |
-q 30 (or -q 60 for unique only) |
| Bowtie2 | -q 1 |
-q 23 (Bowtie2 MAPQ maxes at 42 end-to-end; 23 is a community "uniquely mapped" convention derived from analysis of Bowtie2's MAPQ scoring, not stated in the official manual) |
| STAR | -q 255 |
-q 255 (STAR emits only MAPQ 0/1/3/255, 255 = unique; -q 60 is therefore equivalent to -q 255 -- there are no values between 3 and 255) |
| HISAT2 | -q 1 |
-q 60 |
| minimap2 (DNA, long-read) | -q 1 |
-q 60 |
| pbmm2 (PacBio) | -q 1 |
-q 60 |
For Phred-scaled aligners (BWA, minimap2), MAPQ Q maps to ~10^(-Q/10) probability of wrong mapping. For STAR, the only emitted values are 0/1/3/255 (sentinels, not probabilities).
Drop Ambiguous Across Aligners (Universal)
samtools view -q 1 in.bam # exclude MAPQ=0; works for all aligners
Filter by Region
Single Region
samtools view -o region.bam input.bam chr1:1000000-2000000
Multiple Regions
samtools view -o regions.bam input.bam chr1:1000-2000 chr2:3000-4000
Regions from BED File
samtools view -L targets.bed -o targets.bam input.bam
Combine Region and Quality
samtools view -q 30 -L targets.bed -o filtered.bam input.bam
Combined Filters
Standard Quality Filter
Goal: Produce a clean BAM containing only primary, mapped, non-duplicate reads with high mapping confidence.
Approach: Combine FLAG exclusion (-F for unmapped + secondary + duplicate + supplementary) with a MAPQ threshold.
Reference (samtools 1.19+):
samtools view -F 3332 -q 30 -o filtered.bam input.bam
# 3332 = 4 (unmapped) + 256 (secondary) + 1024 (duplicate) + 2048 (supplementary)
Variant Calling Prep -- Assay-Aware
Goal: Choose a filter that matches what the downstream caller expects. Stripping supplementary alignments breaks SV callers; requiring proper-pair drops valid spliced RNA-seq reads.
| Assay / caller | Recommended filte
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- examples/filter_bam.py
- usage-guide.md
FAQ
Что делает скилл bio-alignment-filtering?
Filter alignments by flags, mapping quality, and regions using samtools view and pysam. Use when extracting specific reads, removing low-quality alignments, or subsetting to target regions.
Как установить скилл bio-alignment-filtering?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл bio-alignment-filtering запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…