samtools sort -n file -o{file}_sorted.bam
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
.