CRAM (file format)


CRAM is a compressed columnar file format for storing biological sequences aligned to a reference sequence, initially devised by Markus Hsi-Yang Fritz et al.
CRAM was designed to be an efficient reference-based alternative to the Sequence Alignment Map and Binary Alignment Map file formats. It optionally uses a genomic reference to describe differences between the aligned sequence fragments and the reference sequence, reducing storage costs. Additionally each column in the SAM format is separated into its own blocks, improving compression ratio. CRAM files typically vary from 30 to 60% smaller than BAM, depending on the data held within them.
Implementations of CRAM exist in htsjdk, htslib, JBrowse, and Scramble.
The file format specification is maintained by the Global Alliance for Genomics and Health with the specification document available from the EBI cram toolkit page.

File format

The basic structure of a CRAM file is a series of containers, the first of which holds a compressed copy of the SAM header. Subsequent containers consist of a container Compression Header followed by a series of slices which in turn hold the alignment records themselves, formatted as a series of blocks.
CRAM file:
Container:
Slice:
CRAM constructs records from a set of data series, describing the components of an alignment. The container Compression Header specifies which data series is encoded in which block, what codec will be used, and any codec specific meta-data. While data series can be mixed together within the same block, keeping them separate usually improves compression and provides the opportunity for efficient selective decoding where only some data types are required.
Selective access to a CRAM file is granted via the index. On chromosome and position sorted data this indicates which region is covered by each slice. On unsorted data the index may be used to simply fetch the Nth container. Selective decoding may also be achieved using the Compression Header to skip specified data series if partial records are required.

History

YearVersionNotes
2010-11pre-CRAMInitial paper describing the reference based format. This did not use the name CRAM, but called it mzip. This software was implemented in Python as a prototype and demonstration of the basic concepts.
2011-120.3 - 0.86Vadim Zalunin of the European Bioinformatics Institute produced the first implementation named CRAM as a package called CRAMtools, written in the Java programming language.
20121.0Implemented in Java CRAMtools.
2013C implementation added to the Scramble tool, by James Bonfield of the Wellcome Sanger Institute.
20132.0Changes included support for more than one reference per slice, better encoding of SAM auxiliary tags, splitting soft-clip and inserted bases into their own data-series, meta-data to track the number of records and bases per slice, and corrections to the BF data-series.
2013Added to htslib.
20142.1Added EOF blocks, to help identify truncated files.
2014Added to htsjdk.
20143.0Inclusion of lzma and rANS codecs for block compression, along with multiple checksums for ensuring data integrity
2018Javascript implementation as part of JBrowse, by Rob Buels.

CRAM version 4.0 exists as a prototype in Scramble, initially demonstrated in 2015, but has yet to be adopted as a standard.