<commit_before>#!/usr/bin/env python

""" MultiQC module to parse output from featureCounts """

from __future__ import print_function
from collections import OrderedDict
import logging
import re

from multiqc import config
from multiqc.plots import linegraph
from multiqc.modules.base_module import BaseMultiqcModule

# Initialise the logger
log = logging.getLogger('multiqc')

class MultiqcModule(BaseMultiqcModule):

    def __init__(self):

        # Initialise the parent object
        super(MultiqcModule, self).__init__(name='DupRadar',
        target="dupRadar", anchor='dupRadar',
        href='https://www.bioconductor.org/packages/release/bioc/html/dupRadar.html',
        info="provides duplication rate quality control for RNA-Seq datasets. "
             "Highly expressed genes can be expected to have a lot of duplicate reads, "
             "but high numbers of duplicates at low read counts can indicate low library "
             "complexity with technical duplication.")

        # Find and load any dupRadar int_slope reports
        int_regex = r'(.*)- dupRadar Int \(duprate at low read counts\): ([\d\.]+)'
        slope_regex = r'(.*)- dupRadar Sl \(progression of the duplication rate\): ([\d\.]+)'
        self.dupradar_stats = dict()
        for f in self.find_log_files('ngi_rnaseq/dupradar_intslope'):
            for l in f['f'].splitlines():
                # Intercept
                m = re.search(int_regex, l)
                if m:
                    s_name = self.clean_s_name(m.group(1), f['root']).strip()
                    if s_name not in self.dupradar_stats:
                        self.dupradar_stats[s_name] = dict()
                    self.dupradar_stats[s_name]['dupRadar_int'] = m.group(2)

                # Slope
                m = re.search(slope_regex, l)
                if m:
                    s_name = self.clean_s_name(m.group(1), f['root']).strip()
                    if s_name not in self.dupradar_stats:
                        self.dupradar_stats[s_name] = dict()
                    self.dupradar_stats[s_name]['dupRadar_slope'] = m.group(2)

        # Find and load any dupRadar GML line plots
        self.dupradar_plots = dict()
        for f in self.find_log_files('ngi_rnaseq/dupradar_gml_intslope'):
            self.dupradar_plots[f['s_name']] = dict()
            for l in f['f'].splitlines():
                s = l.split()
                try:
                    self.dupradar_plots[f['s_name']][float(s[0])] = float(s[1])
                except (ValueError, IndexError):
                    pass

        if len(self.dupradar_stats) == 0 and len(self.dupradar_plots) == 0:
            log.debug("Could not find any reports in {}".format(config.analysis_dir))
            raise UserWarning

        log.info("Found {} reports".format(max(len(self.dupradar_stats), len(self.dupradar_plots))))

        # Write parsed report data to a file
        self.write_data_file(self.dupradar_stats, 'multiqc_dupRadar')

        # Add Int to General Stats table
        headers = OrderedDict()
        headers['dupRadar_int'] = {
            'title': 'dupRadar Int',
            'description': 'Int (duprate at low read counts)',
            'min': 0,
            'scale': 'RdYlGn-rev',
            'format': '{:,.2f}'
        }
        self.general_stats_addcols(self.dupradar_stats, headers)

        # Create line plot of GML lines
        pconfig = {
            'id': 'dupRadar_plot',
            'title': 'DupRadar General Linear Model',
            'ylab': '% duplicate reads',
            'xlab': 'expression (reads/kbp)',
            'ymax': 100,
            'ymin': 0,
            'xLog': True,
            'tt_label': '<b>{point.x:.0f} reads/kbp</b>: {point.y:,.2f}% duplicates',
            'xPlotLines': [{
                'value': 0.5,
                'color': 'green',
                'width': 1,
                'dashStyle': 'LongDash',
                'label': {
                    'text': '0.5 RPKM',
                    'verticalAlign': 'bottom',
                    'y': -65,
                    'style': {'color': 'green'}
                }
            },{
                'value': 1000,
                'color': 'red',
                'width': 1,
                'dashStyle': 'LongDash',
                'label': {
                    'text': '1 read/bp',
                    'verticalAlign': 'bottom',
                    'y': -65,
                    'style': {'color': 'red'}
                }
            }]
        }

        self.add_section(
            description = '''This plot shows the general linear models -
                a summary of the gene duplication distributions.''',
            plot = linegraph.plot(self.dupradar_plots, pconfig)
        )


<commit_msg>Made the dupradar tooltip a bit more helpful<commit_after>#!/usr/bin/env python

""" MultiQC module to parse output from featureCounts """

from __future__ import print_function
from collections import OrderedDict
import logging
import re

from multiqc import config
from multiqc.plots import linegraph
from multiqc.modules.base_module import BaseMultiqcModule

# Initialise the logger
log = logging.getLogger('multiqc')

class MultiqcModule(BaseMultiqcModule):

    def __init__(self):

        # Initialise the parent object
        super(MultiqcModule, self).__init__(name='DupRadar',
        target="dupRadar", anchor='dupRadar',
        href='https://www.bioconductor.org/packages/release/bioc/html/dupRadar.html',
        info="provides duplication rate quality control for RNA-Seq datasets. "
             "Highly expressed genes can be expected to have a lot of duplicate reads, "
             "but high numbers of duplicates at low read counts can indicate low library "
             "complexity with technical duplication.")

        # Find and load any dupRadar int_slope reports
        int_regex = r'(.*)- dupRadar Int \(duprate at low read counts\): ([\d\.]+)'
        slope_regex = r'(.*)- dupRadar Sl \(progression of the duplication rate\): ([\d\.]+)'
        self.dupradar_stats = dict()
        for f in self.find_log_files('ngi_rnaseq/dupradar_intslope'):
            for l in f['f'].splitlines():
                # Intercept
                m = re.search(int_regex, l)
                if m:
                    s_name = self.clean_s_name(m.group(1), f['root']).strip()
                    if s_name not in self.dupradar_stats:
                        self.dupradar_stats[s_name] = dict()
                    self.dupradar_stats[s_name]['dupRadar_int'] = m.group(2)

                # Slope
                m = re.search(slope_regex, l)
                if m:
                    s_name = self.clean_s_name(m.group(1), f['root']).strip()
                    if s_name not in self.dupradar_stats:
                        self.dupradar_stats[s_name] = dict()
                    self.dupradar_stats[s_name]['dupRadar_slope'] = m.group(2)

        # Find and load any dupRadar GML line plots
        self.dupradar_plots = dict()
        for f in self.find_log_files('ngi_rnaseq/dupradar_gml_intslope'):
            self.dupradar_plots[f['s_name']] = dict()
            for l in f['f'].splitlines():
                s = l.split()
                try:
                    self.dupradar_plots[f['s_name']][float(s[0])] = float(s[1])
                except (ValueError, IndexError):
                    pass

        if len(self.dupradar_stats) == 0 and len(self.dupradar_plots) == 0:
            log.debug("Could not find any reports in {}".format(config.analysis_dir))
            raise UserWarning

        log.info("Found {} reports".format(max(len(self.dupradar_stats), len(self.dupradar_plots))))

        # Write parsed report data to a file
        self.write_data_file(self.dupradar_stats, 'multiqc_dupRadar')

        # Add Int to General Stats table
        headers = OrderedDict()
        headers['dupRadar_int'] = {
            'title': 'dupRadar Int',
            'description': 'Int (duprate at low read counts) Low tech. duplication typically  < 0.5, high duplication > 1',
            'min': 0,
            'scale': 'RdYlGn-rev',
            'format': '{:,.2f}'
        }
        self.general_stats_addcols(self.dupradar_stats, headers)

        # Create line plot of GML lines
        pconfig = {
            'id': 'dupRadar_plot',
            'title': 'DupRadar General Linear Model',
            'ylab': '% duplicate reads',
            'xlab': 'expression (reads/kbp)',
            'ymax': 100,
            'ymin': 0,
            'xLog': True,
            'tt_label': '<b>{point.x:.0f} reads/kbp</b>: {point.y:,.2f}% duplicates',
            'xPlotLines': [{
                'value': 0.5,
                'color': 'green',
                'width': 1,
                'dashStyle': 'LongDash',
                'label': {
                    'text': '0.5 RPKM',
                    'verticalAlign': 'bottom',
                    'y': -65,
                    'style': {'color': 'green'}
                }
            },{
                'value': 1000,
                'color': 'red',
                'width': 1,
                'dashStyle': 'LongDash',
                'label': {
                    'text': '1 read/bp',
                    'verticalAlign': 'bottom',
                    'y': -65,
                    'style': {'color': 'red'}
                }
            }]
        }

        self.add_section(
            description = '''This plot shows the general linear models -
                a summary of the gene duplication distributions.''',
            plot = linegraph.plot(self.dupradar_plots, pconfig)
        )



{'fraction_non_alphanumeric': 0.12157392026578073, 'fraction_numerical': 0.006748338870431894, 'mean_word_length': 1.7312163311596258, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3004783', 'n_tokens_mistral': 2998, 'n_tokens_neox': 2741, 'n_words': 683}