Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-09T19:41:08.487Z
Answers.Text: 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.
Answers.UserDisplayName: swbarnes2
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-10T09:39:28.890Z
Answers.Text: @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).
Answers.UserDisplayName: Kamil S Jaron
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-10T16:45:38.643Z
Answers.Text: 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.
Answers.UserDisplayName: swbarnes2
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-25T01:21:38.853Z
Answers.Text: @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
Answers.UserDisplayName: Divon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-08T15:31:33.117Z
Answers.LastActivityDate: 2021-06-08T22:42:02.747Z
Answers.LastEditDate: 2021-06-08T22:42:02.747Z
Answers.UserDisplayName: Kamil S Jaron
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-02T21:39:51.300Z
Answers.LastActivityDate: 2022-03-02T21:39:51.300Z
Answers.UserDisplayName: chrisamiller
Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-06-08T20:12:25.183Z
Comments.Text: 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
Comments.UserDisplayName: Chris_Rands
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-06-08T22:44:13.133Z
Comments.Text: @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.
Comments.UserDisplayName: Kamil S Jaron
Tags: <sam><fastq><format-conversion><cram>
Title: How to convert CRAM file with 10x data in three fastq files
ThreadText: # 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**: @username_1 (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](http://www.htslib.org/). This is how [the Darwin Tree of Life folks convert it](https://github.com/darwintreeoflife/darwintreeoflife.data/issues/2#event-4859159249):
  
  ```
  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**: @username_2 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**: @username_0, 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>
  
  
  ---
  
  