Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

bio-bam-statistics

БесплатноЗапускает вложенные скриптыНе проверен

Generate alignment statistics using samtools flagstat, stats, depth, coverage, and mosdepth. Use when assessing alignment quality, calculating coverage, or…

gabrielmoreiraот gabrielmoreira★ 23 звезды на GitHub

Об этом скилле

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> then help(module.function) to check signatures
  • CLI: <tool> --version then <tool> --help to 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.

BAM Statistics

"Get alignment statistics and coverage from my BAM file" → Generate read counts, mapping rates, per-chromosome statistics, depth profiles, and coverage summaries.

  • CLI: samtools flagstat, samtools stats, samtools depth, samtools coverage (samtools)
  • Python: pysam.AlignmentFile with pileup() and get_index_statistics() (pysam)

Generate alignment statistics using samtools and pysam.

Quick Summary Commands

Question Best tool Why
Quick read counts by FLAG category samtools flagstat Fast; counts secondary+supp in totals
Per-chromosome counts samtools idxstats Fast (needs index); counts secondary+supp
Insert size, MAPQ, error, GC samtools stats -r ref.fa Comprehensive; feeds MultiQC
Per-position depth (small region) samtools depth or pysam pileup Slow on full genome
Per-position depth (genome-wide) mosdepth 3-10x faster than samtools depth
Per-region coverage (BED) mosdepth --by regions.bed Production default
Coverage histogram / cumulative mosdepth -t 4 --no-per-base Single-pass histogram
Breadth at depth thresholds mosdepth --thresholds 1,10,30,100 Standard exome QC
Targeted enrichment QC picard CollectHsMetrics PCT_OFF_BAIT, FOLD_80_BASE_PENALTY, AT/GC dropout
Cross-sample contamination verifybamid2, somalier FREEMIX < 0.01 expected

What Each Tool Counts (and Doesn't)

Counting category flagstat stats idxstats
Primary alignments in total minus supp raw total sequences mapped column
Secondary secondary line filtered out counted in mapped
Supplementary supplementary line filtered out counted in mapped
Mapping rate denominator total including supp primary only mapped+unmapped

For long-read data where one read produces many supplementary alignments, the senior cross-check:

input_read_count = flagstat_total - secondary - supplementary
                 = stats_raw_total_sequences

Reports of "the file has 1.2M reads" where the input was actually 800k with 400k supplementary chimeric splits trace to flagstat misinterpretation.

samtools flagstat

Fast summary of alignment flags.

samtools flagstat input.bam

Output:

10000000 + 0 in total (QC-passed reads + QC-failed reads)
0 + 0 secondary
50000 + 0 supplementary
0 + 0 duplicates
9800000 + 0 mapped (98.00% : N/A)
9950000 + 0 paired in sequencing
4975000 + 0 read1
4975000 + 0 read2
9700000 + 0 properly paired (97.49% : N/A)
9750000 + 0 with itself and mate mapped
100000 + 0 singletons (1.01% : N/A)
25000 + 0 with mate mapped to a different chr
10000 + 0 with mate mapped to a different chr (mapQ>=5)

Multi-threaded

samtools flagstat -@ 4 input.bam

Output to File

samtools flagstat input.bam > flagstat.txt

samtools idxstats

Per-chromosome read counts (requires index).

samtools idxstats input.bam

Output format: chrom length mapped unmapped

chr1    248956422    5000000    1000
chr2    242193529    4800000    800
chrM    16569        50000      100
*       0            0          150000

Parse idxstats

# Total mapped reads
samtools idxstats input.bam | awk '{sum += $3} END {print sum}'

# Mitochondrial percentage
samtools idxstats input.bam | awk '
    /^chrM/ {mt = $3}
    {total += $3}
    END {print mt/total*100 "% mitochondrial"}'

samtools stats

Comprehensive statistics including insert size, base quality, and more.

samtools stats input.bam > stats.txt

View Summary Numbers

samtools stats input.bam | grep "^SN"

Key summary fields:

  • raw total sequences - Total reads
  • reads mapped - Mapped reads
  • reads mapped and paired - Properly paired
  • insert size average - Mean insert size
  • insert size standard deviation - Insert size spread
  • average length - Mean read length
  • error rate - Mismatch rate

Generate Plots (with plot-bamstats)

samtools stats input.bam > stats.txt
plot-bamstats -p plots/ stats.txt

Stats for Specific Region

samtools stats input.bam chr1:1000000-2000000 > region_stats.txt

samtools depth

Per-position read depth.

Basic Depth

samtools depth input.bam > depth.txt

Output: chrom position depth

Depth at Specific Positions

samtools depth -r chr1:1000-2000 input.bam
`
Полный SKILL.md на GitHub

Установить bio-bam-statistics в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

examples/qc_report.pyusage-guide.md

FAQ

Что делает скилл bio-bam-statistics?

Generate alignment statistics using samtools flagstat, stats, depth, coverage, and mosdepth. Use when assessing alignment quality, calculating coverage, or generating QC reports.

Как установить скилл bio-bam-statistics?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл bio-bam-statistics запускает скрипты?

Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.

Похожие скиллы

Сравнить bio-bam-statistics с