Question: samtools mpileup for multiple regions output in different files
0
gravatar for tonja.r
3.7 years ago by
tonja.r450
UK
tonja.r450 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.4k views
ADD COMMENTlink modified 3.7 years ago by Devon Ryan90k • written 3.7 years ago by tonja.r450
1
gravatar for Devon Ryan
3.7 years ago by
Devon Ryan90k
Freiburg, Germany
Devon Ryan90k 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 3.7 years ago by Devon Ryan90k
Please log in to add an answer.

Help
Access

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