annotate SAINT_preprocessing_mq_pep.py @ 45:0eae5a2c37d4 draft

Uploaded
author bornea
date Thu, 19 May 2016 10:55:39 -0400
parents b95bf0251ffd
children 5b2a60b59f46
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
1 #######################################################################################
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
2 # Python-code: SAINT pre-processing from MaxQuant "Samples Report" output
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
3 # Author: Brent Kuenzi
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
4 #######################################################################################
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
5 # This program reads in a raw MaxQuant "Samples Report" output and a user generated
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
6 # bait file and autoformats it into prey and interaction files for SAINTexpress
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
7 # analysis
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
8 #######################################################################################
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
9 # Copyright (C) Brent Kuenzi.
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
10 # Permission is granted to copy, distribute and/or modify this document
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
11 # under the terms of the GNU Free Documentation License, Version 1.3
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
12 # or any later version published by the Free Software Foundation;
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
13 # with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
14 # A copy of the license is included in the section entitled "GNU
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
15 # Free Documentation License".
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
16 #######################################################################################
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
17 ## REQUIRED INPUT ##
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
18
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
19 # 1) infile: MaxQuant "Samples Report" output
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
20 # 2) baitfile: SAINT formatted bait file generated in Galaxy
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
21 # 3) fasta_db: fasta database for use (defaults to SwissProt_HUMAN_2014_08.fasta)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
22 # 4) prey: Y or N for generating a prey file
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
23 # 5) make_bait: String of bait names, assignment, and test or control boolean
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
24 #######################################################################################
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
25
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
26
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
27 import sys
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
28 import os
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
29
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
30
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
31 mq_file = sys.argv[1]
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
32 ins_path = sys.argv[8]
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
33 names_path = str(ins_path) + r"uniprot_names.txt"
29
bd71998aec8d Uploaded
bornea
parents: 6
diff changeset
34 fasta_db = sys.argv[3]
bd71998aec8d Uploaded
bornea
parents: 6
diff changeset
35
bd71998aec8d Uploaded
bornea
parents: 6
diff changeset
36 # Uses faster names list for filtering when default db used.
bd71998aec8d Uploaded
bornea
parents: 6
diff changeset
37 if fasta_db == "None":
bd71998aec8d Uploaded
bornea
parents: 6
diff changeset
38 cmd = (r"Rscript "+ str(ins_path) +"pre_process_protein_name_set.R " + str(mq_file) +
bd71998aec8d Uploaded
bornea
parents: 6
diff changeset
39 " " + str(names_path))
bd71998aec8d Uploaded
bornea
parents: 6
diff changeset
40 os.system(cmd)
bd71998aec8d Uploaded
bornea
parents: 6
diff changeset
41 else:
bd71998aec8d Uploaded
bornea
parents: 6
diff changeset
42 cmd = (r"Rscript "+ str(ins_path) +"pre_process_protein_name_set.R " + str(mq_file) +
31
761e1ad2b130 Uploaded
bornea
parents: 29
diff changeset
43 " " + str(fasta_db))
29
bd71998aec8d Uploaded
bornea
parents: 6
diff changeset
44 os.system(cmd)
6
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
45
31
761e1ad2b130 Uploaded
bornea
parents: 29
diff changeset
46
6
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
47 infile = "./tukeys_output.txt"
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
48 # The MaxQuant "Samples Report" output.
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
49 prey = sys.argv[2]
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
50 # Y or N boolean from Galaxy.
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
51 if fasta_db == "None":
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
52 fasta_db = str(ins_path) + "SwissProt_HUMAN_2014_08.fasta"
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
53 make_bait = sys.argv[6]
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
54 bait_bool = sys.argv[9]
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
55
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
56 def bait_create(baits, infile):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
57 # Takes the Bait specified by the user and makes them into a Bait file and includes a
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
58 # check to make sure they are using valid baits.
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
59 baits = make_bait.split()
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
60 i = 0
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
61 bait_file_tmp = open("bait.txt", "w")
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
62 order = []
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
63 bait_cache = []
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
64 while i < len(baits):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
65 if baits[i+2] == "true":
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
66 T_C = "C"
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
67 else:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
68 T_C = "T"
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
69 bait_line = baits[i] + "\t" + baits[i+1] + "\t" + T_C + "\n"
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
70 read_infile = open(infile, "r")
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
71 for input_line in read_infile :
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
72 input_line = input_line.replace("\"", "")
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
73 input_line = input_line.replace(r"Intensity.", "")
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
74 # R coerces "-" into "." changes them back and remove Intensity from the Bait names.
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
75 input_line = input_line.replace(r".", r"-")
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
76 temp = input_line.split()
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
77 if "mapped_protein" in str(temp):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
78 if baits[i] in temp:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
79 number_bait = temp.index(str(baits[i]))
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
80 number_bait = number_bait - 9
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
81 bait_cache.append((number_bait, str(bait_line)))
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
82 # Locates the Bait names in the column names and then sets the Baits in the
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
83 # correct order in the cache thus the - 9 because the baits start at the 9th
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
84 # column.
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
85 else:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
86 print "Error: bad bait " + str(baits[i])
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
87 sys.exit()
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
88 else:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
89 pass
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
90 i = i + 3
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
91 # Writes cache to Bait file.
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
92 bait_cache.sort()
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
93 for line in bait_cache:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
94 bait_file_tmp.write(line[1])
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
95
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
96 bait_file_tmp.close()
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
97
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
98
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
99 if bait_bool == 'false':
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
100 bait_create(make_bait, infile)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
101 baitfile = "bait.txt"
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
102 else:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
103 bait_temp_file = open(sys.argv[10], 'r')
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
104 bait_cache = bait_temp_file.readlines()
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
105 bait_file_tmp = open("bait.txt", "wr")
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
106 for line in bait_cache:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
107 bait_file_tmp.write(line)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
108 bait_file_tmp.close()
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
109 baitfile = "bait.txt"
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
110
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
111
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
112 class ReturnValue1(object):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
113 def __init__(self, sequence, gene):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
114 self.seqlength = sequence
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
115 self.genename = gene
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
116 class ReturnValue2(object):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
117 def __init__(self, getdata, getproteins, getheader):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
118 self.data = getdata
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
119 self.proteins = getproteins
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
120 self.header = getheader
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
121
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
122
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
123 def main(MaxQuant_input, make_bait):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
124 #bait_check(baitfile, MaxQuant_input)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
125 make_inter(MaxQuant_input)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
126 if prey == 'true':
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
127 make_prey(MaxQuant_input)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
128 no_error_inter(MaxQuant_input)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
129 os.rename('prey.txt', sys.argv[5])
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
130 elif prey == 'false':
35
26cc583a4ae4 Uploaded
bornea
parents: 34
diff changeset
131 if os.path.isfile('./error_proteins.txt') == True:
6
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
132 no_error_inter(MaxQuant_input)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
133 pass
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
134 elif prey != 'true' or 'false':
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
135 sys.exit("Invalid Prey Argument: Y or N")
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
136 os.rename('inter.txt', sys.argv[4])
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
137 os.rename("bait.txt", sys.argv[7])
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
138
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
139
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
140 def get_info(uniprot_accession_in):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
141 # Get aa lengths and gene name.
35
26cc583a4ae4 Uploaded
bornea
parents: 34
diff changeset
142 error = open('./error_proteins.txt', 'a+')
6
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
143 data = open(fasta_db, 'r')
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
144 data_lines = data.readlines()
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
145 db_len = len(data_lines)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
146 seqlength = 0
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
147 count = 0
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
148 for data_line in data_lines:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
149 if ">sp" in data_line:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
150 if uniprot_accession_in == data_line.split("|")[1]:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
151 match = count + 1
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
152 if 'GN=' in data_line:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
153 lst = data_line.split('GN=')
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
154 lst2 = lst[1].split(' ')
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
155 genename = lst2[0]
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
156 if 'GN=' not in data_line:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
157 genename = 'NA'
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
158 while ">sp" not in data_lines[match]:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
159 if match <= db_len:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
160 seqlength = seqlength + len(data_lines[match].strip())
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
161 match = match + 1
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
162 else:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
163 break
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
164 return ReturnValue1(seqlength, genename)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
165 count = count + 1
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
166
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
167
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
168 if seqlength == 0:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
169 error.write(uniprot_accession_in + '\t' + "Uniprot not in Fasta" + '\n')
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
170 error.close
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
171 seqlength = 'NA'
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
172 genename = 'NA'
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
173 return ReturnValue1(seqlength, genename)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
174
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
175
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
176 def readtab(infile):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
177 with open(infile, 'r') as input_file:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
178 # Read in tab-delim text file.
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
179 output = []
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
180 for input_line in input_file:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
181 input_line = input_line.strip()
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
182 temp = input_line.split('\t')
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
183 output.append(temp)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
184 return output
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
185
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
186
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
187 def read_MaxQuant(MaxQuant_input):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
188 # Get data, proteins and header from MaxQuant output.
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
189 dupes = readtab(MaxQuant_input)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
190 header_start = 0
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
191 header = dupes[header_start]
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
192 for var_MQ in header:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
193 var_MQ = var_MQ.replace(r"\"", "")
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
194 var_MQ = var_MQ.replace(r"Intensity.", r"")
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
195 var_MQ = var_MQ.replace(r".", r"-")
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
196 data = dupes[header_start+1:len(dupes)]
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
197 # Cut off blank line and END OF FILE.
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
198 proteins = []
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
199 for protein in data:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
200 proteins.append(protein[0])
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
201 return ReturnValue2(data, proteins, header)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
202
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
203
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
204 def make_inter(MaxQuant_input):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
205 bait = readtab(baitfile)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
206 data = read_MaxQuant(MaxQuant_input).data
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
207 header = read_MaxQuant(MaxQuant_input).header
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
208 proteins = read_MaxQuant(MaxQuant_input).proteins
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
209 bait_index = []
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
210 for bait_item in bait:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
211 bait_index.append(header.index("mapped_protein") + 1)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
212 # Find just the baits defined in bait file.
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
213 with open('inter.txt', 'w') as y:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
214 a = 0; l = 0
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
215 for bb in bait:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
216 for lst in data:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
217 y.write(header[bait_index[l]] + '\t' + bb[1] + '\t' + proteins[a] + '\t'
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
218 + lst[bait_index[l]] + '\n')
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
219 a += 1
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
220 if a == len(proteins):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
221 a = 0; l += 1
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
222
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
223
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
224 def make_prey(MaxQuant_input):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
225 proteins = read_MaxQuant(MaxQuant_input).proteins
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
226 output_file = open("prey.txt", 'w')
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
227 for a in proteins:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
228 a = a.replace("\n", "")
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
229 # Remove \n for input into function.
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
230 a = a.replace("\r", "")
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
231 # Ditto for \r.
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
232 seq = get_info(a).seqlength
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
233 GN = get_info(a).genename
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
234 if seq != 'NA':
34
05c5844e037b Uploaded
bornea
parents: 31
diff changeset
235 if GN != 'NA':
05c5844e037b Uploaded
bornea
parents: 31
diff changeset
236 output_file.write(a+"\t"+str(seq)+ "\t" + str(GN) + "\n")
6
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
237 output_file.close()
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
238
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
239
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
240 def no_error_inter(MaxQuant_input):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
241 # Remake inter file without protein errors from Uniprot.
35
26cc583a4ae4 Uploaded
bornea
parents: 34
diff changeset
242 err = readtab("./error_proteins.txt")
6
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
243 bait = readtab(baitfile)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
244 data = read_MaxQuant(MaxQuant_input).data
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
245 header = read_MaxQuant(MaxQuant_input).header
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
246 header = [MQ_var.replace(r"\"", "") for MQ_var in header]
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
247 header = [MQ_var.replace(r"Intensity.", r"") for MQ_var in header]
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
248 header = [MQ_var.replace(r".", r"-") for MQ_var in header]
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
249 bait_index = []
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
250 for bait_item in bait:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
251 bait_index.append(header.index(bait_item[0]))
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
252 proteins = read_MaxQuant(MaxQuant_input).proteins
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
253 errors = []
40
8102ffab0f85 Uploaded
bornea
parents: 39
diff changeset
254 valid_prots = []
6
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
255 for e in err:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
256 errors.append(e[0])
36
bc9c7764cc2f Uploaded
bornea
parents: 35
diff changeset
257 for a in proteins:
bc9c7764cc2f Uploaded
bornea
parents: 35
diff changeset
258 a = a.replace("\n", "")
bc9c7764cc2f Uploaded
bornea
parents: 35
diff changeset
259 # Remove \n for input into function.
bc9c7764cc2f Uploaded
bornea
parents: 35
diff changeset
260 a = a.replace("\r", "")
bc9c7764cc2f Uploaded
bornea
parents: 35
diff changeset
261 # Ditto for \r.
bc9c7764cc2f Uploaded
bornea
parents: 35
diff changeset
262 seq = get_info(a).seqlength
bc9c7764cc2f Uploaded
bornea
parents: 35
diff changeset
263 GN = get_info(a).genename
40
8102ffab0f85 Uploaded
bornea
parents: 39
diff changeset
264 if seq != 'NA':
8102ffab0f85 Uploaded
bornea
parents: 39
diff changeset
265 if GN != 'NA':
8102ffab0f85 Uploaded
bornea
parents: 39
diff changeset
266 valid_prots.append(a)
43
1341c966a016 Uploaded
bornea
parents: 42
diff changeset
267 print valid_prots
6
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
268 with open('inter.txt', 'w') as input_file:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
269 l = 0; a = 0
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
270 for bb in bait:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
271 for lst in data:
40
8102ffab0f85 Uploaded
bornea
parents: 39
diff changeset
272 if valid_prots[a] not in errors:
45
0eae5a2c37d4 Uploaded
bornea
parents: 44
diff changeset
273 print lst
44
b95bf0251ffd Uploaded
bornea
parents: 43
diff changeset
274 print l
b95bf0251ffd Uploaded
bornea
parents: 43
diff changeset
275 print a
42
13969f07b129 Uploaded
bornea
parents: 41
diff changeset
276 input_file.write(header[bait_index[l]] + '\t' + bb[1] + '\t' + valid_prots[a] + '\t' + lst[bait_index[l]] + '\n')
44
b95bf0251ffd Uploaded
bornea
parents: 43
diff changeset
277 print(header[bait_index[l]] + '\t' + bb[1] + '\t' + valid_prots[a] + '\t' + lst[bait_index[l]] + '\n')
6
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
278 a += 1
40
8102ffab0f85 Uploaded
bornea
parents: 39
diff changeset
279 if a == len(valid_prots):
6
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
280 l += 1; a = 0
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
281
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
282
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
283 def bait_check(bait, MaxQuant_input):
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
284 # Check that bait names share header titles.
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
285 bait_in = readtab(bait)
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
286 header = read_MaxQuant(MaxQuant_input).header
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
287 for bait in bait_in:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
288 if bait[0] not in header:
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
289 sys.exit("Bait must share header titles with MaxQuant output")
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
290
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
291 if __name__ == '__main__':
0fed3fc380c7 Uploaded
bornea
parents:
diff changeset
292 main(infile, make_bait)