<p>All can be done with <a href="http://www.htslib.org/" rel="nofollow noreferrer">samtools</a>. This is how <a href="https://github.com/darwintreeoflife/darwintreeoflife.data/issues/2#event-4859159249" rel="nofollow noreferrer">the Darwin Tree of Life folks convert it</a>:</p>
<pre><code>samtools fastq -@4 -i \
  -1 <span class="math-container">${sample}_S$</span>{tag}_L%03s_R1_001.fastq.gz \
  -2 <span class="math-container">${sample}_S$</span>{tag}_L%03s_R2_001.fastq.gz \
  --i1 <span class="math-container">${sample}_S$</span>{tag}_L%03s_I1_001.fastq.gz \
  --index-format i8 ${lane}.cram
</code></pre>

CC BY-SA 4.0
2021-06-09T19:41:08.487Z
I don't know if that solution will work with 10xGenomics files.  You have to recreate R2 out of the contents of tags; there will be no reads with the read2 binary flag set.
swbarnes2
CC BY-SA 4.0
2021-06-10T09:39:28.890Z
@swbarnes2 I just have seen this thread: https://github.com/darwintreeoflife/darwintreeoflife.data/issues/2#event-4859159249 and tried to make it more googlable (because I do think there will be quite a few people who will be downloading the tDToL data).
Kamil S Jaron
CC BY-SA 4.0
2021-06-10T16:45:38.643Z
I saw that thread too.  I don't think it's right.  samtools fastq -2 will work fine for bams from many applications, but not 10XGenomics.
swbarnes2
CC BY-SA 4.0
2021-07-25T01:21:38.853Z
@kamil, can you post a couple of lines of the BAM file showing how tags for R1 and R2 appear in 10x data? I can probably quite easily add support for this in https://genozip.com/sam2fq.html
Divon
CC BY-SA 4.0
2021-06-08T15:31:33.117Z
2021-06-08T22:42:02.747Z
2021-06-08T22:42:02.747Z
Kamil S Jaron
<p>You'll want to use the 10x provided bamtofastq tool to preserve the indices properly: <a href="https://github.com/10XGenomics/bamtofastq" rel="nofollow noreferrer">https://github.com/10XGenomics/bamtofastq</a></p>

CC BY-SA 4.0
2022-03-02T21:39:51.300Z
2022-03-02T21:39:51.300Z
chrisamiller
<p><a href="https://support.10xgenomics.com/single-cell-gene-expression/software/pipelines/latest/using/fastq-input" rel="nofollow noreferrer">10x Genomics</a> data are stored in three FASTQ files, besides the standard R1 and R2 reads, there is also a I1 file with some metadata. Sometimes however they are shipped in a single bam/cram file (e.g. the data from the Darwin Tree of Life). How can I convert the BAM or CRAM files to FASTQ?</p>
<p>-- edit --</p>
<p>Apparently, the I3 file is not 10x specific thing. It is an index generated when demultiplexing any Illumina data. See <a href="https://bioinformatics.stackexchange.com/questions/5178/what-is-the-index-fastq-file-sample-i-fastq-gz-generated-when-demultiplexing">this question</a> for a nice explanation.</p>

CC BY-SA 4.0
2021-06-08T20:12:25.183Z
Isn't I1 the index read not unique to 10x data? But normally demultiplexing Illumina data with `bcl2fastq` does not generate these reads with default arguments
Chris_Rands
CC BY-SA 4.0
2021-06-08T22:44:13.133Z
@Chris_Rands (after a bit of googling) you are right. I just not aware of its existence before I run into [this question on the tDToL GitHub](https://github.com/darwintreeoflife/darwintreeoflife.data/issues/2#event-4859159249). And then I thought I might as well put it here so it's easier to google it.
Kamil S Jaron
<sam><fastq><format-conversion><cram>
How to convert CRAM file with 10x data in three fastq files
# How to convert CRAM file with 10x data in three fastq files

(Asked by: username_0 on 2021-06-08)

[10x Genomics](https://support.10xgenomics.com/single-cell-gene-expression/software/pipelines/latest/using/fastq-input) data are stored in three FASTQ files, besides the standard R1 and R2 reads, there is also a I1 file with some metadata. Sometimes however they are shipped in a single bam/cram file (e.g. the data from the Darwin Tree of Life). How can I convert the BAM or CRAM files to FASTQ?

-- edit --

Apparently, the I3 file is not 10x specific thing. It is an index generated when demultiplexing any Illumina data. See [this question](https://bioinformatics.stackexchange.com/questions/5178/what-is-the-index-fastq-file-sample-i-fastq-gz-generated-when-demultiplexing) for a nice explanation.

**Tags:** sam, fastq, format-conversion, cram
> **Comments:**
> **username_1**: Isn't I1 the index read not unique to 10x data? But normally demultiplexing Illumina data with `bcl2fastq` does not generate these reads with default arguments  
> **username_0**: @Chris_Rands (after a bit of googling) you are right. I just not aware of its existence before I run into [this question on the tDToL GitHub](https://github.com/darwintreeoflife/darwintreeoflife.data/issues/2#event-4859159249). And then I thought I might as well put it here so it's easier to google it.  

---

## 2 answers

### Answer by username_0 on 2021-06-08. Score: 1

All can be done with samtools. This is how the Darwin Tree of Life folks convert it:
samtools fastq -@4 -i \
  -1 ${sample}_S${tag}_L%03s_R1_001.fastq.gz \
  -2 ${sample}_S${tag}_L%03s_R2_001.fastq.gz \
  --i1 ${sample}_S${tag}_L%03s_I1_001.fastq.gz \
  --index-format i8 ${lane}.cram

> **Comments:**
> **username_2**: I don't know if that solution will work with 10xGenomics files.  You have to recreate R2 out of the contents of tags; there will be no reads with the read2 binary flag set.  
> **username_0**: @swbarnes2 I just have seen this thread: https://github.com/darwintreeoflife/darwintreeoflife.data/issues/2#event-4859159249 and tried to make it more googlable (because I do think there will be quite a few people who will be downloading the tDToL data).  
> **username_2**: I saw that thread too.  I don't think it's right.  samtools fastq -2 will work fine for bams from many applications, but not 10XGenomics.  
> **username_3**: @kamil, can you post a couple of lines of the BAM file showing how tags for R1 and R2 appear in 10x data? I can probably quite easily add support for this in https://genozip.com/sam2fq.html  

---

### Answer by username_4 on 2022-03-02. Score: 1

You'll want to use the 10x provided bamtofastq tool to preserve the indices properly: <https://github.com/10XGenomics/bamtofastq>


---

