Fed with a psms generator, this returns the master proteins present
    in the PSM table. PSMs with multiple master proteins are excluded.
491025
def generate_master_proteins(psms, protcol):
    """"""
    master_proteins = {}
    if not protcol:
        protcol = mzidtsvdata.HEADER_MASTER_PROT
    for psm in psms:
        protacc = psm[protcol]
        if ';' in protacc:
            continue
        master_proteins[protacc] = 1
    if 'NA' in master_proteins:
        master_proteins.pop('NA')
    if '' in master_proteins:
        master_proteins.pop('')
    for protacc in master_proteins:
        yield {prottabledata.HEADER_PROTEIN: protacc}
664633
def get_unique_gene_psms(self, genetable, fields, firstjoin):
        """"""
        lastgene = None
        gpsms_out, gp_ids = [], []
        for gpsm in self.get_proteins_psms(genetable, fields, firstjoin):
            if gpsm[0] != lastgene:
                for outpsm in gpsms_out:
                    yield outpsm
                lastgene = gpsm[0]
                gpsms_out, gp_ids = [], []
            gp_id = gpsm[0] + gpsm[1] + gpsm[3]
            if gp_id not in gp_ids:
                gp_ids.append(gp_id)
                gpsms_out.append(gpsm)
        for outpsm in gpsms_out:
            yield outpsm
253736
def save_protein_pickles_and_reset_protein(self):
        """"""
        self.gene_protein_pickles = {}
        for g in tqdm(self.genes):
            if g.protein.representative_sequence:
                initproteinpickle = op.join(g.protein.protein_dir, '{}_protein.pckl'.format(g.id))
                g.protein.save_pickle(initproteinpickle)
                self.gene_protein_pickles[g.id] = initproteinpickle
                g.reset_protein()
            else:
                g.reset_protein()
426084
def missing_uniprot_mapping(self):
        """"""
        uniprot_missing = []
        for g in self.genes:
            ups = g.protein.filter_sequences(UniProtProp)

            no_sequence_file_available = True
            for u in ups:
                if u.sequence_file or u.metadata_file:
                    no_sequence_file_available = False
                    break
            if no_sequence_file_available:
                uniprot_missing.append(g.id)

        return list(set(uniprot_missing))
732922
def add_protein_sequence_args(parser):
    
    protein_sequence_group = parser.add_argument_group(
        "Protein sequences (grouping equivalent translations)")
    protein_sequence_group.add_argument(
        "--max-protein-sequences-per-variant",
        type=int,
        default=MAX_PROTEIN_SEQUENCES_PER_VARIANT)
    return protein_sequence_group
547150
def map_psmnrcol_to_quantcol(quantcols, psmcols, tablefn_map):
    """"""
    if not psmcols:
        for fn in quantcols:
            for qcol in quantcols[fn]:
                yield (tablefn_map[fn], qcol)
    else:
        for fn in quantcols:
            for qcol, psmcol in zip(quantcols[fn], psmcols[fn]):
                yield (tablefn_map[fn], qcol, psmcol)
138804
def get_protein_feather_paths(protgroup, memornot, protgroup_dict, protein_feathers_dir, core_only_genes=None):
    
    prots_memornot = protgroup_dict['localization'][memornot[0]][memornot[1]]

    if protgroup[0] == 'localization':
        if protgroup[2] != 'all':
            if memornot[1] in ['membrane', 'inner_membrane', 'outer_membrane'] and protgroup[2] not in ['membrane', 'inner_membrane', 'outer_membrane']:
                return []
            if memornot[1] not in ['membrane', 'inner_membrane', 'outer_membrane'] and protgroup[2] in ['membrane', 'inner_membrane', 'outer_membrane']:
                return []

    prots_group = protgroup_dict[protgroup[0]][protgroup[1]][protgroup[2]]
    prots_filtered = list(set(prots_group).intersection(prots_memornot))
    if core_only_genes:
        prots_filtered = list(set(prots_filtered).intersection(core_only_genes))
    return [op.join(protein_feathers_dir, '{}_protein_strain_properties.fthr'.format(x)) for x in prots_filtered if op.exists(op.join(protein_feathers_dir, '{}_protein_strain_properties.fthr'.format(x)))]
16859
def get_psms(self):
        """"""
        self.header, isob_header = prep.get_full_and_isobaric_headers(
            self.oldheader, self.lookup, self.isobaric, self.precursor)
        self.psms = prep.generate_psms_quanted(self.lookup, self.fn,
                                               isob_header, self.oldheader,
                                               self.isobaric, self.precursor)
982269
def get_pepproteins(line):
    
    psm_id = get_psm_id(line)
    proteins = get_proteins_from_psm(line)
    return psm_id, proteins
7395
def create_pep_protein_quant_lookup(fns, pqdb, poolnames, featcolnr, patterns,
                                    storefuns, isobqcolpattern=None,
                                    psmnrpattern=None):
    """"""
    tablefn_map = create_tablefn_map(fns, pqdb, poolnames)
    feat_map = pqdb.get_feature_map()
    for pattern, storefun in zip(patterns, storefuns):
        if pattern is None:
            continue
        colmap = get_colmap(fns, pattern, single_col=True)
        if colmap:
            store_single_col_data(fns, tablefn_map, feat_map,
                                  storefun, featcolnr, colmap)
    if isobqcolpattern is not None:
        isocolmap = get_colmap(fns, isobqcolpattern, antipattern=psmnrpattern)
    else:
        return
    if psmnrpattern is not None:
        psmcolmap = get_colmap(fns, psmnrpattern)
    else:
        psmcolmap = False
    create_isobaric_quant_lookup(fns, tablefn_map,
                                 feat_map, pqdb,
                                 featcolnr,
                                 isocolmap, psmcolmap)
450820
def get_combo_subseq_within_2_5D(protein, props, within, filter_resnums=None):
        """"""
        if not protein.representative_structure:
            log.error('{}: no representative structure, cannot search for subseq'.format(protein.id))
            return {'subseq_len': 0, 'subseq': None, 'subseq_resnums': []}

        all_resnums = []
        for prop in props:
            tmp_results = protein.get_generic_subseq_within_2_5D(prop_name=prop, within=within,
                                                         filter_resnums=filter_resnums)
            all_resnums.extend(tmp_results['subseq_resnums'])
        final_resnums = list(set(all_resnums))
        sub_id = '{}-{}->{}_within_{}_{}_extracted'.format(protein.representative_structure.id,
                                                           protein.representative_chain,
                                                           protein.representative_sequence.id,
                                                           within, props)
        new_sp = protein.representative_sequence.get_subsequence(resnums=final_resnums, new_id=sub_id,
                                                                 copy_letter_annotations=False)
        return {'subseq_len': len(final_resnums), 'subseq': new_sp, 'subseq_resnums': final_resnums}
696029
def get_biopython_pepstats(self, clean_seq=False):
        """"""

        if self.seq:
            if clean_seq:  # TODO: can make this a property of the SeqProp class
                seq = self.seq_str.replace('X', '').replace('U', '')
            else:
                seq = self.seq_str

            try:
                pepstats = ssbio.protein.sequence.properties.residues.biopython_protein_analysis(seq)
            except KeyError as e:
                log.error('{}: unable to run ProteinAnalysis module, unknown amino acid {}'.format(self.id, e))
                return
            except ValueError as e:
                log.error('{}: unable to run ProteinAnalysis module, {}'.format(self.id, e))
                return
            self.annotations.update(pepstats)
        else:
            raise ValueError('{}: no sequence available, unable to run ProteinAnalysis'.format(self.id))
537261
def get_protein_data(peptide, pdata, headerfields, accfield):
    """"""
    report = get_proteins(peptide, pdata, headerfields)
    return get_cov_descriptions(peptide, pdata, report)
928251
def parse_checkM_tables(tables):
    
    g2info = {}
    for table in tables:
        for line in open(table):
            line = line.strip().split('\t')
            if line[0].startswith('Bin Id'):
                header = line
                header[8] = 'genome size (bp)'
                header[5] = '#SCGs'
                header[6] = '#SCG duplicates'
                continue
            ID, info = line[0], line
            info = [to_int(i) for i in info]
            ID = ID.replace(' ', '')
            g2info[ID] = {item:stat for item, stat in zip(header, info)}
            if g2info[ID]['genome size (bp)'] == '':
                g2info[ID]['genome size (bp)'] = 0
    return g2info
365448
def get_psm(line, unroll=False, specfncol=None):
    
    if specfncol is None:
        specfncol = mzidtsvdata.HEADER_SPECFILE
    specfn = line[specfncol]
    psm_id = get_psm_id(line)
    scan = line[mzidtsvdata.HEADER_SCANNR]
    peptideseq = get_psm_sequence(line, unroll)
    score = line[mzidtsvdata.HEADER_MSGFSCORE]
    return specfn, psm_id, scan, peptideseq, score
331742
def add_psms_to_proteindata(proteindata, p_acc, pool, psmdata):
    """"""
    seq, psm_id = psmdata[2], psmdata[3]
    try:
        proteindata[p_acc]['pools'][pool]['psms'].add(psm_id)
    except KeyError:
        emptyinfo = {'psms': set(), 'peptides': set(), 'unipeps': 0}
        try:
            proteindata[p_acc]['pools'][pool] = emptyinfo
        except KeyError:
            proteindata[p_acc].update({'pools': {pool: emptyinfo}})
        proteindata[p_acc]['pools'][pool]['psms'].add(psm_id)
    proteindata[p_acc]['pools'][pool]['peptides'].add(seq)
1180176
def get_exclusions(self):
        
        all_packages = (
            pkg
            for ns_pkg in self._get_SVEM_NSPs()
            for pkg in self._all_packages(ns_pkg)
        )

        excl_specs = product(all_packages, self._gen_exclusion_paths())
        return set(starmap(self._exclude_pkg_path, excl_specs))