Hello BioStars,

Is there a tool which generates mapping quality score distributions from bam files?

I know I could potentially do this myself, but I am looking for something which would essentially do the work for me, and also something which plugs in nicely to multiqc

I have had a quick search, and it is surprisingly difficult to find a tool which provides this functionality, so I am just wondering if I am missing something obvious here? The obvious candidate would be something like picard, but picard does not seem to offer this functionality from what I can tell

Thanks in advance!
This may be too simple for what you need, but I have a script [here][1] that uses pysam to extract MapQ scores from a bam file and then generates a kernel density plot of the scores.

Here is the actual code:

    #!/usr/bin/env python
    
    import pysam
    import seaborn as sns
    import argparse
    from matplotlib import pyplot as plt
    
    parser = argparse.ArgumentParser(description="Plot mapping quality score from bam file")
    
    parser.add_argument('--bam', required=True, help='path to input bam file', action='store')
    parser.add_argument('--png', required=True, help='path to output png file', action='store')
    
    args=parser.parse_args()
    
    output = args.png
    input = args.bam 
    
    bam = pysam.AlignmentFile(input, "rb")
    
    quals = [read.mapping_quality for read in bam.fetch()]
    
    sns.set_style("dark")
    sns.set_context("paper")
    
    plt.figure(figsize=(10,6))
    
    ax = sns.kdeplot(quals, shade = True)
    ax.set_ylabel('Density')
    ax.set_xlabel('Mapping Quality Score')
    
    plt.savefig(output)

  [1]: https://github.com/davidecarlson/Fasta-Manipulation/blob/master/plotMapQ.py