I am aligning paired-end reads to a reference genome. I am having troubles when it comes to sorting and indexing the bam files. I have always used a bai index, however, I have learned that the genome is too large for this species and therefore a bai index won't work. Instead I am now using a csi index.
I am having multiple problems using a csi index. Originally I was getting the following error: [E::hts_idx_push] NO_COOR reads not in a single block at the end 1 -1
. I fixed this by sorting the mapped and unmapped reads separately then combining them. But now I am getting the following error: [E::hts_idx_push] Chromosome blocks not continuous
. I cannot figure out what is the issue. Any help would be appreciated. The code chunk I am running is below.
samtools view -b -F 4 bwa_assem_pe/$basename.bam > bwa_assem_pe/$basename.mapped.bam
samtools view -b -f 4 bwa_assem_pe/$basename.bam > bwa_assem_pe/$basename.unmapped.bam
samtools sort bwa_assem_pe/$basename.mapped.bam -o bwa_assem_pe/$basename.mapped.sorted.bam
samtools sort bwa_assem_pe/$basename.unmapped.bam -o bwa_assem_pe/$basename.unmapped.sorted.bam
samtools cat -o bwa_assem_pe/$basename.sorted.bam bwa_assem_pe/$basename.mapped.sorted.bam bwa_assem_pe/$basename.unmapped.sorted.bam
samtools index -c -m 14 bwa_assem_pe/$basename.sorted.bam
I have tried multiple fixes to no success. Advice and help would be greatly appreciated.