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
@PG ID:BEDTools_bedToBam
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!
the command you posted does not look right, that slash in front of sample.bed indicates a file in the root of you computer, most likely it is not what you ran:
overall something is not quite right with your sam file. Investigate the SAM file you've created.
the follow the errors if you get any
Thanks for your reply!
I cut my absolute path because it's too long ,sorry that I left a '/'.
Apart from this,I didn't got any SAM file , I only have the BAM file in coordinate after I ran STAR.And I can index this BAM successfully. That's what I'm confused,there are only two steps:bedtools bamtobed and bedtobam,then I got the wrong BAM .
Here is samtools view I got without -h
Any reply will be appreciated.