annotate SAINT_preprocessing_v6.py @ 32:fce21ee45396 draft

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