Or far less complicated:
for f in *.bam ; do samtools view -b $f chr1:100-1000 > part-$f ; done
• 0 views
•
link
Hello,
I want to extract regions of multiple bamfiles kept as seperate files using the following samtools command:
samtools view -b a.bam refsequence :113111720-113112765 > aoutput.bam
How can I modify the above command so it works on multiple bamfiles example:a.bam b.bam c.bam d.bam simultaneously? I am currently doing this one bamfile at a time and it is taking forever. Thanks
To output one BAM:
samtools merge -r chr1:100-1000 - *.bam > out.bam
To output multiple BAMs:
ls *.bam|sed s,.bam,,|xargs -i echo samtools view -b {}.bam chr1:100-1000 > part-{}.bam|sh
Or far less complicated:
for f in *.bam ; do samtools view -b $f chr1:100-1000 > part-$f ; done
I don't think you can. If you made the .bam files with read group information, you could merge them togehter, then run the view command on that.
Log in to answer this question.