Esempio n. 1
0
def get_theor_spectrum(peptide,
                       acc_frag,
                       types=('b', 'y'),
                       maxcharge=None,
                       **kwargs):
    """
    Calculates theoretical spectra in two ways: usual one. and formatter in integer (mz / frag_acc).
    `peptide` -peptide sequence
    `acc_frag` - accuracy of matching.
    `types` - ion types.
    `maxcharge` - maximum charge.

    ----------
    Returns spectra in two ways (usual, integer)
    """
    peaks = {}
    theoretical_set = defaultdict(set)
    pl = len(peptide) - 1
    if not maxcharge:
        maxcharge = 1 + int(ec.charge(peptide, pH=2))
    for charge in range(1, maxcharge + 1):
        for ion_type in types:
            nterminal = ion_type[0] in 'abc'
            if nterminal:
                maxpart = peptide[:-1]
                maxmass = cmass.fast_mass(maxpart,
                                          ion_type=ion_type,
                                          charge=charge,
                                          **kwargs)
                marr = np.zeros((pl, ), dtype=float)
                marr[0] = maxmass
                for i in range(1, pl):
                    marr[i] = marr[i - 1] - mass.fast_mass2(
                        [maxpart[-i]]) / charge  ### recalculate
            else:
                maxpart = peptide[1:]
                maxmass = cmass.fast_mass(maxpart,
                                          ion_type=ion_type,
                                          charge=charge,
                                          **kwargs)
                marr = np.zeros((pl, ), dtype=float)
                marr[pl - 1] = maxmass
                for i in range(pl - 2, -1, -1):
                    marr[i] = marr[i + 1] - mass.fast_mass2(
                        [maxpart[-(i + 2)]]) / charge  ### recalculate

            tmp = marr / acc_frag
            tmp = tmp.astype(int)
            theoretical_set[ion_type].update(tmp)
            marr.sort()
            peaks[ion_type, charge] = marr
    return peaks, theoretical_set
Esempio n. 2
0
def generate_Yion(Ytype, aa_mass, ion_maxcharge, ion_type, labels, temp):
    str_seq = parser.tostring(temp, False)
    for m in range(ion_maxcharge):
        if "Y" in ion_type:
            yield Ion(seq=temp, charge=m + 1, ion_type="Y",
                      mz=mass.fast_mass2(str_seq, charge=m + 1, aa_mass=aa_mass, labels=labels),
                      fragment_number=int(Ytype[1:]) + 1)
Esempio n. 3
0
def generate_byion(aa_mass, b_stop_at, ion_maxcharge, ion_type, labels, seq_len, temp, y_stop_at, b_selected, y_selected):
    for s in range(seq_len):
        if not (s + 1) == 1:
            for m in range(ion_maxcharge):
                for ion in ion_type:
                    if ion == "y":
                        position = seq_len - s - 1
                        if y_stop_at > -1:
                            if position <= y_stop_at:
                                continue
                        if y_selected:
                            if position in y_selected:
                                seq = temp[position:]
                                str_seq = parser.tostring(seq, False)
                                # print(str_seq)
                                yield Ion(seq=temp, ion_type=ion, charge=m + 1,
                                          mz=mass.fast_mass2(str_seq, ion_type=ion, charge=m + 1, aa_mass=aa_mass,
                                                             labels=labels), fragment_number=s + 1)
                        else:
                            seq = temp[position:]
                            str_seq = parser.tostring(seq, False)
                            # print(str_seq)
                            yield Ion(seq=temp, ion_type=ion, charge=m + 1,
                                      mz=mass.fast_mass2(str_seq, ion_type=ion, charge=m + 1, aa_mass=aa_mass,
                                                         labels=labels), fragment_number=s + 1)
                    elif ion == "b":
                        position = s + 1
                        if position == seq_len:
                            continue
                        if b_stop_at > -1:
                            if position > b_stop_at:
                                continue
                        if b_selected:
                            if s in b_selected:
                                seq = temp[:position]
                                str_seq = parser.tostring(seq, False)
                                # print(str_seq)
                                yield Ion(seq=temp, ion_type=ion, charge=m + 1,
                                          mz=mass.fast_mass2(str_seq, ion_type=ion, charge=m + 1, aa_mass=aa_mass,
                                                             labels=labels), fragment_number=s + 1)
                        else:
                            seq = temp[:position]
                            str_seq = parser.tostring(seq, False)
                            # print(str_seq)
                            yield Ion(seq=temp, ion_type=ion, charge=m + 1,
                                      mz=mass.fast_mass2(str_seq, ion_type=ion, charge=m + 1, aa_mass=aa_mass,
                                                         labels=labels), fragment_number=s + 1)
Esempio n. 4
0
 def theor_spectrum(self, types=('b', 'y'), maxcharge=None, **kwargs):
     peaks = {}
     if not maxcharge:
         maxcharge = max(self.pcharge, 1)
     for ion_type in types:
         ms = []
         for i in range(1, len(self.modified_sequence)):
             if self.modified_sequence[i - 1] in parser.std_amino_acids and self.modified_sequence[i] != '-':
                 for charge in range(1, maxcharge + 1):
                     if ion_type[0] in 'abc':
                         ms.append(mass.fast_mass2(
                             str(self.modified_sequence)[:i], ion_type=ion_type, charge=charge,
                             **kwargs))
                     else:
                         ms.append(mass.fast_mass2(
                             str(self.modified_sequence)[i:], ion_type=ion_type, charge=charge,
                             **kwargs))
         marr = np.array(ms)
         marr.sort()
         peaks[ion_type] = marr
     return peaks
Esempio n. 5
0
def fragmenting(i,
                rec,
                ms,
                mv,
                query_unique,
                protein_id,
                unique_q3=None,
                y=None):
    labels, aa_mass, seq = prepare_libraries(i['_protein']['_sequence'],
                                             static=ms,
                                             variable=mv)
    seq_len = len(seq)
    result = []
    msMap = {m['label']: m['m_label'] for m in ms}

    for f in generate_fragments(seq[:], static=ms, variable=mv):
        # print(f)
        new_seq = parser.tostring(f, False)
        print('Current: ' + new_seq)
        precursor_mz = mass.fast_mass2(new_seq,
                                       charge=i['_precursor_charge'],
                                       aa_mass=aa_mass,
                                       labels=labels)
        variable = ''

        for r in i['_rt']:
            for ion in fragments_by(aa_mass,
                                    i['_charge'],
                                    i['_protein']['_ion_type'],
                                    labels,
                                    seq_len,
                                    f,
                                    mv,
                                    Ytype=y,
                                    b_stop_at=i['_b_stop_at'],
                                    y_stop_at=i['_y_stop_at'],
                                    by_static=i['_by_run'],
                                    b_selected=i['_b_selected'],
                                    y_selected=i['_y_selected']):
                create_row(f, i, ion, msMap, mv, precursor_mz, query_unique, r,
                           rec, result, seq, seq_len, unique_q3, variable,
                           protein_id)

    return result, query_unique
Esempio n. 6
0
 def test_fast_mass2(self):
     for pep in self.random_peptides:
         self.assertAlmostEqual(
             mass.fast_mass2(pep, aa_mass=self.test_aa_mass),
             sum(pep.count(aa) * m for aa, m in self.test_aa_mass.items()) +
             self.mass_H * 2.0 + self.mass_O)