Question: Use samtools index on multiple bam files at the same time from the command line?
2
gravatar for nash.claire
2.9 years ago by
nash.claire300
Canada
nash.claire300 wrote:

Hi all,

Simple question, is it possible to run samtools index (or any of the samtools in fact) on multiple bam files at the same time from the command line? I tried $ samtools index *.bam from within the directory with all more bam files stored and got the following error 

Samtools-htslib-API: bam_index_build2() not yet implemented

Abort trap: 6

I also had a go at using $ ls *.bam | samtools index which also didn't work. To note, my bam files are all co-ordinate sorted. I went through the pain of doing that one by one. 

It would be especially useful to be able to use samtools on multiple files when it comes to filtering on MAPQ scores etc etc. 

Any ideas?

myposts rna-seq sequence next-gen • 2.9k views
ADD COMMENTlink modified 2.9 years ago • written 2.9 years ago by nash.claire300

Thanks Pierre I'll try it out. I already have GNU Parallel installed so I'll use that. And this should work for other samtools too?

And can I ask a naive newbie question? What is the '{}' doing specifically? What does it mean? I saw this in other posts and wasn't sure.

ADD REPLYlink written 2.9 years ago by nash.claire300

'{}' will be replaced by the filename.

ADD REPLYlink written 2.9 years ago by Pierre Lindenbaum114k

And sorry to bug you again but I just tried the following command :-

$ ls *.bam | parallel samtools view -b -q 23 '{}'

in an effort to try out Parallel with a different samtool (I want to filter multiple bam files based on mapq score) and this happened and scared me....

I got reams and reams of stuff like this before terminal eventually stopped responding (I think it crashed)

2??E??4,%e???

?v????C?d?8.??e??d/?f?j???e??ʫ?W?/j    ?????Cy??%??)Ǫi%zp??H???"??x???Q??FڌTb?b?q??Ф???q#Ӳ?I?Ua?,%?

                                                                                                    gF?s??#6??6???<8T????u?Gđ?@?/?i?X??3??lS?&

                                                                                                                                              ??'y??1ȱ?w?G?j?XM?"*,t?GQ3ZT??h??#)

       ??;?kG?f??v:???N6@5?f???`?

?.Lم?5?6_??VWYQk?^???%????5

                           ???Z?.?f??XV??F??{jr(?c??=/!G?D??-HV??\??(?v??b?_?go??????<?,I?e?|?]p?9V?qN?h??O?{[???|x?ˬ<e?l;l󞄭?R??Bz94l???:?>???*?]*?٪?F

ub????o?A?M~?<E?????H:H?0?3?)?"y??s89מ3O^A2?>=?w?4?>)?5S}?ѓ???+.?QP.????k?Q??dgV?+?O]??F???@?K]?L?B̓fs?h?,M"??T8PTZ???

I'm guessing that ain't normal??

 

ADD REPLYlink written 2.9 years ago by nash.claire300

because samtools view (not index as you asked) ouput bam to stdout. See the parallel manual for '{.}' and '{/}' etc...

ADD REPLYlink written 2.9 years ago by Pierre Lindenbaum114k
9
gravatar for Pierre Lindenbaum
2.9 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum114k wrote:

use XARGS

ls *.bam | xargs -n1 -P5 samtools index

or GNU parallel :

ls *.bam | parallel samtools index '{}'
ADD COMMENTlink modified 2.9 years ago • written 2.9 years ago by Pierre Lindenbaum114k
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: 1578 users visited in the last hour