<commit_before>from app.readers import tsv as tsvreader
from app.dataformats import prottable as prottabledata
from app.dataformats import mzidtsv as mzidtsvdata


def add_ms1_quant_from_top3_mzidtsv(proteins, peptides):
    """Collects peptides or PSMs with the highes precursor quant values,
    adds sum of the top 3 of these to a protein table"""
    top_ms1_peptides = {}
    for peptide in peptides:
        protacc = peptide[mzidtsvdata.HEADER_MASTER_PROT]
        precursor_amount = peptide[mzidtsvdata.HEADER_PRECURSOR_QUANT]
        if ';' in protacc or precursor_amount == 'NA':
            continue
        precursor_amount = float(precursor_amount)
        pep_id = tsvreader.get_psm_id(peptide)
        try:
            min_precursor_amount = min(top_ms1_peptides[protacc])
        except KeyError:
            top_ms1_peptides[protacc] = {-1: None, -2: None,
                                         precursor_amount: pep_id}
            continue
        else:
            if precursor_amount > min_precursor_amount:
                top_ms1_peptides[protacc][precursor_amount] = pep_id
                top_ms1_peptides[protacc].pop(min_precursor_amount)
    for protein in proteins:
        outprotein = {k: v for k, v in protein.items()}
        try:
            amounts = top_ms1_peptides[protein[prottabledata.HEADER_PROTEIN]]
        except KeyError:
            prec_area = 'NA'
        else:
            amounts = [x for x in amounts if x > 0]
            prec_area = sum(amounts) / len(amounts)
        outprotein[prottabledata.HEADER_AREA] = str(prec_area)
        yield outprotein


def get_quantchannels(pqdb):
    quantheader = []
    for fn, chan_name, amnt_psms_name in pqdb.get_quantchannel_headerfields():<commit_msg>MS1 quant for proteins is from PSMs, not peptides. Highest PSMs (that made FDR cut) are taken, not highest peptides (which are PSMs with best svm score)<commit_after>from app.readers import tsv as tsvreader
from app.dataformats import prottable as prottabledata
from app.dataformats import mzidtsv as mzidtsvdata


def add_ms1_quant_from_top3_mzidtsv(proteins, psms):
    """Collects PSMs with the highes precursor quant values,
    adds sum of the top 3 of these to a protein table"""
    top_ms1_psms = {}
    for psm in psms:
        protacc = psm[mzidtsvdata.HEADER_MASTER_PROT]
        precursor_amount = psm[mzidtsvdata.HEADER_PRECURSOR_QUANT]
        if ';' in protacc or precursor_amount == 'NA':
            continue
        precursor_amount = float(precursor_amount)
        psm_seq = psm[mzidtsvdata.HEADER_PEPTIDE]
        try:
            min_precursor_amount = min(top_ms1_psms[protacc])
        except KeyError:
            top_ms1_psms[protacc] = {-1: None, -2: None,
                                         precursor_amount: psm_seq}
            continue
        else:
            if precursor_amount > min_precursor_amount:
                top_ms1_psms[protacc][precursor_amount] = psm_seq 
                top_ms1_psms[protacc].pop(min_precursor_amount)
    for protein in proteins:
        outprotein = {k: v for k, v in protein.items()}
        try:
            amounts = top_ms1_psms[protein[prottabledata.HEADER_PROTEIN]]
        except KeyError:
            prec_area = 'NA'
        else:
            amounts = [x for x in amounts if x > 0]
            prec_area = sum(amounts) / len(amounts)
        outprotein[prottabledata.HEADER_AREA] = str(prec_area)
        yield outprotein


def get_quantchannels(pqdb):
    quantheader = []
    for fn, chan_name, amnt_psms_name in pqdb.get_quantchannel_headerfields():
{'fraction_non_alphanumeric': 0.07172760256768071, 'fraction_numerical': 0.006977393245883338, 'mean_word_length': 2.5732801595214356, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1426066', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1143, 'n_words': 279}