<ol>
<li>Whenever you want to save space (this can be a substantial savings). Until quite recently (samtools/htslib 1.7), only CRAM supported long CIGAR strings.</li>
<li>If you need to guarantee that any random obscure downstream program will be able to handle it.</li>
</ol>

<p>Uptake of CRAM has been pretty slow. Java programs using htsjdk (e.g., picard, IGV and GATK) have only relatively recently added support for CRAM. If you need to use an old version of those for some very odd reason then CRAM may not be supported.</p>

<p>There are a lot of programs written in python that use pysam to open BAM files and these should, theoretically, support CRAM. The issue is that some of the functions may fail and one can't assume that authors will have always written the code needed to handle this. I'll use deepTools as an example, since I'm one of its developers. One of the things about CRAM files is that they (by default) are made such that you require a reference genome in order to construct the sequence field in each alignment. This works fine if you're using a standard genome (htslib, via pysam, can fetch many standard genomes from the web automatically), but if you're not, then you need to specify a fasta file to use for decompression. Every tool, then, needs to add an option for this. With pysam 0.14 and htslib 1.7 this can be circumvented by not decompressing the sequence, but behavior has to be explicitly requested.</p>

<p>Another issue is that many tools will use features from the file index, such as the <code>.mapped</code> accessor, to get the number of mapped reads in a file. CRAM files contain very very little information, so this then fails. Consequently, tool authors need to check for CRAM files and both derive and propagate this information through their functions if it's needed. This can be a time-consuming task (e.g., it took me a couple days to get this implemented in deepTools). Relatedly, <code>samtools idxstats</code> is useless on CRAM files, since there are no statistics stored in the index.</p>

<p>That having been said, it's likely that CRAMs slowly gaining acceptance will eventually make it the standard. It's already a convenient archival format, it's just a matter of time before users can assume that most analysis programs are written to handle it.</p>

CC BY-SA 3.0
2018-02-26T11:07:30.187Z
@EB2127 If this answer solved your issue, please take a moment and [accept it](http://bioinformatics.stackexchange.com/help/someone-answers) by clicking on the check mark to the left.
terdon
CC BY-SA 3.0
2018-03-01T20:20:37.387Z
@terdon Thank you for the reminder. I normally try to leave the question open a few days for other answers :)
EB2127
CC BY-SA 3.0
2018-02-26T01:10:37.510Z
2018-02-26T01:10:37.510Z
Devon Ryan
<p>I had this question from a graduate student yesterday, and I was stuck.</p>

<p>What should I say? Why use a CRAM instead of a BAM? </p>

<ol>
<li><p>When is it a good idea to use a CRAM instead of a BAM? </p></li>
<li><p>When is it a bad idea?</p></li>
</ol>

<sam><file-formats><cram>
Why would someone use a CRAM instead of a BAM?
# Why would someone use a CRAM instead of a BAM?

(Asked by: username_0 on 2018-02-26)

I had this question from a graduate student yesterday, and I was stuck.

What should I say? Why use a CRAM instead of a BAM?

1. When is it a good idea to use a CRAM instead of a BAM?
2. When is it a bad idea?

**Tags:** sam, file-formats, cram

---

## 1 answers

### Answer by username_1 on 2018-02-26. Score: 17 | Accepted answer

1. Whenever you want to save space (this can be a substantial savings). Until quite recently (samtools/htslib 1.7), only CRAM supported long CIGAR strings.
2. If you need to guarantee that any random obscure downstream program will be able to handle it.

Uptake of CRAM has been pretty slow. Java programs using htsjdk (e.g., picard, IGV and GATK) have only relatively recently added support for CRAM. If you need to use an old version of those for some very odd reason then CRAM may not be supported.

There are a lot of programs written in python that use pysam to open BAM files and these should, theoretically, support CRAM. The issue is that some of the functions may fail and one can't assume that authors will have always written the code needed to handle this. I'll use deepTools as an example, since I'm one of its developers. One of the things about CRAM files is that they (by default) are made such that you require a reference genome in order to construct the sequence field in each alignment. This works fine if you're using a standard genome (htslib, via pysam, can fetch many standard genomes from the web automatically), but if you're not, then you need to specify a fasta file to use for decompression. Every tool, then, needs to add an option for this. With pysam 0.14 and htslib 1.7 this can be circumvented by not decompressing the sequence, but behavior has to be explicitly requested.

Another issue is that many tools will use features from the file index, such as the `.mapped` accessor, to get the number of mapped reads in a file. CRAM files contain very very little information, so this then fails. Consequently, tool authors need to check for CRAM files and both derive and propagate this information through their functions if it's needed. This can be a time-consuming task (e.g., it took me a couple days to get this implemented in deepTools). Relatedly, `samtools idxstats` is useless on CRAM files, since there are no statistics stored in the index.

That having been said, it's likely that CRAMs slowly gaining acceptance will eventually make it the standard. It's already a convenient archival format, it's just a matter of time before users can assume that most analysis programs are written to handle it.

> **Comments:**
> **username_2**: @EB2127 If this answer solved your issue, please take a moment and [accept it](http://bioinformatics.stackexchange.com/help/someone-answers) by clicking on the check mark to the left.  
> **username_0**: @terdon Thank you for the reminder. I normally try to leave the question open a few days for other answers :)  

---

