This is a test version of Biostars. For the public version, visit https://www.biostars.org.
samtools index error

Hello everyone I am trying to extract uniquely aligned reads and sort them with samtools with the following command

samtools view -h -f 2 -q 10 -bS -@ 20 hg38.sam | samtools sort -n -@ 1 > hg38.sort.bam

after this when I try to index the output file

samtools index hg38.sort.bam

I get this error message

[E::hts_idx_push] Unsorted positions on sequence #16: 73874275 followed by 73874203
[E::sam_index] Read 'SRR10984462.26' with ref_name='chr16', ref_length=90338345, flags=163, pos=73874203 cannot be indexed
samtools index: failed to create index for "hg38.sort.bam": No such file or directory

any suggestions ?

alignment

1 answer

option -n of samtools sort is for sorting on read name, not on coordinate. Remove this this.option.

Log in to answer this question.