Question: samtools mpileup for multiple regions output in different files
gravatar for tonja.r
4.5 years ago by
tonja.r470 wrote:

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 • 1.7k views
ADD COMMENTlink modified 4.5 years ago by Devon Ryan94k • written 4.5 years ago by tonja.r470
gravatar for Devon Ryan
4.5 years ago by
Devon Ryan94k
Freiburg, Germany
Devon Ryan94k wrote:

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 COMMENTlink written 4.5 years ago by Devon Ryan94k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 871 users visited in the last hour