Help with Bam Sort
1
0
Entering edit mode
23 months ago

Hi All...

I am trying to sort a .bam file created by STAR. I am trying to use samtools sort. I use the following command...

$ samtools sort *.bam -o *sorted.bam

I get a common error I have seen when you dont use the right arguments for the software...it is pages and pages of gibberish, like....

???????????????ndjsjkbiu2b3odn?    >?????????
                          Hjvbqebdi3n2fonlk???????????????      ?????????

The .bam is not already sorted as when I try to use samtools index it says it is not sorted. I tried the direction arrow (>) instead of -o and it asks me to use -o.

Can someone help me trouble shoot this?

Is the -bam corrupted? Should I go back and redo the alignment with STAR and maybe send out put as a sorted -bam to save time? I already aligned 53 files and would prefer just to do the samtools sort.

Best,

Joe

Samtools • 966 views
ADD COMMENT
0
Entering edit mode

Sorry. I am not trying to use the wild card. I just stuck that in there....

here is the actual command I try to use....

$ samtools sort XYZ.bam -o XYZ.sorted.bam

I get the error...

I tried..

$ samtools sort XYZ.bam > XYZ.sorted.bam

and the samtools program asks me to use -o.

if I have tried both -o and > and neither work what could be the problem?

Joe

ADD REPLY
1
Entering edit mode
23 months ago
ATpoint 82k

This gibberish is the binary output file being sent to stdout. First of all, samtools is not wildcard-aware so just doing *.bam will not make it automatically run the sorting on all samples. You have to do a loop, GNU parallel or similar to wrap that in to run on several samples. Second, it could be that your samtools version is old and in that version the -o argument had not been introduced yet, in which the output needs to explicitely captured with like samtools sort (...) > sorted.bam.

Something like this should work:

for i in *.bam
  do
  samtools sort $i > ${i%.bam}_sorted.bam
  done

Or with -o if you upgrade to recent versions instead of >.

ADD COMMENT
0
Entering edit mode

The samtools is actually running. I see the intermediate files...

.bam.0000.bam .bam.0001.bam etc....

and then a sorted.bam with 0 bytes in it.

It is not finishing the job..

this is strange and I need an expert to help me with it...

Best,

Joe

ADD REPLY
0
Entering edit mode

Sorting will take a while to complete depending on the size of the input. As long as the job is running and you see temp files being produced wait. Once the sorting is done the sorted.bam file will be written to. On successful completion of the job the temp files will be removed automatically leaving just the finished sorted BAM file.

ADD REPLY
0
Entering edit mode

Meaning that the sorted.bam will be empty until the merging of the tmp files start at the end of the sorting...it's probably fine, just wait until it is completed.

ADD REPLY

Login before adding your answer.

Traffic: 2457 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