一键导入
sam-bam-basics
Understand the SAM format header, alignment records, FLAGs, MAPQ, CIGAR, and coordinate conventions — the foundation for all downstream BAM analysis.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Understand the SAM format header, alignment records, FLAGs, MAPQ, CIGAR, and coordinate conventions — the foundation for all downstream BAM analysis.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Pass work between ORS skills with a Material Passport — a structured JSON envelope that captures inputs, outputs, decisions, and provenance so a downstream skill can resume without re-deriving context. Use when one skill produces output that another skill must consume, especially across category boundaries (e.g. analysis → writing, sequencing → statistics).
Discover and maintain `## Cross-references` between ORS skills. Given a new or edited skill, suggest related skills (same category, shared tags, complementary workflows). Verify all xref slugs resolve to existing SKILL.md files. Use when adding a new skill, when sibling skills move, or when an audit reveals dangling xrefs.
7-mode AI failure-mode checklist applied before publishing any ORS artifact (skill, manuscript section, dataset card, agent output). Catches: fabricated citations, silent failures, scope creep, missing provenance, unsupervised writes, version drift, hallucinated APIs. Use as the final pass before any 'publish', 'release', 'merge', or 'finalize' action.
Version, changelog, and marketplace workflow for ORS skills. Semver discipline, breaking-change protocol, marketplace.json update, README refresh, and the v0.X.Y → v1.0.0 graduation criteria. Use when bumping a skill version, publishing a release, or upgrading the ORS package version.
Author a new ORS skill from scratch using the v0.4.0 schema. Produces a valid SKILL.md (frontmatter + metadata + sections) following spec/skill-format.md, guided by spec/author-guide.md, validated by scripts/validate-skills.py. Use when a user says 'add a new skill', 'create a skill for X', or 'I want to contribute a skill'.
Process many FASTA/FASTQ/GenBank files in batch — merge, split, convert, summarize, organize — using Biopython 1.83+.
| name | sam-bam-basics |
| description | Understand the SAM format header, alignment records, FLAGs, MAPQ, CIGAR, and coordinate conventions — the foundation for all downstream BAM analysis. |
| license | MIT |
bam-statistics skill.duplicate-handling skill.samtools ≥ 1.19pysam (see pysam-genomics skill)QNAME FLAG RNAME POS CIGAR SEQ QUAL TAGS
| Field | Content | Example |
|---|---|---|
| QNAME | Read name | HISEQ:XX:123:CGT... |
| FLAG | Bitwise OR flags | 99 = paired + proper + reverse + mate-reverse |
| RNAME | Reference | chr1, * if unmapped |
| POS | 1-based leftmost | 12345678, 0 if unmapped |
| CIGAR | Alignment | 100M, 50S50M, * for unmapped |
| SEQ | Sequence | ACGT..., * if no SEQ |
| QUAL | Phred quality | IIII..., * if no QUAL |
| TAGS | Optional fields | NM:i:5 MD:Z:50 GA:G... |
| Tag | Type | Meaning |
|---|---|---|
NM | i | Edit distance (total mismatches + indels) |
MD | Z | MD:Z string for SNPs |
RG | Z | Read group (from input @RG) |
AS | i | Alignment score |
XS | A | Strand for RNA (+ or -) |
XP | Z | Alternative alignment positions |
YI | Z | Old read group (Illumina) |
MC | Z | Mate CIGAR |
MQ | i | Mate MAPQ |
PG | Z | Program that produced this alignment |
Use samtools flags 99 to decode or encode:
| Flag | Binary | Meaning |
|---|---|---|
| 1 | 000000000001 | paired |
| 2 | 000000000010 | proper paired |
| 4 | 000000000100 | unmapped |
| 8 | 000000001000 | mate unmapped |
| 16 | 000000010000 | reverse strand |
| 32 | 000000100000 | mate reverse strand |
| 64 | 000001000000 | first in pair |
| 128 | 000010000000 | second in pair |
| 256 | 000100000000 | secondary alignment |
| 512 | 001000000000 | QC fail |
| 1024 | 010000000000 | duplicate |
| 2048 | 100000000000 | supplementary alignment |
samtools view -h input.bam | head -20
samtools view -bS input.sam > output.bam
samtools view -F 4 -b input.bam > mapped.bam
# -F 4 = exclude FLAG 4 (unmapped)
samtools view -f 4 -b input.bam > unmapped.bam
# -f 4 = require FLAG 4 (unmapped)
samtools view -F 4 -f 2 -b input.bam > proper.bam
samtools view -q 30 -b input.bam > q30.bam
samtools view -F 256 -b input.bam > primary.bam
samtools view -b chr1 input.bam > chr1.bam
samtools view -h input.bam | grep "read_name" | samtools view -bS - > reads.bam
BEDTools: bedtools bedtobam -bed12 input.bed -g genome.txt > output.bam
samtools flags 99
# 99 = PAIRED|PROPER_PAIRED|REVERSE|MREVERSE
samtools sort -n input.bam -o input.name.bam
samtools index input.name.bam
samtools sort -o input.coord.bam input.bam
samtools index input.coord.bam
samtools view -H input.bam
# Shows @HD, @SQ, @RG, @PG lines
samtools addreplacerg -r "@RG\tID:sample1\tSM:sample1\tPL:ILLUMINA" -o out.bam in.bam
samtools index out.bam
For RNA-seq, the XS tag indicates strand:
samtools view input.bam | awk '$20 ~ /XS:A:[+-]/ {print $20}'
| System | Start | End | Used by |
|---|---|---|---|
| SAM/BAM (POS) | 1-based | inclusive | SAM/BAM |
| BED | 0-based | exclusive | UCSC, BEDTools |
| VCF | 1-based | inclusive | VCF |
| Python | 0-based | exclusive | All Python libraries |
| GFF3 | 1-based | inclusive | GFF3 |
50M = 50 matches. 10S40M = 10 soft-clipped + 40 matches.samtools markdup is the canonical; confirm before filtering.samtools flagstat to check read counts.samtools view -F 4, no reads should have FLAG bit 4.samtools index) before samtools tview or region queries.| Need | Tool |
|---|---|
| PAF (minimap2 output) | Convert to SAM with paftools, or use minimap2 -a for SAM |
| CRAM (compressed) | samtools view -C |
| HTSJDK (JVM) | Use Picard from GATK |
| Genome-wide statistics | samtools stats, mosdepth |
ors-bioinformatics-sequence-bam-statistics, ors-bioinformatics-sequence-pysam-genomicsbio-sam-bam-basics (bioSkills-main/alignment-files/sam-bam-basics).Other skills in this category: