Question: bedtools questions ! can't sort/index by samtools after bedToBam command
0
gravatar for zhaizhaoyu7
5 weeks ago by
zhaizhaoyu70 wrote:

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!

rna-seq software error • 126 views
ADD COMMENTlink written 5 weeks ago by zhaizhaoyu70
1

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:

bedtools bedtobam -i /sample.bed -g genome > new_sample.bam

overall something is not quite right with your sam file. Investigate the SAM file you've created.

samtools view new_sample.bam

the follow the errors if you get any

ADD REPLYlink modified 5 weeks ago • written 5 weeks ago by Istvan Albert ♦♦ 85k

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

[main_samview] truncated file.

Any reply will be appreciated.

ADD REPLYlink modified 5 weeks ago • written 5 weeks ago by zhaizhaoyu70
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1203 users visited in the last hour