BAM / CRAM
BAM and CRAM are the binary and reference-compressed forms of the SAM alignment format, storing every sequencing read together with where and how well it aligned to a reference genome.
BAM and CRAM are container formats for aligned sequencing reads. Both are compressed encodings of SAM, the tab-delimited Sequence Alignment/Map format: one line per read, carrying the read name, flags, chromosome and position, mapping quality, CIGAR string, sequence, base qualities, and optional tags 1. BAM is a block-gzip (BGZF) binary version of that text. CRAM stores the same information column by column and, for reference-matching bases, stores only the differences from the reference instead of the bases themselves.
How it works
A SAM record has 11 mandatory fields. The ones you will read most often:
- FLAG: a bitfield.
0x4unmapped,0x10reverse strand,0x400PCR/optical duplicate,0x100secondary,0x800supplementary.samtools flags 1024decodes any value. - RNAME/POS: reference name and 1-based leftmost aligned position.
- MAPQ: phred-scaled probability the alignment position is wrong. 0 means the aligner found equally good placements elsewhere, which happens across segmental duplications and in the pseudoautosomal regions.
- CIGAR: the edit script, e.g.
76M2D74Mor40S110M. Soft clips (S) keep the bases in the record but exclude them from the alignment, and a pileup of soft clips at one coordinate is the classic signature of a structural breakpoint 2.
BGZF makes BAM indexable: it is gzip with a fixed block structure, so a .bai or .csi index can map a genomic interval to a byte offset and a reader can seek instead of streaming. That is what lets a browser jump to one gene in a 60 GB file rather than decompressing the whole thing 3.
CRAM adds reference-based compression. For a base that matches the reference, the record stores nothing about the base itself. The consequence is structural: a CRAM is unreadable without the exact reference it was written against. The header’s @SQ lines carry an M5 MD5 checksum per contig, and samtools resolves that checksum via -T ref.fa or the REF_PATH/REF_CACHE environment variables. Get the reference wrong (GRCh38 with ALT contigs versus the analysis set, or hg19 versus GRCh37 naming) and you get either an error or silently corrupted sequence.
Typical sizes for a 30x human genome: FASTQ around 100 GB, BAM 50-80 GB, CRAM 15-25 GB. Most of the remaining bulk in either format is base quality strings, which is why CRAM’s lossy quality modes exist and why we generally leave them off.
In your own data
Conversion is one command. Always pass the reference:
samtools view -@ 8 -T GRCh38_full_analysis_set_plus_decoy_hla.fa \
-b -o sample.bam sample.cram
samtools index -@ 8 sample.bam
Reverse direction, -C instead of -b. The -@ thread flag matters: BGZF compression is the bottleneck in most conversions, and single-threaded runs on a 30x genome take hours where eight threads take tens of minutes 4.
Checks worth running before you trust anything downstream:
samtools quickcheck -v sample.bamconfirms the EOF block is present. Truncated downloads are the single most common failure, and a truncated BAM reads fine until it doesn’t.samtools view -H sample.bam | grep '@RG'shows read groups. Missing or duplicatedSMvalues break joint calling and most pipelines built on GATK conventions 5.samtools flagstatandsamtools idxstats. Look for mapped rate above roughly 99% for human WGS, duplicate rate (Illumina PCR-free libraries typically land in the low single digits), and reads on unexpected contigs.samtools stats | plot-bamstatsfor insert size distribution and per-cycle quality. A bimodal insert distribution usually means mixed libraries.- If you have two files and want to know they are the same person, compare genotypes at common sites rather than trusting filenames. BAM-matcher does exactly this and is the right reflex whenever a sample’s identity is in question 6.
BAM versus VCF is a question of granularity. The BAM holds every read; the VCF holds positions where your genome differs from the reference, with one line per variant site and no read-level evidence beyond summary annotations. You cannot recover phasing from a VCF alone, but you can from the reads: WhatsHap walks the alignments to assign heterozygous variants to haplotypes using reads that span multiple sites 7. Marking duplicates and calling variants directly from a streaming alignment is also standard practice now, which is how tools like SpeedSeq get a genome from reads to calls in hours 8.
Limitations
CRAM’s dependency on an external reference is a real archival risk: a CRAM plus a lost reference is close to unrecoverable. Keep the exact FASTA and its .fai next to the file, and record the M5 checksums.
MAPQ 0 regions are invisible to most callers, so absence of a variant in a low-mappability region is not evidence of reference genotype. Off-target and clipped reads are retained in the file but ignored by default filters, so a quick flagstat can look clean while a breakpoint sits in the soft clips.
Neither format is anonymous. An alignment file is an identifiable genotype, and selective-retrieval schemes with encryption exist precisely because sharing a region of a BAM leaks more than the region 9. Treat these files like private keys. Interpreting any specific variant for health purposes requires a clinician and a clinically validated assay, not an analysis pipeline you ran yourself.
Woolf Software builds longitudinal molecular profiles of individuals: whole-genome sequencing, RNA sequencing, proteomics, blood biomarkers, and continuous glucose data, integrated into one model of you. Build your profile.
Your alignment file is the last place your raw evidence lives intact: every read, every base quality, every mismatch. Variant calls are a summary of it, and when a call looks wrong, the alignment is what you go back to.
Related Terms
References
- Peter Robinson, Peter Hansen. SAM/BAM Format . Computational Exome and Genome Analysis, 2017. DOI
- Jianmin Wang, Charles G Mullighan, John Easton, et al.. CREST maps somatic structural variation in cancer genomes with base-pair resolution . Nature Methods, 2011. DOI
- T. Carver, S. R. Harris, T. D. Otto, et al.. BamView: visualizing and interpretation of next-generation sequencing read alignments . Briefings in Bioinformatics, 2012. DOI
- Lifeng Yan, Zhan Zhao, Zekun Yin, et al.. RabbitBAM: Accelerating BAM File Manipulation on Multi-Core Platforms . IEEE Transactions on Computational Biology and Bioinformatics, 2025. DOI
- Friederike Hanssen, Maxime U Garcia, Lasse Folkersen, et al.. Scalable and efficient DNA sequencing analysis on different compute infrastructures aiding variant discovery . NAR Genomics and Bioinformatics, 2024. DOI
- Paul P.S. Wang, Wendy T. Parker, Susan Branford, et al.. BAM-matcher: a tool for rapid NGS sample matching . Bioinformatics, 2016. DOI
- Marcel Martin, Peter Ebert, Tobias Marschall. Read-Based Phasing and Analysis of Phased Variants with WhatsHap . Methods in Molecular Biology, 2022. DOI
- Colby Chiang, Ryan M Layer, Gregory G Faust, et al.. SpeedSeq: ultra-fast personal genome analysis and interpretation . Nature Methods, 2015. DOI
- Zhicong Huang, Erman Ayday, Huang Lin, et al.. A privacy-preserving solution for compressed storage and selective retrieval of genomic data . Genome Research, 2016. DOI