annotate SAINT_preprocessing.py @ 78:211fd8ae6edc draft

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