Getting 'Samtools View' To Work On Multiple Bamfiles Simultaneously
2
2
Entering edit mode
12.4 years ago
Kwame ▴ 20

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

samtools bam • 7.0k views
ADD COMMENT
10
Entering edit mode
12.4 years ago
lh3 33k

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
ADD COMMENT
1
Entering edit mode

Or far less complicated:

for f in *.bam ; do samtools view -b $f chr1:100-1000 > part-$f ; done

ADD REPLY
0
Entering edit mode
12.4 years ago
Swbarnes2 ★ 1.6k

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.

ADD COMMENT

Login before adding your answer.

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