<p>This is essentially a duplicate of <a href="https://bioinformatics.stackexchange.com/questions/13997/samtools-index-chromosome-blocks-not-continuous">Samtools Index: Chromosome Blocks not Continuous</a> but with different error messages, and a duplicate of <a href="https://bioinformatics.stackexchange.com/questions/5352/error-given-while-trying-to-index-a-bam-file-with-samtools-index-no-coor">Error given while trying to index a BAM file with Samtools Index - NO COOR?</a>.</p>
<pre><code>samtools sort -n ${file} -o ${file}_sorted.bam
</code></pre>
<p>These error messages also indicate that the reads are not sorted by coordinate — in particular, that the unplaced unmapped reads with RNAME <code>*</code> are not all together at the end of the file.</p>
<p>This is because <code>samtools sort -n</code> has been used to sort the reads by name instead. Remove <code>-n</code> to sort by position, which is what is needed to prepare a BAM file for indexing with <code>samtools index</code>.</p>

CC BY-SA 4.0
2020-08-20T08:12:39.520Z
Thank you! problem solved :)
user9393
CC BY-SA 4.0
2020-08-19T07:29:20.887Z
2020-08-20T07:06:22.450Z
2020-08-20T07:06:22.450Z
John Marshall
<p>I am doing an RNA seq analysis with mouse samples. I had my reads in several lanes, so I concatenated those fastq reads. Then I've mapped my reads with Hisat2 against the new version of mouse  &quot;GCA_000001635.9_GRCm39_genomic.fna&quot;.</p>
<p>Apparently everything works well up to here. Now I'm using samtools 1.9 to convert sam to bam, to sort those bam and create the index, just like this:</p>
<pre><code>samtools view -bS <span class="math-container">${file} &gt; $</span>{file}.bam

samtools sort -n <span class="math-container">${file} -o $</span>{file}_sorted.bam

samtools index  ${file}_sorted.bam
</code></pre>
<p>But when indexing I get this error:</p>
<blockquote>
<p>[bam_sort_core] merging from 11 files and 1 in-memory blocks...
[E::hts_idx_push] NO_COOR reads not in a single block at the end 0 -1
samtools index: failed to create index for
&quot;CD4_1A_concat.bam_sorted.bam&quot;: No such file or directory</p>
<p>[bam_sort_core] merging from 11 files and 1 in-memory blocks...
[E::hts_idx_push] NO_COOR reads not in a single block at the end 23 -1
samtools index: failed to create index for
&quot;CD4_1B_concat.bam_sorted.bam&quot;: No such file or directory
[bam_sort_core] merging from 11 files and 1 in-memory blocks...</p>
</blockquote>
<p>And more...</p>
<p>Any help would be appreciated!</p>

<rna-seq><samtools>
NO_COOR reads not in a single block at the end 0 -1
# NO_COOR reads not in a single block at the end 0 -1

(Asked by: username_0 on 2020-08-19)

I am doing an RNA seq analysis with mouse samples. I had my reads in several lanes, so I concatenated those fastq reads. Then I've mapped my reads with Hisat2 against the new version of mouse  "GCA_000001635.9_GRCm39_genomic.fna".
Apparently everything works well up to here. Now I'm using samtools 1.9 to convert sam to bam, to sort those bam and create the index, just like this:
samtools view -bS ${file} > ${file}.bam

samtools sort -n ${file} -o ${file}_sorted.bam

samtools index  ${file}_sorted.bam

But when indexing I get this error:

[bam_sort_core] merging from 11 files and 1 in-memory blocks...
[E::hts_idx_push] NO_COOR reads not in a single block at the end 0 -1
samtools index: failed to create index for
"CD4_1A_concat.bam_sorted.bam": No such file or directory
[bam_sort_core] merging from 11 files and 1 in-memory blocks...
[E::hts_idx_push] NO_COOR reads not in a single block at the end 23 -1
samtools index: failed to create index for
"CD4_1B_concat.bam_sorted.bam": No such file or directory
[bam_sort_core] merging from 11 files and 1 in-memory blocks...

And more...
Any help would be appreciated!

**Tags:** rna-seq, samtools

---

## 1 answers

### Answer by username_1 on 2020-08-19. Score: 2

This is essentially a duplicate of Samtools Index: Chromosome Blocks not Continuous but with different error messages, and a duplicate of Error given while trying to index a BAM file with Samtools Index - NO COOR?.
samtools sort -n ${file} -o ${file}_sorted.bam

These error messages also indicate that the reads are not sorted by coordinate — in particular, that the unplaced unmapped reads with RNAME * are not all together at the end of the file.
This is because samtools sort -n has been used to sort the reads by name instead. Remove -n to sort by position, which is what is needed to prepare a BAM file for indexing with samtools index.

> **Comments:**
> **username_0**: Thank you! problem solved :)  

---

