This seems to work. Thank you! The number seem to line up extremely well when confirmed with this method:
- awk 'BEGIN{sum=0;}{if(NR%4==2){sum+=length($0);}}END{print sum;}' file.fq
And off by more than 1% when confirmed with this method:
- cat test.fastq | paste - - - - | cut -f 2 | tr -d '\n' | wc -c
As denoted here:
Counting Number Of Bases In A Fastq File
I may dig in deeper as the "inaccurate" method is the one that's the most up-voted. But thank you!
So...your plan is to map, look at per-base coverage across a set of targets or something, then downsample the reads so you have an absolute known coverage with zero variability? I'm confused by your calculations - are you just saying that sample 1 has X reads so, given a mean length of Y bases/read, you can assume average depth of 13x across all positions of interest? But, you know there will be some variability due to, say, read QC or something, so you want to do the calculations per-base as opposed to per-read? I also don't know why you'd have a variable reference size here, so I'm lost with respect to that detail as well.
Why not try something like
bbtools'BBNorm?I just want to guarantee 13x coverage.
I'm comparing the performance of multiple wet lab protocols. The following variables changed between samples:
The project was designed by a team of PhD's and I'm just the guy processing the data. I won't know what they are looking at/for until I see the final presentation.
Thanks for clarifying. I've never seen an absolute requirement this stringent, so I was just curious as to the purpose. Genomax' solution below is a good starting place.