samtools index: failed to create index. ([E::hts_idx_push] NO_COOR reads not in a single block )
2
1
Entering edit mode
10 months ago
DareDevil ★ 4.3k

I have run hisat2 on paired end samples to generate sorted bam file. I used following command:

for r1 in *_1.fastq.gz; do sample=${r1/_1.fastq.gz/}; \
echo "Processing sample: "$sample; \
hisat2 -p 12 --rna-strandness RF -x /media/genome \
-1 $sample"_1.fastq.gz" -2 $sample"_2.fastq.gz" | samtools view -Sbo $sample.bam; \
done

Next. I tried to index the sorted bam file using samtools:

samtools index Sample1.bam Sample1.bam.bai

But it thrown me an error as follows:

[E::hts_idx_push] NO_COOR reads not in a single block at the end 18 -1
samtools index: failed to create index for "Sample1.bam"

How to rectify this error? Any help appreciated

bam samtools hisat2 • 961 views
ADD COMMENT
3
Entering edit mode
10 months ago
aw7 ▴ 340

Are you sure the hisat2 results are coordinate sorted?

Anyway, if you replace your samtools view with:

samtools sort --write-index -o $sample.bam

That should sort, index and write out a bam file in one command.

ADD COMMENT
2
Entering edit mode
10 months ago
svp ▴ 680

The aim your code seems to generate sorted bam files. Not sure the code you have written sorts your file You can sort it directly:

for r1 in *_1.fastq.gz; do sample=${r1/_1.fastq.gz/}; \
echo "Processing sample: "$sample; \
hisat2 -p 12 --rna-strandness RF -x /media/genome \
-1 $sample"_1.fastq.gz" -2 $sample"_2.fastq.gz" \
| samtools sort -o $sample.bam; \
done

You can index your bam files in parallel:

ls *.bam | parallel samtools index '{}'
ADD COMMENT

Login before adding your answer.

Traffic: 2689 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6