thanks, you are right, now it works!
Dear all,
I have aligned a file with the command:
bwa mem -t 10 <refFile> <input_1.fq.gz> <input_2.fq.gz> -o <output>.sam
then I converted the SAM to BAM with:
samtools view -Sb <output>.sam > <output>.bam
and I wanted to make the index of it with:
samtools index <output>.bam
but I got the error:
[E::hts_idx_push] NO_COOR reads not in a single block at the end 0 -1 samtools index: failed to create index for "output.bam"
To check if the error was due to missing alignment I checked the number of mapped reads with:
samtools -c -F 4 <output>.bam
but I got the error:
[main] unrecognized command '-c'
and when removing the flag -c I got:
samtools -F 4 <output>.bam
[main] unrecognized command '-F'
Why I got the [E::hts_idx_push] error? maybe a missing heading?
And why the flags are not recognized?
Thank you.
1 answer
There are two things:
1) Indexing requires coordinate-sorted files.
bwa mem idx file_1.fq.gz file_2.fq.gz | samtools sort -o file_sorted.bam -
samtools index file_sorted.bam
Directly pipe the sam file to the sort, there is no need to keep the uncompressed and unsorted sam files. They only take up space.
2) Your -c -f -F etc... commands must be used like samtools view -f -F -c (...). You did not specify the subcommand they belong to.
Log in to answer this question.