Biology:CRAM (file format)

From HandWiki
Short description: File format for sequence alignments
CRAM
Filename extension.cram
Developed byMarkus Hsi-Yang Fritz et al; Vadim Zalunin; James Bonfield
Type of formatBioinformatics
Websitewww.ga4gh.org/cram/, www.ebi.ac.uk/ena/software/cram-toolkit

Compressed Reference-oriented Alignment Map (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.[1]

CRAM was designed to be an efficient reference-based alternative to the Sequence Alignment Map (SAM) and Binary Alignment Map (BAM) 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,[2] htslib,[3] JBrowse,[4] and Scramble.[5]

The file format specification is maintained by the Global Alliance for Genomics and Health (GA4GH)[6] with the specification document available from the EBI cram toolkit page.[7]

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:

Magic number Container
(SAM header)
Container
(Data)
... Container
(Data)
Container
(EOF)

Container:

Container
Header
Compression
Header
Slice ... Slice

Slice:

Slice
Header
Block Block ... Block

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 (for example a table of Huffman symbol code lengths). 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 (with file-name suffix ".crai"). 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

Year Version(s) Notes
2010-11 pre-CRAM Initial 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.[1]
2011-12 0.3–0.86 Vadim Zalunin of the European Bioinformatics Institute (EBI) produced the first implementation named CRAM as a package called CRAMtools,[8] written in the Java programming language.
2012 1.0[9] Implemented in Java CRAMtools.[10]
2013 C implementation added to the Scramble[11][5] tool, by James Bonfield of the Wellcome Sanger Institute.
2013 2.0 Changes included support for more than one reference per slice (useful with highly fragmented assemblies), 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 (BAM flag) data-series.
2013 Added to htslib (0.2.0).
2014 2.1[12] Added EOF blocks, to help identify truncated files.
2014 Added to htsjdk (1.127).
2014 3.0[13] Inclusion of lzma and rANS codecs for block compression, along with multiple checksums for ensuring data integrity
2018 JavaScript implementation as part of JBrowse[4] (1.15.0), by Rob Buels.
2021 Rust implementation in Noodles[14]
2023 3.1[15] Officially adopted. (Draft from 2019)

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

See also

References

  1. 1.0 1.1 Hsi-Yang Fritz, Markus; Leinonen, Rasko; Cochrane, Guy; Birney, Ewan (May 2011). "Efficient storage of high throughput DNA sequencing data using reference-based compression". Genome Research 21 (5): 734–740. doi:10.1101/gr.114819.110. ISSN 1549-5469. PMID 21245279. 
  2. "Htsjdk by Broad Institute". https://samtools.github.io/htsjdk/. 
  3. "Samtools". http://www.htslib.org/. 
  4. 4.0 4.1 "JBrowse · A fast, embeddable genome browser built with HTML5 and JavaScript". https://jbrowse.org/. 
  5. 5.0 5.1 5.2 Bonfield, James K. (2014-06-14). "The Scramble conversion tool" (in en). Bioinformatics 30 (19): 2818–2819. doi:10.1093/bioinformatics/btu390. ISSN 1460-2059. PMID 24930138. 
  6. "GA4GH" (in en-US). https://www.ga4gh.org/. 
  7. EMBL-EBI. "CRAM toolkit < Software < European Nucleotide Archive < EMBL-EBI" (in en). https://www.ebi.ac.uk/ena/software/cram-toolkit. 
  8. "vadimzalunin/crammer" (in en). 2017-08-08. https://github.com/vadimzalunin/crammer. 
  9. "CRAM 1.0 Specification". https://www.ebi.ac.uk/sites/ebi.ac.uk/files/groups/ena/documents/cram_format_1.0.1.pdf. 
  10. "enasequence/cramtools" (in en). 2018-10-02. https://github.com/enasequence/cramtools. 
  11. "jkbonfield/io_lib" (in en). 2018-10-16. https://github.com/jkbonfield/io_lib. 
  12. "CRAM 2.1 Specification". https://samtools.github.io/hts-specs/CRAMv2.1.pdf. 
  13. "CRAM 3.0 Specification". https://samtools.github.io/hts-specs/CRAMv3.pdf. 
  14. https://github.com/zaeleus/noodles/
  15. "CRAM 3.1 Specification". https://samtools.github.io/hts-specs/CRAMv3.pdf.