/
calculate_peptide_substrings.py
executable file
·50 lines (33 loc) · 1.35 KB
/
calculate_peptide_substrings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python
import sys
import getopt
import os
import ming_fileio_library
from pyteomics import mass
def usage():
print "<input file>"
def find_all_substring_of_length(input_string, length):
return_list = []
for i in range(len(input_string) - length + 1):
return_list.append(input_string[i:i+length])
return return_list
def main():
input_filename = sys.argv[1]
line_counts, table_data = ming_fileio_library.parse_table_with_headers(input_filename)
all_sub_peptides = []
for i in range(line_counts):
#print table_data["Peptides"][i]
for length in range(10):
peptide = table_data["Peptides"][i]
substrings = find_all_substring_of_length(peptide, length + 4)
#print peptide + "\t" + str(substrings)
all_sub_peptides += substrings
#print len(all_sub_peptides)
all_sub_peptides = list(set(all_sub_peptides))
#print len(all_sub_peptides)
for peptide in all_sub_peptides:
print peptide + "\t" + "2" + "\t" + str(mass.calculate_mass(sequence=peptide, ion_type='M', charge=2))
print peptide + "\t" + "3" + "\t" + str(mass.calculate_mass(sequence=peptide, ion_type='M', charge=3))
print peptide + "\t" + "4" + "\t" + str(mass.calculate_mass(sequence=peptide, ion_type='M', charge=4))
if __name__ == "__main__":
main()