def generating_theoretical_spectrum_cyclic_peptide(peptide):
    mass_table = read_mass_table("integer_mass_table.txt")
    
# =============================================================================
#     a = range(57, 201, 1)
#     mass_table = {}
#     for i in a:
#         mass_table[chr(i)] = int(i)
# =============================================================================
 
    
    subpeptides = [peptide]
    
    #in order to easily process cylce, we double peptide
    peptide *= 2
    
    for i in range(0, int(len(peptide) / 2) ):
        for j in range(1, int(len(peptide) / 2)):
                subpeptides.append(peptide[i:i+j])
            
    spectrum = [0]
    #print(subpeptides)
    for subpeptide in subpeptides:
        mass = 0
        for acid in subpeptide:
            mass += mass_table[acid]
        spectrum.append(mass)
    return  spectrum
Example #2
0
def counting_peptides_with_given_mass(m):
    # we know the smallest mass is 57 for G, so the length of linear peptides
    # will be less than int(m/57)
    # On the other hand, the largest mass is 186 for W, so the length will be
    # greater than int(m/186)
    # so the interval of length is [int(m/186), int(m/57)]
    mass_table = read_mass_table("integer_mass_table.txt")
    mass_table.pop("I")
    mass_table.pop("K")
    peptides = [""]
    count = 0
    mass_list = [0]
    for i in range(int(m / 57)):
        print(i)
        peptides_new = []
        mass_list_new = []
        for j in range(len(peptides)):
            for amino in mass_table:
                new_peptide = peptides[j] + amino
                new_peptide_mass = mass_list[j] + mass_table[amino]
                #if i >= int(m / 186) - 1:
                if new_peptide_mass == m:
                    count += 1
                    continue
                elif new_peptide_mass + 57 > m:
                    continue
                peptides_new.append(new_peptide)
                mass_list_new.append(new_peptide_mass)
        mass_list = mass_list_new
        peptides = peptides_new
    return count
def cyclopeptide_sequencing(spectrum):
    mass_table = read_mass_table("integer_mass_table.txt")
    one_k_mer = spectrum_consistent(spectrum, mass_table.copy())
    peptides = one_k_mer.copy()
    for i in range(int(max(spectrum) / 57)):
        new_peptides = []
        for peptide in peptides:
            for j in one_k_mer:
                new_peptides.append(peptide + j)
        peptides_temp = []
        for new_peptide in new_peptides:
            new_peptide_spectrum = generating_theoretical_spectrum_linear_peptide(
                new_peptide)
            #if max(new_peptide_spectrum.values()) == max(spectrum):
            if spectrum_consistent_bool(spectrum, new_peptide_spectrum):
                peptides_temp.append(new_peptide)
        if len(peptides_temp) != 0:
            peptides = peptides_temp
    peptides = set(peptides)
    print(sorted(peptides))
    cyclopeptide_spectrum = []
    for i in peptides:
        s = []
        for j in i:
            s.append(str(mass_table[j]))
        cyclopeptide_spectrum.append("-".join(s))
    return set(cyclopeptide_spectrum)
def generating_theoretical_spectrum_linear_peptide(peptide):
    mass_table = read_mass_table("integer_mass_table.txt")
    subpeptides = []
    #in order to easily process cylce, we double peptide
    i = 0
    for i in range(0, int(len(peptide))):
        for j in range(1, int(len(peptide)) - i + 1):
            subpeptides.append(peptide[i:i + j])
    spectrum = []
    for subpeptide in subpeptides:
        mass = 0
        for acid in subpeptide:
            mass += mass_table[acid]
        spectrum.append(mass)
    return spectrum