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

""" MultiQC module to parse output from Bowtie """

from __future__ import print_function
import json
import logging
import mmap
import os
import re

import multiqc

class MultiqcModule(multiqc.BaseMultiqcModule):

    def __init__(self, report):

        # Initialise the parent object
        super(MultiqcModule, self).__init__()

        # Static variables
        self.name = "Bowtie"
        self.anchor = "bowtie"
        self.intro = '<p><a href="http://bowtie-bio.sourceforge.net/" target="_blank">Bowtie</a> \
            is an ultrafast, memory-efficient short read aligner.</p>'
        self.analysis_dir = report['analysis_dir']
        self.output_dir = report['output_dir']

        # Find and load any Bowtie reports
        self.bowtie_data = dict()
        for root, dirnames, filenames in os.walk(self.analysis_dir):
            for fn in filenames:
                if os.path.getsize(os.path.join(root,fn)) < 10000:
                    try:
                        with open (os.path.join(root,fn), "r") as f:
                            s = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
                            self.bowtie_data[fn] = self.parse_bowtie_logs(s)
                    except ValueError:
                        logging.debug("Couldn't read file when looking for bowtie output: {}".format(fn))

        if len(self.bowtie_data) == 0:
            logging.debug("Could not find any Bowtie reports in {}".format(self.analysis_dir))
            raise UserWarning

        logging.info("Found {} Bowtie reports".format(len(self.bowtie_data)))

        # Write parsed report data to a file
        # Only the summary stats - skip the length data (t_lengths)
        with open (os.path.join(self.output_dir, 'report_data', 'multiqc_bowtie.txt'), "w") as f:
            print( self.dict_to_csv( { k: { j: x for j, x in v.iteritems() if j != 't_lengths'} for k, v in self.bowtie_data.iteritems() } ), file=f)

        self.sections = list()
<commit_msg>Bowtie WIP. Stopped it from throwing an exception on every run.<commit_after>#!/usr/bin/env python

""" MultiQC module to parse output from Bowtie """

from __future__ import print_function
import json
import logging
import mmap
import os
import re

import multiqc

class MultiqcModule(multiqc.BaseMultiqcModule):

    def __init__(self, report):

        # Initialise the parent object
        super(MultiqcModule, self).__init__()

        # Static variables
        self.name = "Bowtie"
        self.anchor = "bowtie"
        self.intro = '<p><a href="http://bowtie-bio.sourceforge.net/" target="_blank">Bowtie</a> \
            is an ultrafast, memory-efficient short read aligner.</p>'
        self.analysis_dir = report['analysis_dir']
        self.output_dir = report['output_dir']

        # Find and load any Bowtie reports
        self.bowtie_data = dict()
        for root, dirnames, filenames in os.walk(self.analysis_dir):
            for fn in filenames:
                if os.path.getsize(os.path.join(root,fn)) < 10000:
                    try:
                        with open (os.path.join(root,fn), "r") as f:
                            s = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
                            parsed_data = self.parse_bowtie_logs(s)
                            if parsed_data is not None:
                                self.bowtie_data[fn] = parsed_data
                    except ValueError:
                        logging.debug("Couldn't read file when looking for bowtie output: {}".format(fn))

        if len(self.bowtie_data) == 0:
            logging.debug("Could not find any Bowtie reports in {}".format(self.analysis_dir))
            raise UserWarning

        logging.info("Found {} Bowtie reports".format(len(self.bowtie_data)))

        # Write parsed report data to a file
        # Only the summary stats - skip the length data (t_lengths)
        with open (os.path.join(self.output_dir, 'report_data', 'multiqc_bowtie.txt'), "w") as f:
            print( self.dict_to_csv( { k: { j: x for j, x in v.iteritems() if j != 't_lengths'} for k, v in self.bowtie_data.iteritems() } ), file=f)

        self.sections = list()

{'fraction_non_alphanumeric': 0.11074144486692016, 'fraction_numerical': 0.003326996197718631, 'mean_word_length': 2.210526315789474, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6929200', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1220, 'n_words': 343}