47
|
1 import argparse
|
|
2 import logging
|
|
3 import sys
|
|
4 import os
|
|
5 import re
|
|
6
|
0
|
7 from collections import defaultdict
|
47
|
8
|
|
9 def main():
|
|
10 parser = argparse.ArgumentParser()
|
|
11 parser.add_argument("--input", help="The '7_V-REGION-mutation-and-AA-change-table' and '10_V-REGION-mutation-hotspots' merged together, with an added 'best_match' annotation")
|
|
12 parser.add_argument("--genes", help="The genes available in the 'best_match' column")
|
|
13 parser.add_argument("--empty_region_filter", help="Where does the sequence start?", choices=['leader', 'FR1', 'CDR1', 'FR2'])
|
|
14 parser.add_argument("--output", help="Output file")
|
0
|
15
|
47
|
16 args = parser.parse_args()
|
|
17
|
|
18 infile = args.input
|
|
19 genes = str(args.genes).split(",")
|
|
20 empty_region_filter = args.empty_region_filter
|
|
21 outfile = args.output
|
0
|
22
|
47
|
23 genedic = dict()
|
0
|
24
|
47
|
25 mutationdic = dict()
|
|
26 mutationMatcher = re.compile("^(.)(\d+).(.),?(.)?(\d+)?.?(.)?(.?.?.?.?.?)?")
|
|
27 NAMatchResult = (None, None, None, None, None, None, '')
|
|
28 geneMatchers = {gene: re.compile("^" + gene + ".*") for gene in genes}
|
|
29 linecount = 0
|
0
|
30
|
47
|
31 IDIndex = 0
|
|
32 best_matchIndex = 0
|
|
33 fr1Index = 0
|
|
34 cdr1Index = 0
|
|
35 fr2Index = 0
|
|
36 cdr2Index = 0
|
|
37 fr3Index = 0
|
|
38 first = True
|
|
39 IDlist = []
|
|
40 mutationList = []
|
|
41 mutationListByID = {}
|
|
42 cdr1LengthDic = {}
|
|
43 cdr2LengthDic = {}
|
|
44
|
|
45 fr1LengthDict = {}
|
|
46 fr2LengthDict = {}
|
|
47 fr3LengthDict = {}
|
|
48
|
|
49 cdr1LengthIndex = 0
|
|
50 cdr2LengthIndex = 0
|
0
|
51
|
47
|
52 fr1SeqIndex = 0
|
|
53 fr2SeqIndex = 0
|
|
54 fr3SeqIndex = 0
|
|
55
|
|
56 tandem_sum_by_class = defaultdict(int)
|
|
57 expected_tandem_sum_by_class = defaultdict(float)
|
0
|
58
|
47
|
59 with open(infile, 'ru') as i:
|
|
60 for line in i:
|
|
61 if first:
|
|
62 linesplt = line.split("\t")
|
|
63 IDIndex = linesplt.index("Sequence.ID")
|
|
64 best_matchIndex = linesplt.index("best_match")
|
|
65 fr1Index = linesplt.index("FR1.IMGT")
|
|
66 cdr1Index = linesplt.index("CDR1.IMGT")
|
|
67 fr2Index = linesplt.index("FR2.IMGT")
|
|
68 cdr2Index = linesplt.index("CDR2.IMGT")
|
|
69 fr3Index = linesplt.index("FR3.IMGT")
|
|
70 cdr1LengthIndex = linesplt.index("CDR1.IMGT.seq")
|
|
71 cdr2LengthIndex = linesplt.index("CDR2.IMGT.seq")
|
|
72 fr1SeqIndex = linesplt.index("FR1.IMGT.seq")
|
|
73 fr2SeqIndex = linesplt.index("FR2.IMGT.seq")
|
|
74 fr3SeqIndex = linesplt.index("FR3.IMGT.seq")
|
|
75 first = False
|
|
76 continue
|
|
77 linecount += 1
|
0
|
78 linesplt = line.split("\t")
|
47
|
79 ID = linesplt[IDIndex]
|
|
80 genedic[ID] = linesplt[best_matchIndex]
|
|
81 try:
|
|
82 mutationdic[ID + "_FR1"] = [mutationMatcher.match(x).groups() for x in linesplt[fr1Index].split("|") if x] if (linesplt[fr1Index] != "NA" and empty_region_filter == "leader") else []
|
|
83 mutationdic[ID + "_CDR1"] = [mutationMatcher.match(x).groups() for x in linesplt[cdr1Index].split("|") if x] if (linesplt[cdr1Index] != "NA" and empty_region_filter in ["leader", "FR1"]) else []
|
|
84 mutationdic[ID + "_FR2"] = [mutationMatcher.match(x).groups() for x in linesplt[fr2Index].split("|") if x] if (linesplt[fr2Index] != "NA" and empty_region_filter in ["leader", "FR1", "CDR1"]) else []
|
|
85 mutationdic[ID + "_CDR2"] = [mutationMatcher.match(x).groups() for x in linesplt[cdr2Index].split("|") if x] if (linesplt[cdr2Index] != "NA") else []
|
|
86 mutationdic[ID + "_FR2-CDR2"] = mutationdic[ID + "_FR2"] + mutationdic[ID + "_CDR2"]
|
|
87 mutationdic[ID + "_FR3"] = [mutationMatcher.match(x).groups() for x in linesplt[fr3Index].split("|") if x] if linesplt[fr3Index] != "NA" else []
|
|
88 except Exception as e:
|
|
89 print "Something went wrong while processing this line:"
|
|
90 print linesplt
|
|
91 print linecount
|
|
92 print e
|
|
93 mutationList += mutationdic[ID + "_FR1"] + mutationdic[ID + "_CDR1"] + mutationdic[ID + "_FR2"] + mutationdic[ID + "_CDR2"] + mutationdic[ID + "_FR3"]
|
|
94 mutationListByID[ID] = mutationdic[ID + "_FR1"] + mutationdic[ID + "_CDR1"] + mutationdic[ID + "_FR2"] + mutationdic[ID + "_CDR2"] + mutationdic[ID + "_FR3"]
|
|
95
|
|
96 cdr1Length = len(linesplt[cdr1LengthIndex])
|
|
97 cdr2Length = len(linesplt[cdr2LengthIndex])
|
|
98
|
|
99 #print linesplt[fr2SeqIndex]
|
|
100 fr1Length = len(linesplt[fr1SeqIndex]) if empty_region_filter == "leader" else 0
|
|
101 fr2Length = len(linesplt[fr2SeqIndex]) if empty_region_filter in ["leader", "FR1", "CDR1"] else 0
|
|
102 fr3Length = len(linesplt[fr3SeqIndex])
|
|
103
|
|
104 cdr1LengthDic[ID] = cdr1Length
|
|
105 cdr2LengthDic[ID] = cdr2Length
|
|
106
|
|
107 fr1LengthDict[ID] = fr1Length
|
|
108 fr2LengthDict[ID] = fr2Length
|
|
109 fr3LengthDict[ID] = fr3Length
|
|
110
|
|
111 IDlist += [ID]
|
|
112
|
|
113
|
|
114 #tandem mutation stuff
|
|
115 tandem_frequency = defaultdict(int)
|
|
116 mutation_frequency = defaultdict(int)
|
|
117
|
|
118 tandem_file = os.path.join(os.path.dirname(outfile), "tandems_by_id.txt")
|
|
119 with open(tandem_file, 'w') as o:
|
|
120 highest_tandem_length = 0
|
|
121
|
|
122 o.write("Sequence.ID\tnumber_of_mutations\tnumber_of_tandems\tregion_length\texpected_tandems\tlongest_tandem\ttandems\n")
|
|
123 for ID in IDlist:
|
|
124 mutations = mutationListByID[ID]
|
|
125 if len(mutations) == 0:
|
|
126 continue
|
|
127 last_mut = max(mutations, key=lambda x: int(x[1]))
|
|
128
|
|
129 last_mut_pos = int(last_mut[1])
|
|
130
|
|
131 mut_positions = [False] * (last_mut_pos + 1)
|
|
132
|
|
133 for mutation in mutations:
|
|
134 frm, where, to, frmAA, whereAA, toAA, thing = mutation
|
|
135 where = int(where)
|
|
136 mut_positions[where] = True
|
|
137
|
|
138 tandem_muts = []
|
|
139 tandem_start = -1
|
|
140 tandem_length = 0
|
|
141 for i in range(len(mut_positions)):
|
|
142 if mut_positions[i]:
|
|
143 if tandem_start == -1:
|
|
144 tandem_start = i
|
|
145 tandem_length += 1
|
|
146 #print "".join(["1" if x else "0" for x in mut_positions[:i+1]])
|
|
147 else:
|
|
148 if tandem_length > 1:
|
|
149 tandem_muts.append((tandem_start, tandem_length))
|
|
150 #print "{0}{1} {2}:{3}".format(" " * (i - tandem_length), "^" * tandem_length, tandem_start, tandem_length)
|
|
151 tandem_start = -1
|
|
152 tandem_length = 0
|
|
153 if tandem_length > 1: # if the sequence ends with a tandem mutation
|
|
154 tandem_muts.append((tandem_start, tandem_length))
|
|
155
|
|
156 if len(tandem_muts) > 0:
|
|
157 if highest_tandem_length < len(tandem_muts):
|
|
158 highest_tandem_length = len(tandem_muts)
|
0
|
159
|
47
|
160 region_length = fr1LengthDict[ID] + cdr1LengthDic[ID] + fr2LengthDict[ID] + cdr2LengthDic[ID] + fr3LengthDict[ID]
|
|
161 longest_tandem = max(tandem_muts, key=lambda x: x[1]) if len(tandem_muts) else (0, 0)
|
|
162 num_mutations = len(mutations)
|
|
163 f_num_mutations = float(num_mutations)
|
|
164 num_tandem_muts = len(tandem_muts)
|
|
165 expected_tandem_muts = f_num_mutations * (f_num_mutations - 1.0) / float(region_length)
|
|
166 o.write("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\n".format(ID,
|
|
167 str(num_mutations),
|
|
168 str(num_tandem_muts),
|
|
169 str(region_length),
|
|
170 str(round(expected_tandem_muts, 2)),
|
|
171 str(longest_tandem[1]),
|
|
172 str(tandem_muts)))
|
|
173 gene = genedic[ID]
|
|
174 if gene.find("unmatched") == -1:
|
|
175 tandem_sum_by_class[gene] += num_tandem_muts
|
|
176 expected_tandem_sum_by_class[gene] += expected_tandem_muts
|
0
|
177
|
47
|
178 tandem_sum_by_class["all"] += num_tandem_muts
|
|
179 expected_tandem_sum_by_class["all"] += expected_tandem_muts
|
0
|
180
|
47
|
181 gene = gene[:3]
|
|
182 if gene in ["IGA", "IGG"]:
|
|
183 tandem_sum_by_class[gene] += num_tandem_muts
|
|
184 expected_tandem_sum_by_class[gene] += expected_tandem_muts
|
|
185 else:
|
|
186 tandem_sum_by_class["unmatched"] += num_tandem_muts
|
|
187 expected_tandem_sum_by_class["unmatched"] += expected_tandem_muts
|
|
188
|
40
|
189
|
47
|
190 for tandem_mut in tandem_muts:
|
|
191 tandem_frequency[str(tandem_mut[1])] += 1
|
|
192 #print "\t".join([ID, str(len(tandem_muts)), str(longest_tandem[1]) , str(tandem_muts)])
|
|
193
|
|
194 tandem_freq_file = os.path.join(os.path.dirname(outfile), "tandem_frequency.txt")
|
|
195 with open(tandem_freq_file, 'w') as o:
|
|
196 for frq in sorted([int(x) for x in tandem_frequency.keys()]):
|
|
197 o.write("{0}\t{1}\n".format(frq, tandem_frequency[str(frq)]))
|
0
|
198
|
47
|
199 tandem_row = []
|
|
200 print genes
|
|
201 print tandem_sum_by_class
|
|
202 print expected_tandem_sum_by_class
|
|
203 genes_extra = list(genes)
|
|
204 genes_extra.append("all")
|
|
205 for x, y, in zip([tandem_sum_by_class[x] for x in genes_extra], [expected_tandem_sum_by_class[x] for x in genes_extra]):
|
|
206 if y != 0:
|
|
207 tandem_row += [x, round(y, 2), round(x / y, 2)]
|
|
208 else:
|
|
209 tandem_row += [x, round(y, 2), 0]
|
|
210
|
|
211 """
|
|
212 print tandem_row
|
|
213 tandem_row += tandem_row[-3:]
|
|
214 print tandem_row
|
|
215 all_expected_tandem = expected_tandem_sum_by_class["all"]
|
|
216 all_tandem = tandem_sum_by_class["all"]
|
|
217 if all_expected_tandem == 0:
|
|
218 tandem_row[-6:-3] = [all_tandem, round(all_expected_tandem, 2), 0]
|
|
219 else:
|
|
220 tandem_row[-6:-3] = [all_tandem, round(all_expected_tandem, 2), round(all_tandem / all_expected_tandem, 2)]
|
|
221 print tandem_row
|
|
222 """
|
|
223 for i in range(len(genes_extra)):
|
|
224 gene = genes_extra[i]
|
|
225 print gene, tandem_row[i*3:i*3+3]
|
0
|
226
|
47
|
227 tandem_freq_file = os.path.join(os.path.dirname(outfile), "shm_overview_tandem_row.txt")
|
|
228 with open(tandem_freq_file, 'w') as o:
|
|
229 o.write("Tandems/Expected (ratio),{0}\n".format(",".join([str(x) for x in tandem_row])))
|
|
230
|
|
231 #print mutationList, linecount
|
|
232
|
|
233 AALength = (int(max(mutationList, key=lambda i: int(i[4]) if i[4] else 0)[4]) + 1) # [4] is the position of the AA mutation, None if silent
|
|
234 if AALength < 60:
|
|
235 AALength = 64
|
|
236
|
|
237 AA_mutation = [0] * AALength
|
|
238 AA_mutation_dic = {"IGA": AA_mutation[:], "IGG": AA_mutation[:], "IGM": AA_mutation[:], "IGE": AA_mutation[:], "unm": AA_mutation[:], "all": AA_mutation[:]}
|
|
239 AA_mutation_empty = AA_mutation[:]
|
|
240
|
|
241 aa_mutations_by_id_file = outfile[:outfile.rindex("/")] + "/aa_id_mutations.txt"
|
|
242 with open(aa_mutations_by_id_file, 'w') as o:
|
|
243 o.write("ID\tbest_match\t" + "\t".join([str(x) for x in range(1,AALength)]) + "\n")
|
|
244 for ID in mutationListByID.keys():
|
|
245 AA_mutation_for_ID = AA_mutation_empty[:]
|
|
246 for mutation in mutationListByID[ID]:
|
|
247 if mutation[4]:
|
|
248 AA_mutation_position = int(mutation[4])
|
|
249 AA_mutation[AA_mutation_position] += 1
|
|
250 AA_mutation_for_ID[AA_mutation_position] += 1
|
|
251 clss = genedic[ID][:3]
|
|
252 AA_mutation_dic[clss][AA_mutation_position] += 1
|
|
253 o.write(ID + "\t" + genedic[ID] + "\t" + "\t".join([str(x) for x in AA_mutation_for_ID[1:]]) + "\n")
|
0
|
254
|
|
255
|
|
256
|
47
|
257 #absent AA stuff
|
|
258 absentAACDR1Dic = defaultdict(list)
|
|
259 absentAACDR1Dic[5] = range(29,36)
|
|
260 absentAACDR1Dic[6] = range(29,35)
|
|
261 absentAACDR1Dic[7] = range(30,35)
|
|
262 absentAACDR1Dic[8] = range(30,34)
|
|
263 absentAACDR1Dic[9] = range(31,34)
|
|
264 absentAACDR1Dic[10] = range(31,33)
|
|
265 absentAACDR1Dic[11] = [32]
|
0
|
266
|
47
|
267 absentAACDR2Dic = defaultdict(list)
|
|
268 absentAACDR2Dic[0] = range(55,65)
|
|
269 absentAACDR2Dic[1] = range(56,65)
|
|
270 absentAACDR2Dic[2] = range(56,64)
|
|
271 absentAACDR2Dic[3] = range(57,64)
|
|
272 absentAACDR2Dic[4] = range(57,63)
|
|
273 absentAACDR2Dic[5] = range(58,63)
|
|
274 absentAACDR2Dic[6] = range(58,62)
|
|
275 absentAACDR2Dic[7] = range(59,62)
|
|
276 absentAACDR2Dic[8] = range(59,61)
|
|
277 absentAACDR2Dic[9] = [60]
|
0
|
278
|
47
|
279 absentAA = [len(IDlist)] * (AALength-1)
|
|
280 for k, cdr1Length in cdr1LengthDic.iteritems():
|
|
281 for c in absentAACDR1Dic[cdr1Length]:
|
|
282 absentAA[c] -= 1
|
0
|
283
|
47
|
284 for k, cdr2Length in cdr2LengthDic.iteritems():
|
|
285 for c in absentAACDR2Dic[cdr2Length]:
|
|
286 absentAA[c] -= 1
|
0
|
287
|
|
288
|
47
|
289 aa_mutations_by_id_file = outfile[:outfile.rindex("/")] + "/absent_aa_id.txt"
|
|
290 with open(aa_mutations_by_id_file, 'w') as o:
|
|
291 o.write("ID\tcdr1length\tcdr2length\tbest_match\t" + "\t".join([str(x) for x in range(1,AALength)]) + "\n")
|
|
292 for ID in IDlist:
|
|
293 absentAAbyID = [1] * (AALength-1)
|
|
294 cdr1Length = cdr1LengthDic[ID]
|
|
295 for c in absentAACDR1Dic[cdr1Length]:
|
|
296 absentAAbyID[c] -= 1
|
0
|
297
|
47
|
298 cdr2Length = cdr2LengthDic[ID]
|
|
299 for c in absentAACDR2Dic[cdr2Length]:
|
|
300 absentAAbyID[c] -= 1
|
|
301 o.write(ID + "\t" + str(cdr1Length) + "\t" + str(cdr2Length) + "\t" + genedic[ID] + "\t" + "\t".join([str(x) for x in absentAAbyID]) + "\n")
|
0
|
302
|
47
|
303 if linecount == 0:
|
|
304 print "No data, exiting"
|
|
305 with open(outfile, 'w') as o:
|
|
306 o.write("RGYW (%)," + ("0,0,0\n" * len(genes)))
|
|
307 o.write("WRCY (%)," + ("0,0,0\n" * len(genes)))
|
|
308 o.write("WA (%)," + ("0,0,0\n" * len(genes)))
|
|
309 o.write("TW (%)," + ("0,0,0\n" * len(genes)))
|
|
310 import sys
|
0
|
311
|
47
|
312 sys.exit()
|
0
|
313
|
47
|
314 hotspotMatcher = re.compile("[actg]+,(\d+)-(\d+)\((.*)\)")
|
|
315 RGYWCount = {}
|
|
316 WRCYCount = {}
|
|
317 WACount = {}
|
|
318 TWCount = {}
|
0
|
319
|
47
|
320 #IDIndex = 0
|
|
321 ataIndex = 0
|
|
322 tatIndex = 0
|
|
323 aggctatIndex = 0
|
|
324 atagcctIndex = 0
|
|
325 first = True
|
|
326 with open(infile, 'ru') as i:
|
|
327 for line in i:
|
|
328 if first:
|
|
329 linesplt = line.split("\t")
|
|
330 ataIndex = linesplt.index("X.a.t.a")
|
|
331 tatIndex = linesplt.index("t.a.t.")
|
|
332 aggctatIndex = linesplt.index("X.a.g.g.c.t..a.t.")
|
|
333 atagcctIndex = linesplt.index("X.a.t..a.g.c.c.t.")
|
|
334 first = False
|
|
335 continue
|
0
|
336 linesplt = line.split("\t")
|
47
|
337 gene = linesplt[best_matchIndex]
|
|
338 ID = linesplt[IDIndex]
|
|
339 RGYW = [(int(x), int(y), z) for (x, y, z) in
|
|
340 [hotspotMatcher.match(x).groups() for x in linesplt[aggctatIndex].split("|") if x]]
|
|
341 WRCY = [(int(x), int(y), z) for (x, y, z) in
|
|
342 [hotspotMatcher.match(x).groups() for x in linesplt[atagcctIndex].split("|") if x]]
|
|
343 WA = [(int(x), int(y), z) for (x, y, z) in
|
|
344 [hotspotMatcher.match(x).groups() for x in linesplt[ataIndex].split("|") if x]]
|
|
345 TW = [(int(x), int(y), z) for (x, y, z) in
|
|
346 [hotspotMatcher.match(x).groups() for x in linesplt[tatIndex].split("|") if x]]
|
|
347 RGYWCount[ID], WRCYCount[ID], WACount[ID], TWCount[ID] = 0, 0, 0, 0
|
0
|
348
|
47
|
349 mutationList = mutationdic[ID + "_FR1"] + mutationdic[ID + "_CDR1"] + mutationdic[ID + "_FR2"] + mutationdic[ID + "_CDR2"] + mutationdic[ID + "_FR3"]
|
|
350 for mutation in mutationList:
|
|
351 frm, where, to, AAfrm, AAwhere, AAto, junk = mutation
|
|
352 mutation_in_RGYW = any([(start <= int(where) <= end) for (start, end, region) in RGYW])
|
|
353 mutation_in_WRCY = any([(start <= int(where) <= end) for (start, end, region) in WRCY])
|
|
354 mutation_in_WA = any([(start <= int(where) <= end) for (start, end, region) in WA])
|
|
355 mutation_in_TW = any([(start <= int(where) <= end) for (start, end, region) in TW])
|
0
|
356
|
47
|
357 in_how_many_motifs = sum([mutation_in_RGYW, mutation_in_WRCY, mutation_in_WA, mutation_in_TW])
|
0
|
358
|
47
|
359 if in_how_many_motifs > 0:
|
|
360 RGYWCount[ID] += (1.0 * int(mutation_in_RGYW)) / in_how_many_motifs
|
|
361 WRCYCount[ID] += (1.0 * int(mutation_in_WRCY)) / in_how_many_motifs
|
|
362 WACount[ID] += (1.0 * int(mutation_in_WA)) / in_how_many_motifs
|
|
363 TWCount[ID] += (1.0 * int(mutation_in_TW)) / in_how_many_motifs
|
0
|
364
|
|
365
|
47
|
366 def mean(lst):
|
|
367 return (float(sum(lst)) / len(lst)) if len(lst) > 0 else 0.0
|
0
|
368
|
|
369
|
47
|
370 def median(lst):
|
|
371 lst = sorted(lst)
|
|
372 l = len(lst)
|
|
373 if l == 0:
|
|
374 return 0
|
|
375 if l == 1:
|
|
376 return lst[0]
|
|
377
|
|
378 l = int(l / 2)
|
0
|
379
|
47
|
380 if len(lst) % 2 == 0:
|
|
381 return float(lst[l] + lst[(l - 1)]) / 2.0
|
|
382 else:
|
|
383 return lst[l]
|
0
|
384
|
47
|
385 funcs = {"mean": mean, "median": median, "sum": sum}
|
0
|
386
|
47
|
387 directory = outfile[:outfile.rfind("/") + 1]
|
|
388 value = 0
|
|
389 valuedic = dict()
|
0
|
390
|
47
|
391 for fname in funcs.keys():
|
|
392 for gene in genes:
|
|
393 with open(directory + gene + "_" + fname + "_value.txt", 'r') as v:
|
|
394 valuedic[gene + "_" + fname] = float(v.readlines()[0].rstrip())
|
|
395 with open(directory + "all_" + fname + "_value.txt", 'r') as v:
|
|
396 valuedic["total_" + fname] = float(v.readlines()[0].rstrip())
|
|
397
|
0
|
398
|
47
|
399 def get_xyz(lst, gene, f, fname):
|
|
400 x = round(round(f(lst), 1))
|
|
401 y = valuedic[gene + "_" + fname]
|
|
402 z = str(round(x / float(y) * 100, 1)) if y != 0 else "0"
|
|
403 return (str(x), str(y), z)
|
0
|
404
|
47
|
405 dic = {"RGYW": RGYWCount, "WRCY": WRCYCount, "WA": WACount, "TW": TWCount}
|
|
406 arr = ["RGYW", "WRCY", "WA", "TW"]
|
0
|
407
|
47
|
408 for fname in funcs.keys():
|
|
409 func = funcs[fname]
|
|
410 foutfile = outfile[:outfile.rindex("/")] + "/hotspot_analysis_" + fname + ".txt"
|
|
411 with open(foutfile, 'w') as o:
|
|
412 for typ in arr:
|
|
413 o.write(typ + " (%)")
|
|
414 curr = dic[typ]
|
|
415 for gene in genes:
|
|
416 geneMatcher = geneMatchers[gene]
|
|
417 if valuedic[gene + "_" + fname] is 0:
|
|
418 o.write(",0,0,0")
|
|
419 else:
|
|
420 x, y, z = get_xyz([curr[x] for x in [y for y, z in genedic.iteritems() if geneMatcher.match(z)]], gene, func, fname)
|
|
421 o.write("," + x + "," + y + "," + z)
|
|
422 x, y, z = get_xyz([y for x, y in curr.iteritems() if not genedic[x].startswith("unmatched")], "total", func, fname)
|
|
423 #x, y, z = get_xyz([y for x, y in curr.iteritems()], "total", func, fname)
|
|
424 o.write("," + x + "," + y + "," + z + "\n")
|
0
|
425
|
|
426
|
47
|
427 # for testing
|
|
428 seq_motif_file = outfile[:outfile.rindex("/")] + "/motif_per_seq.txt"
|
|
429 with open(seq_motif_file, 'w') as o:
|
|
430 o.write("ID\tRGYW\tWRCY\tWA\tTW\n")
|
|
431 for ID in IDlist:
|
|
432 #o.write(ID + "\t" + str(round(RGYWCount[ID], 2)) + "\t" + str(round(WRCYCount[ID], 2)) + "\t" + str(round(WACount[ID], 2)) + "\t" + str(round(TWCount[ID], 2)) + "\n")
|
|
433 o.write(ID + "\t" + str(RGYWCount[ID]) + "\t" + str(WRCYCount[ID]) + "\t" + str(WACount[ID]) + "\t" + str(TWCount[ID]) + "\n")
|
|
434
|
|
435 if __name__ == "__main__":
|
|
436 main()
|