<commit_before>import os

from app.lookups import quant as lookups
from app.readers import openmz as readers
from app.preparation import openmz as preparation
from app.writers import tsv as writers


class BaseDriver(object):
    def __init__(self, **kwargs):
        self.outdir = kwargs['outdir']

    def create_outfilepath(self, fn, suffix=None):
        basefn, ext = os.path.splitext(os.path.basename(fn))
        outfn = basefn + suffix + ext
        return os.path.join(self.outdir, outfn)


class TSVQuantDriver(BaseDriver):
    def __init__(self, **kwargs):
        super(TSVQuantDriver, self).__init__(**kwargs)
        self.spectrafn = kwargs.get('spectra', None)
        self.quantfn = kwargs.get('quants', None)
        self.tsvfn = kwargs.get('tsv', None)

    def run(self):
        quantdb = self.create_quantlookup()
        self.generate_psms(quantdb)
        self.write()

    def create_quantlookup(self):
        """Creates sqlite file containing quantification data and
        spectra file/scan number data for looking up quant data.
        Returns sqlite file name.
        """
        spectra = readers.mzml_generator(self.spectrafn)
        consensus_quants = readers.quant_generator(self.quantfn)
        return lookups.create_quant_lookup(spectra, consensus_quants)

    def generate_psms(self, quantdb):
        self.psms = preparation.generate_psms_quanted(quantdb, self.tsvfn)

    def write(self):
        outfn = self.create_outfilepath(self.tsvm, 'quants')
        writers.write_quantpsm_tsv(self.header, self.psms, outfn)
<commit_msg>Created content generator calling code for tsv mzid with quant<commit_after>import os

from app.lookups import quant as lookups
from app.readers import openmz as readers
from app.preparation import openmz as preparation
from app.writers import tsv as writers


class BaseDriver(object):
    def __init__(self, **kwargs):
        self.outdir = kwargs['outdir']

    def create_outfilepath(self, fn, suffix=None):
        basefn, ext = os.path.splitext(os.path.basename(fn))
        outfn = basefn + suffix + ext
        return os.path.join(self.outdir, outfn)


class TSVQuantDriver(BaseDriver):
    def __init__(self, **kwargs):
        super(TSVQuantDriver, self).__init__(**kwargs)
        self.spectrafn = kwargs.get('spectra', None)
        self.quantfn = kwargs.get('quants', None)
        self.tsvfn = kwargs.get('tsv', None)

    def run(self):
        quantdb = self.create_quantlookup()
        self.generate_psms(quantdb)
        self.write()

    def create_quantlookup(self):
        """Creates sqlite file containing quantification data and
        spectra file/scan number data for looking up quant data.
        Returns sqlite file name.
        """
        spectra = readers.mzml_generator(self.spectrafn)
        consensus_quants = readers.quant_generator(self.quantfn)
        return lookups.create_quant_lookup(spectra, consensus_quants)

    def generate_tsv_content(self, quantdb):
        """Creates iterator to write to new tsv. Contains input tsv
        lines plus quant data for these."""
        quantheader = preparation.get_quant_header(quantdb)
        self.header = preparation.create_tsv_header_quant(self.tsvfn,
                                                          quantheader)
        self.psms = preparation.generate_psms_quanted(quantdb,
                                                      self.tsvfn,
                                                      quantheader)

    def write(self):
        outfn = self.create_outfilepath(self.tsvm, 'quants')
        writers.write_quantpsm_tsv(self.header, self.psms, outfn)

{'fraction_non_alphanumeric': 0.09140969162995595, 'fraction_numerical': 0.0, 'mean_word_length': 2.714723926380368, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4246298', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1057, 'n_words': 255}