This is a test version of Biostars. For the public version, visit https://www.biostars.org.
how to generate a bai ?

I made a complete genome assembly and then tried to generate a bai using this command (with the file path):

samtools index /home/ims.santos06/bam/SRR062634.bam/home/ims.santos06/bam/SRR062634.bam.bai

but it did not work because of this error:

[E :: hts_idx_push] Unsorted positions on sequence # 6: 68538456 followed by 68538386
samtools index: failed to create index for "/home/ims.santos06/bam/SRR062634.bam".

Was it a mistake in the assembly? How do I solve this problem?

assembly

A message to both manubiomed20 and darbinator :

Please use the formatting bar (especially the code option) to present your post better. You can use backticks for inline code (`text` becomes text), or select a chunk of text and use the highlighted button to format it as a code block. I've done it for you this time.
code_formatting

Indexing automatically generates a file which ends in .bai and uses the name of the BAM file you used as an input for samtools index.

1 answer

You need to sort your alignments files before to index them:

samtools sort yourfile.bam > yourfile.sorted.bam

Log in to answer this question.