Given a BAM file, I'd like to calculate the sum, over all reads, of the mapping quality and the number of mapped bases (i.e. number of M's in the CIGAR string).
For example, given two reads like this:
read1: mapq=40, mapped_bases=10
read2: mapq=20, mapped_bases=50
The number I'm looking for is:
(40*10) + (20*50) = 1400
One option here is to stream the file and get the two quantities line-by-line. But this seems likely to be slow. Thoughts welcome.