ls *.bam | xargs -n1 -P5 samtools index works in my hands, but what are the meanings of -n1 and -P5? Thank you very much!
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?
1 answer
use XARGS
ls *.bam | xargs -n1 -P5 samtools index
or GNU parallel:
ls *.bam | parallel samtools index '{}'
UPDATE 2023:
http://www.htslib.org/doc/samtools-index.html
I think samtools index now supports the following syntax:
samtools index -M *.bam
When doing samtools index *.bam an error occurs:
samtools index *.bam
samtools index: use -M to enable indexing more than one alignment file
Hence the working command working for me is:
samtools index *.bam -M
Log in to answer this question.
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.
'{}' will be replaced by the filename.
And sorry to bug you again but I just tried the following command :-
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)
I'm guessing that ain't normal??
because samtools view (not index as you asked) ouput bam to stdout. See the parallel manual for '{.}' and '{/}' etc...