Hi all ! After I use STAR to alignment , I got the BAM file , this BAM file could index successfully by samtools , but after converting this BAM file to BED with command
bedtools bamtobed -i sample.bam > sample.bed
and then,I use bedtobam convert it to bam
bedtools bedtobam -i /sample.bed -g genome > new_sample.bam
I want to index this new BAM ,so I run
samtools index new_sample.bam
But I got this error finally
[E::hts_idx_push] Unsorted positions on sequence #1: 248926319 followed by 127352
samtools index: failed to create index for "new_sample.bam"
Why? Is there any wrong that makes this happen? How I can fix this problem ?
And I try to use samtools view to see what happen,but I got this,here is the command and error
samtools view -h new_sample.bam | head -10
@HD VN:1.0 SO:unsorted
VN:Vv2.29.2 [main_samview] truncated file.
And samtools sort failed either
samtools sort: truncated file. Aborting
BTW:samtools version=1.9 bedtools version=2.29.2
I new to NGS ,any reply is greatly appreciated!