samtools-cram-size(1)
π samtools cram-size π
Okay bestie, listen β this is samtools-cram-size, one of the little samtools helpers, and it's here to spill the tea on exactly what's living inside your CRAM file. Like a full body scan but for data blocks. Iconic.
β¨ SYNOPSIS β¨
samtools cram-size [-ve] [-o file] in.bam
πΈ DESCRIPTION πΈ
So what it does is: it makes a summary of all the CRAM block Content ID numbers and the Data Series that are chilling inside them. And if you want the whole story β like, per-container-level detail of how each data series is encoded β you can pass -e or --encodings and it'll give you that too. Obsessed.
Now here's the messy part π CRAM is allowed to mix multiple Data Series into a single block. And when that happens, there's literally no way to tell what proportion of the block each Data Series is eating. Not a vibe, but that's the spec.
CRAM also lets different encodings and block Content ID assignments happen per container, which β honestly? Highly unusual. Red flag energy, but legal. Meanwhile, Htslib will always assign the same Data Series to a block with a consistent Content ID, though the CRAM Encoding itself may change.
Every CRAM block has a compression method, and ngl these are not guaranteed to be consistent between successive blocks that share the same Content ID. Htslib is out here learning which compression methods actually work, so a single Content ID can end up with multiple compression methods attached to it. Each method gets listed per line with a single character code β but if you want the size breakdown per method and a chattier description, use -v. π
The compression codecs used in CRAM can have a whole variety of parameters β think compression levels, inbuilt transformations, choices of entropy encoding. This tool makes an attempt to distinguish between those different method parameterisations.
So here are the compression methods with their short and long (verbose) names, in all their glory π
π The method table π
g/gzipβ Gzip_/gzip-minβ Gzip -1G/gzip-maxβ Gzip -9b/bzip2β Bzip2b/bzip2-1 to bzip2-8β Explicit bzip2 compression levelsB/bzip2-9β Bzip2 -9l/lzmaβ LZMAr/r4x8-o0β rANS 4x8 Order-0R/r4x8-o1β rANS 4x8 Order-10/r4x16-o00/r4x16-o0Rβ rANS 4x16 Order-0 with RLE0/r4x16-o0Pβ rANS 4x16 Order-0 with PACK0/r4x16-o0PRβ rANS 4x16 Order-0 with PACK and RLE1/r4x16-o11/r4x16-o1Rβ rANS 4x16 Order-1 with RLE1/r4x16-o1Pβ rANS 4x16 Order-1 with PACK1/r4x16-o1PRβ rANS 4x16 Order-1 with PACK and RLE4/r32x16-o04/r32x16-o0Rβ rANS 32x16 Order-0 with RLE4/r32x16-o0Pβ rANS 32x16 Order-0 with PACK4/r32x16-o0PRβ rANS 32x16 Order-0 with PACK and RLE5/r32x16-o15/r32x16-o1Rβ rANS 32x16 Order-1 with RLE5/r32x16-o1Pβ rANS 32x16 Order-1 with PACK5/r32x16-o1PRβ rANS 32x16 Order-1 with PACK and RLE8/rNx16-xo0β rANS Nx16 STRIPED mode2/rNx16-catβ rANS Nx16 CAT modea/arith-o0a/arith-o0Rβ Arithmetic coding Order-0 with RLEa/arith-o0Pβ Arithmetic coding Order-0 with PACKa/arith-o0PRβ Arithmetic coding Order-0 with PACK and RLEA/arith-o1A/arith-o1Rβ Arithmetic coding Order-1 with RLEA/arith-o1Pβ Arithmetic coding Order-1 with PACKA/arith-o1PRβ Arithmetic coding Order-1 with PACK and RLEa/arith-xo0β Arithmetic coding STRIPED modea/arith-catβ Arithmetic coding CAT modef/fqzcompβ FQZComp quality codecn/tok3-ransβ Name tokeniser with rANS encodingn/tok3-arithβ Name tokeniser with Arithmetic encoding
β¨ OPTIONS β¨
-o FILEβ sends the size information into FILE instead of wherever it was going. π«Ά-vβ verbose mode, babes. Shows one whole line per combination of Content ID and compression method. That's the detail you came for.-e,--encodingsβ okay so CRAM uses an Encoding, which is the whole description of how the data gets serialised into a data block. Important: this is distinct from the CRAM compression method, which is applied to the block after encoding. The encoding methods are stored per CRAM Container.
This option lists the CRAM record encoding map and tag encoding map. It shows you the data series, the associated CRAM encoding method β things like HUFFMAN, BETA or EXTERNAL β and any parameters tied to that encoding.
Heads up bestie: the output can be large π because this is information per container, not one tidy set of summary statistics dumped at the end of processing.
π EXAMPLES π
- The basic summary of block Content ID sizes for a CRAM file:
$ samtools cram-size in.cram
# Content_ID Uncomp.size Comp.size Ratio Method Data_series
BLOCK CORE 0 0 100.00% .
BLOCK 11 394734019 51023626 12.93% g RN
BLOCK 12 1504781763 99158495 6.59% R QS
BLOCK 13 330065 84195 25.51% _r.g IN
BLOCK 14 26625602 6803930 25.55% Rrg SC
...
- Same file as above, but with verbose mode on. Here's where you actually see the distinct compression methods that have been used per block Content ID π
$ samtools cram-size -v in.cram
# Content_ID Uncomp.size Comp.size Ratio Method Data_series
BLOCK CORE 0 0 100.00% raw
BLOCK 11 394734019 51023626 12.93% gzip RN
BLOCK 12 1504781763 99158495 6.59% r4x8-o1 QS
BLOCK 13 275033 64343 23.39% gzip-min IN
BLOCK 13 43327 15412 35.57% r4x8-o0 IN
BLOCK 13 2452 2452 100.00% raw IN
BLOCK 13 9253 1988 21.49% gzip IN
BLOCK 14 23106404 5903351 25.55% r4x8-o1 SC
BLOCK 14 1951616 513722 26.32% r4x8-o0 SC
BLOCK 14 1567582 386857 24.68% gzip SC
...
- Listing encoding methods per CRAM Data Series. The two-letter series are the standard CRAM Data Series, and the three-letter ones are the optional auxiliary tags with the tag name and type combined together. iykyk π
$ samtools cram-size -e in.cram
Container encodings
RN BYTE_ARRAY_STOP(stop=0,id=11)
QS EXTERNAL(id=12)
IN BYTE_ARRAY_STOP(stop=0,id=13)
SC BYTE_ARRAY_STOP(stop=0,id=14)
BB BYTE_ARRAY_LEN(len_codec={EXTERNAL(id=42)}, \
val_codec={EXTERNAL(id=37)}
...
XAZ BYTE_ARRAY_STOP(stop=9,id=5783898)
MDZ BYTE_ARRAY_STOP(stop=9,id=5063770)
ASC BYTE_ARRAY_LEN(len_codec={HUFFMAN(codes={1},lengths={0})}, \
val_codec={EXTERNAL(id=4281155)}
...
π AUTHOR π
Written by James Bonfield from the Sanger Institute. Absolute legend, no cap. π«Ά
π¦ SEE ALSO π¦
samtools(1)- Samtools website:
http://www.htslib.org/
and that's the whole page bestie!! β¨ this lil masterpiece is from samtools-1.24, dated 9 July 2026 β go forth and inspect those CRAM blocks, you gorgeous data gremlin πππ¦
π¦ where this page comes from
- epel 10: samtools 1.24-2.el10_3 Β· MIT
- nixpkgs unstable: samtools 1.24
- Copyright (C) 2023 Genome Research Ltd
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms