annotate SAINT_preprocessing_v6.py @ 20:e21be0412789 draft

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