How to sub-sample .bam file to target coverage?
Hi,
I have .bam files for blood samples from which I extract signals. Let's assume my samples have a 30x coverage and my signal of interest is nicely detectable. To see how well the signal is detectable with lower coverage samples, I want to downsample to 20x, 10x, etc. Is there an easy way to do this?
So far I had a closer look at samtools view -s, but it takes only the target fraction and not a target coverage. Is there a program that lets me specify the target coverage that generalizes well for multiple samples with different start coverage?
• 1,968 views
•
link
0 answers
No answers yet.
Log in to answer this question.
If you want to downsample from 30x to 20x then then just do
samtools --subsample 0.66 .....This assumes that unaligned reads are not in the BAM file? If they are then it may be best to filter those out first.
someXcoverage is a fluid term and subject to interpretation so it could mean different things to different people.I know... If I had one sample or even five samples this would be my solution. I have hundreds of samples, all with different coverage and I was wondering whether there is a simpler solution that for example caps the max coverage to a certain value so that I don't have to calculate the fraction for each sample.