annotate SAINT_preprocessing_v6_mq_pep.py @ 23:4e78eebffda3 draft

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