Answers.Body: <p>An unmapped read segment is any entry with bit 4 of the flag field set (i.e., it's unmapped). Assuming the reference to which you aligned reasonably matches the sample from which the reads were generated, less than ~10% of to total reads should be unmapped.</p>
  <p>Please note that BAM files have no idea what a &quot;feature&quot; is. They only contain information about reads and the chromosomes/contigs to which they align.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-14T12:56:21.600Z
Answers.Text: I have mapped to a gene catalogue, i.e., I have many references, and every line in the idxstats output correspondes to one such reference. I understand how a read mapped to a reference/gene/feature is associated with it, but a read unmapped is unmapped to all of them...
  
  But what you wrote about flags makes a lot of sense - I have to look what happened at the mapping step. Thanks.
Answers.UserDisplayName: Roger V.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-14T13:39:24.257Z
Answers.Text: For paired-end reads, some aligners will assign an unmapped read to the chromosome of its mate if its mate aligned (the unmapped bit in the flag will still be set).
Answers.UserDisplayName: Devon Ryan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-14T10:54:18.877Z
Answers.LastActivityDate: 2021-01-14T10:54:18.877Z
Answers.UserDisplayName: Devon Ryan
Body: <p><code>samtools idxstats</code> produces a four column output  (<a href="http://www.htslib.org/doc/samtools-idxstats.html" rel="nofollow noreferrer">see here</a>)</p>
  <pre><code>The output is TAB-delimited with each line consisting of reference sequence name, sequence length, 
  # mapped read-segments and # unmapped read-segments. It is written to stdout. Note this may count reads 
  multiple times if they are mapped more than once or in multiple fragments. 
  </code></pre>
  <p>What is the meaning of <em>unmapped reads</em> here? Naively, I would take it to mean all the reads that didn't map to a specific feature... however in a sample with millions of reads most of them should be counted as such, which is not the case in my calculations, where the number of unmapped reads is of the same order as the number of mapped reads.</p>
  <p>I will very much appreciate explanations from people experience with <code>samtools</code>.</p>
  
Tags: <samtools><read-mapping><reads><featurecounts>
Title: What is "unmapped read segments" in the output of samtools idxstats?
ThreadText: # What is "unmapped read segments" in the output of samtools idxstats?
  
  (Asked by: username_0 on 2021-01-14)
  
  `samtools idxstats` produces a four column output ([see here](http://www.htslib.org/doc/samtools-idxstats.html))
  
  ```
  The output is TAB-delimited with each line consisting of reference sequence name, sequence length, 
  # mapped read-segments and # unmapped read-segments. It is written to stdout. Note this may count reads 
  multiple times if they are mapped more than once or in multiple fragments. 
  
  ```
  
  What is the meaning of *unmapped reads* here? Naively, I would take it to mean all the reads that didn't map to a specific feature... however in a sample with millions of reads most of them should be counted as such, which is not the case in my calculations, where the number of unmapped reads is of the same order as the number of mapped reads.
  
  I will very much appreciate explanations from people experience with `samtools`.
  
  **Tags:** samtools, read-mapping, reads, featurecounts
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-01-14. Score: 2 | Accepted answer
  
  An unmapped read segment is any entry with bit 4 of the flag field set (i.e., it's unmapped). Assuming the reference to which you aligned reasonably matches the sample from which the reads were generated, less than ~10% of to total reads should be unmapped.
  
  Please note that BAM files have no idea what a "feature" is. They only contain information about reads and the chromosomes/contigs to which they align.
  
  > **Comments:**
  > **username_0**: I have mapped to a gene catalogue, i.e., I have many references, and every line in the idxstats output correspondes to one such reference. I understand how a read mapped to a reference/gene/feature is associated with it, but a read unmapped is unmapped to all of them...  But what you wrote about flags makes a lot of sense - I have to look what happened at the mapping step. Thanks.  
  > **username_1**: For paired-end reads, some aligners will assign an unmapped read to the chromosome of its mate if its mate aligned (the unmapped bit in the flag will still be set).  
  
  ---
  
  