annotate SAINT_preprocessing_v6_mq_pep.py @ 12:ed33c5e621b7 draft

Uploaded
author bornea
date Tue, 10 Nov 2015 13:23:17 -0500
parents 9c3d2b1d0c1c
children 729aac64ce43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
1 #######################################################################################
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
2 # Python-code: SAINT pre-processing from maxquant "Samples Report" output
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
3 # Author: Brent Kuenzi
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
4 #######################################################################################
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
5 # This program reads in a raw maxquant "Samples Report" output and a user generated
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
6 # bait file and autoformats it into prey and interaction files for SAINTexpress
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
7 # analysis
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
8 #######################################################################################
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
9 import sys
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
10 import urllib2
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
11 import os
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
12 #######################################################################################
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
13 ## REQUIRED INPUT ##
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
14
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
15 # 1) infile: maxquant "Samples Report" output
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
16 # 2) baitfile: SAINT formatted bait file generated in Galaxy
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
17 # 3) prey: Y or N for generating a prey file (requires internet connection)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
18 #######################################################################################
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
19 mq_file = sys.argv[1]
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
20 cmd = r"Rscript /home/bornea/galaxy_moffitt_dev/tools/Moffitt_Tools/bubblebeam/pre_process_protein_name_set.R " + str(mq_file)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
21 os.system(cmd)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
22
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
23 infile = "./tukeys_output.txt" #maxquant "Samples Report" output
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
24 prey = sys.argv[2] # Y or N
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
25 fasta_db = sys.argv[3]
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
26 if fasta_db == "None":
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
27 fasta_db = "/home/bornea/galaxy_moffitt_dev/tools/Moffitt_Tools/bubblebeam/SwissProt_HUMAN_2014_08.fasta"
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
28 make_bait= sys.argv[6]
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
29
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
30 def bait_create(baits, infile):
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
31 #Takes the Bait specified by the user and makes them into a Bait file and includes a check to make sure they are using valid baits.
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
32 baits = make_bait.split()
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
33 i = 0
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
34 bait_file_tmp = open("bait.txt", "wr")
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
35 order = []
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
36 bait_cache = []
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
37 while i < len(baits):
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
38 if baits[i+2] == "true":
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
39 T_C = "C"
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
40 else:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
41 T_C = "T"
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
42 line1 = baits[i] + "\t" + baits[i+1] + "\t" + T_C + "\n"
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
43 q = open(infile,"r")
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
44 for line2 in q:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
45 line2 = line2.replace("\"", "")
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
46 line2 = line2.replace(r"Intensity.", "") #R coerces "-" into "." this changes them back and remove Intensity from the Bait names.
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
47 line2 = line2.replace(r".", r"-")
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
48 temp = line2.split()
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
49 if "mapped_protein" in str(temp):
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
50 #If the bait is in the original file then write to cache it if not exit.
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
51 if baits[i] in temp:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
52 number_bait = temp.index(str(baits[i]))
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
53 number_bait = number_bait - 9
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
54 bait_cache.append((number_bait, str(line1)))
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
55 else:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
56 print "Error: bad bait " + str(baits[i])
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
57 sys.exit()
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
58 else:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
59 pass
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
60 i = i + 3
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
61 #Writes cache to file.
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
62 bait_cache.sort()
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
63 for line in bait_cache:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
64 bait_file_tmp.write(line[1])
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
65
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
66 bait_file_tmp.close()
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
67
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
68
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
69 baitfile = "bait.txt"
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
70
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
71 class ReturnValue1(object):
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
72 def __init__(self, sequence, gene):
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
73 self.seqlength = sequence
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
74 self.genename = gene
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
75 class ReturnValue2(object):
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
76 def __init__(self, getdata, getproteins, getheader):
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
77 self.data = getdata
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
78 self.proteins = getproteins
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
79 self.header = getheader
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
80
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
81 def main(maxquant_input, make_bait):
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
82 bait_create(make_bait, infile)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
83 baitfile = "bait.txt"
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
84 #bait_check(baitfile, maxquant_input)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
85 make_inter(maxquant_input)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
86 if prey == 'true':
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
87 make_prey(maxquant_input)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
88 no_error_inter(maxquant_input)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
89 os.rename('prey.txt', sys.argv[5])
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
90 elif prey == 'false':
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
91 if os.path.isfile('error proteins.txt') == True:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
92 no_error_inter(maxquant_input)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
93 pass
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
94 elif prey != 'true' or 'false':
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
95 sys.exit("Invalid Prey Argument: Y or N")
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
96 os.rename('inter.txt', sys.argv[4])
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
97 os.rename("bait.txt", sys.argv[7])
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
98
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
99
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
100 def get_info(uniprot_accession_in): # get aa lengths and gene name
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
101 error = open('error proteins.txt', 'a+')
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
102 # while True:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
103 # i = 0
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
104 # try:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
105 # data = urllib2.urlopen("http://www.uniprot.org/uniprot/" + uniprot_accession_in + ".fasta")
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
106 # break
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
107 # except urllib2.HTTPError, err:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
108 # i = i + 1
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
109 # if i == 50:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
110 # sys.exit("More than 50 errors. Check your file or try again later.")
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
111 # if err.code == 404:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
112 # error.write(uniprot_accession_in + '\t' + "Invalid URL. Check protein" + '\n')
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
113 # seqlength = 'NA'
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
114 # genename = 'NA'
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
115 # return ReturnValue1(seqlength, genename)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
116 # elif err.code == 302:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
117 # sys.exit("Request timed out. Check connection and try again.")
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
118 # else:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
119 # sys.exit("Uniprot had some other error")
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
120 #
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
121 #
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
122 # if lines == []:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
123 # error.write(uniprot_accession_in + '\t' + "Blank Fasta" + '\n')
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
124 # error.close
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
125 # if lines == []:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
126 # error.write(uniprot_accession_in + '\t' + "Blank Fasta" + '\n')
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
127 # error.close
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
128 # seqlength = 'NA'
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
129 # genename = 'NA'
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
130 # return ReturnValue1(seqlength, genename)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
131 # if lines != []:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
132 # seqlength = 0
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
133 # header = lines[0]
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
134 # for line in lines[1:]:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
135 # line = line.replace("\n","") # strip \n or else it gets counted in the length
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
136 # seqlength += len(line)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
137 # if 'GN=' in header:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
138 # lst = header.split('GN=')
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
139 # lst2 = lst[1].split(' ')
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
140 # genename = lst2[0]
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
141 # error.close
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
142 # return ReturnValue1(seqlength, genename)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
143 # if 'GN=' not in header:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
144 # genename = 'NA'
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
145 # error.close
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
146 # return ReturnValue1(seqlength, genename)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
147
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
148 data = open(fasta_db,'r')
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
149 lines = data.readlines()
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
150 db_len = len(lines)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
151 seqlength = 0
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
152 count = 0
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
153 for i in lines:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
154 if ">sp" in i:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
155 if uniprot_accession_in == i.split("|")[1]:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
156 match = count+1
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
157 if 'GN=' in i:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
158 lst = i.split('GN=')
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
159 lst2 = lst[1].split(' ')
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
160 genename = lst2[0]
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
161 if 'GN=' not in i:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
162 genename = 'NA'
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
163 while ">sp" not in lines[match]:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
164 if match <= db_len:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
165 seqlength = seqlength + len(lines[match].strip())
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
166 match = match + 1
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
167 else:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
168 break
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
169 return ReturnValue1(seqlength, genename)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
170 count = count + 1
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
171
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
172
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
173 if seqlength == 0:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
174 error.write(uniprot_accession_in + '\t' + "Uniprot not in Fasta" + '\n')
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
175 error.close
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
176 seqlength = 'NA'
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
177 genename = 'NA'
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
178 return ReturnValue1(seqlength, genename)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
179
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
180
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
181 def readtab(infile):
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
182 with open(infile,'r') as x: # read in tab-delim text
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
183 output = []
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
184 for line in x:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
185 line = line.strip()
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
186 temp = line.split('\t')
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
187 output.append(temp)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
188 return output
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
189 def read_maxquant(maxquant_input): # Get data, proteins and header from maxquant output
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
190 dupes = readtab(maxquant_input)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
191 header_start = 0
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
192 header = dupes[header_start]
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
193 for i in header:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
194 i = i.replace(r"\"", "")
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
195 i = i.replace(r"Intensity.", r"")
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
196 i = i.replace(r".", r"-")
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
197 data = dupes[header_start+1:len(dupes)] #cut off blank line and END OF FILE
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
198 proteins = []
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
199 for protein in data:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
200 proteins.append(protein[0])
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
201 return ReturnValue2(data, proteins, header)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
202 def make_inter(maxquant_input):
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
203 bait = readtab(baitfile)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
204 data = read_maxquant(maxquant_input).data
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
205 header = read_maxquant(maxquant_input).header
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
206 proteins = read_maxquant(maxquant_input).proteins
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
207 bait_index = []
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
208 for i in bait:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
209 bait_index.append(header.index("mapped_protein") + 1) # Find just the baits defined in bait file
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
210 with open('inter.txt', 'w') as y:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
211 a = 0; l=0
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
212 for bb in bait:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
213 for lst in data:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
214 y.write(header[bait_index[l]] + '\t' + bb[1] + '\t' + proteins[a] + '\t' + lst[bait_index[l]] + '\n')
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
215 a+=1
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
216 if a == len(proteins):
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
217 a = 0; l+=1
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
218 def make_prey(maxquant_input):
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
219 proteins = read_maxquant(maxquant_input).proteins
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
220 output_file = open("prey.txt",'w')
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
221 for a in proteins:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
222 a = a.replace("\n","") # remove \n for input into function
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
223 a = a.replace("\r","") # ditto for \r
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
224 seq = get_info(a).seqlength
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
225 GN = get_info(a).genename
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
226 if seq != 'NA':
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
227 output_file.write(a+"\t"+str(seq)+ "\t" + str(GN) + "\n")
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
228 output_file.close()
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
229 def no_error_inter(maxquant_input): # remake inter file without protein errors from Uniprot
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
230 err = readtab("error proteins.txt")
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
231 bait = readtab(baitfile)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
232 data = read_maxquant(maxquant_input).data
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
233 header = read_maxquant(maxquant_input).header
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
234 header = [i.replace(r"\"", "") for i in header]
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
235 header = [i.replace(r"Intensity.", r"") for i in header]
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
236 header = [i.replace(r".", r"-") for i in header]
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
237 print header
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
238 bait_index = []
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
239 for i in bait:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
240 bait_index.append(header.index(i[0]))
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
241 proteins = read_maxquant(maxquant_input).proteins
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
242 errors = []
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
243 for e in err:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
244 errors.append(e[0])
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
245 with open('inter.txt', 'w') as y:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
246 l = 0; a = 0
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
247 for bb in bait:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
248 for lst in data:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
249 if proteins[a] not in errors:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
250 y.write(header[bait_index[l]] + '\t' + bb[1] + '\t' + proteins[a] + '\t' + lst[bait_index[l]] + '\n')
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
251 a+=1
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
252 if a == len(proteins):
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
253 l += 1; a = 0
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
254 def bait_check(bait, maxquant_input): # check that bait names share header titles
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
255 bait_in = readtab(bait)
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
256 header = read_maxquant(maxquant_input).header
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
257 for i in bait_in:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
258 if i[0] not in header:
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
259 sys.exit("Bait must share header titles with maxquant output")
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
260
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
261 if __name__ == '__main__':
9c3d2b1d0c1c Uploaded
bornea
parents:
diff changeset
262 main(infile, make_bait)