samtools mpileup for multiple regions output in different files
1
0
Entering edit mode
8.6 years ago
tonja.r ▴ 600

I am using samtools mpileup over different regions:

samtools mpileup -Q 0 -l regions.bed reads.sort.bam > counts.txt

I would like to output for each region (in regions.bed) a separated file, so that results from different regions will be in different output files. Is there any possibility to do so without running a samtools command for each region separately?

Or is it possible to output results in different files for different .bam files without again running a loop for each file?

samtools mpileup -Q 0 -l chr1:1222454-1342444 reads1.sort.bam reads2.sort.bam > counts.txt​
sequencing • 2.8k views
ADD COMMENT
1
Entering edit mode
8.6 years ago

For the first method (1 BAM file, multiple regions), you can probably pipe the output to bedtools intersect (you'll probably need to munge things with awk) and then pipe that to awk, where you could reformat the region columns into a file name and redirect to it (something like ... | awk 'BEGIN{OFS="\t"}{ofile=some_manipulation; print $1,$2,$3 > ofile}').

For the second method (multiple BAM files, one region), you would just pipe to awk and write the appropriate columns to different files. The only downside to this is that you probably need to tell awk the region, so it can write everything to a new file.

Personally, I'd just write a little script using pysam to do this, but to each his/her own.

ADD COMMENT

Login before adding your answer.

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