n = int((sqrt(4 * len(cyclospec) - 7) + 1) / 2) # Find the first n protein in the peptide. # Need to be careful: two small proteins can add to be less than a larger one, so we can't just take the first n nonzero entries. # Fortunately, no two small proteins masses add to that of a larger protein. protein, i = [], 1 while len(protein) != n: if int(cyclospec[i]) in map(int, weight.values()): protein.append(cyclospec[i]) i += 1 # Get the name of each protein corresponding to a given weight (if multiple, only take one). names = [] for w in protein: names.append( [items[0] for items in weight.items() if int(items[1]) == int(w)][0]) # Build the possible sequences. seq = append_char(names, names) for repeat in xrange(1, n): seq = filter(lambda subpeptide: set(spectrum(subpeptide)) < set(cyclospec), set(seq)) if repeat != n - 1: seq = append_char(seq, names) # Convert each protein to the proper format. cyclopeptide_sequence = [ '-'.join([str(int(weight[protein])) for protein in peptide]) for peptide in seq ]
# Using the quadratic formula to to solve for n: n = (sqrt(4L-7) + 1)/2 n = int((sqrt(4*len(cyclospec)-7)+1)/2) # Find the first n protein in the peptide. # Need to be careful: two small proteins can add to be less than a larger one, so we can't just take the first n nonzero entries. # Fortunately, no two small proteins masses add to that of a larger protein. protein, i = [], 1 while len(protein) != n: if int(cyclospec[i]) in map(int,weight.values()): protein.append(cyclospec[i]) i += 1 # Get the name of each protein corresponding to a given weight (if multiple, only take one). names = [] for w in protein: names.append([items[0] for items in weight.items() if int(items[1])==int(w)][0]) # Build the possible sequences. seq = append_char(names,names) for repeat in xrange(1,n): seq = filter(lambda subpeptide:set(spectrum(subpeptide)) < set(cyclospec), set(seq)) if repeat != n-1: seq = append_char(seq,names) # Convert each protein to the proper format. cyclopeptide_sequence = ['-'.join([str(int(weight[protein])) for protein in peptide]) for peptide in seq] # Print and save the answer. print ' '.join(cyclopeptide_sequence) with open('output/textbook/Textbook_02D.txt', 'w') as output_data: output_data.write(' '.join(cyclopeptide_sequence))
# Using the quadratic formula to to solve for n: n = (sqrt(4L-7) + 1)/2 n = int((sqrt(4*len(cyclospec)-7)+1)/2) # Find the first n protein in the peptide. # Need to be careful: two small proteins can add to be less than a larger one, so we can't just take the first n nonzero entries. # Fortunately, no two small proteins masses add to that of a larger protein. protein, i = [], 1 while len(protein) != n: if int(cyclospec[i]) in map(int,weight.values()): protein.append(cyclospec[i]) i += 1 # Get the name of each protein corresponding to a given weight (if multiple, only take one). names = [] for w in protein: names.append([items[0] for items in weight.items() if int(items[1])==int(w)][0]) # Build the possible sequences. seq = append_char(names,names) for repeat in xrange(1,n): seq = filter(lambda subpeptide:set(spectrum(subpeptide)) < set(cyclospec), set(seq)) if repeat != n-1: seq = append_char(seq,names) # Convert each protein to the proper format. cyclopeptide_sequence = ['-'.join([str(int(weight[protein])) for protein in peptide]) for peptide in seq] # Print and save the answer. print ' '.join(cyclopeptide_sequence) with open('output/Assignment_02D.txt', 'w') as output_data: output_data.write(' '.join(cyclopeptide_sequence))