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)
|
48
|
117
|
|
118 mutations_by_id_dic = {}
|
|
119 first = True
|
|
120 mutation_by_id_file = os.path.join(os.path.dirname(outfile), "mutation_by_id.txt")
|
|
121 with open(mutation_by_id_file, 'r') as mutation_by_id:
|
|
122 for l in mutation_by_id:
|
|
123 if first:
|
|
124 first = False
|
|
125 continue
|
|
126 splt = l.split("\t")
|
|
127 mutations_by_id_dic[splt[0]] = int(splt[1])
|
|
128
|
47
|
129 tandem_file = os.path.join(os.path.dirname(outfile), "tandems_by_id.txt")
|
|
130 with open(tandem_file, 'w') as o:
|
|
131 highest_tandem_length = 0
|
|
132
|
|
133 o.write("Sequence.ID\tnumber_of_mutations\tnumber_of_tandems\tregion_length\texpected_tandems\tlongest_tandem\ttandems\n")
|
|
134 for ID in IDlist:
|
|
135 mutations = mutationListByID[ID]
|
|
136 if len(mutations) == 0:
|
|
137 continue
|
|
138 last_mut = max(mutations, key=lambda x: int(x[1]))
|
|
139
|
|
140 last_mut_pos = int(last_mut[1])
|
|
141
|
|
142 mut_positions = [False] * (last_mut_pos + 1)
|
|
143
|
|
144 for mutation in mutations:
|
|
145 frm, where, to, frmAA, whereAA, toAA, thing = mutation
|
|
146 where = int(where)
|
|
147 mut_positions[where] = True
|
|
148
|
|
149 tandem_muts = []
|
|
150 tandem_start = -1
|
|
151 tandem_length = 0
|
|
152 for i in range(len(mut_positions)):
|
|
153 if mut_positions[i]:
|
|
154 if tandem_start == -1:
|
|
155 tandem_start = i
|
|
156 tandem_length += 1
|
|
157 #print "".join(["1" if x else "0" for x in mut_positions[:i+1]])
|
|
158 else:
|
|
159 if tandem_length > 1:
|
|
160 tandem_muts.append((tandem_start, tandem_length))
|
|
161 #print "{0}{1} {2}:{3}".format(" " * (i - tandem_length), "^" * tandem_length, tandem_start, tandem_length)
|
|
162 tandem_start = -1
|
|
163 tandem_length = 0
|
|
164 if tandem_length > 1: # if the sequence ends with a tandem mutation
|
|
165 tandem_muts.append((tandem_start, tandem_length))
|
|
166
|
|
167 if len(tandem_muts) > 0:
|
|
168 if highest_tandem_length < len(tandem_muts):
|
|
169 highest_tandem_length = len(tandem_muts)
|
0
|
170
|
47
|
171 region_length = fr1LengthDict[ID] + cdr1LengthDic[ID] + fr2LengthDict[ID] + cdr2LengthDic[ID] + fr3LengthDict[ID]
|
|
172 longest_tandem = max(tandem_muts, key=lambda x: x[1]) if len(tandem_muts) else (0, 0)
|
48
|
173 num_mutations = mutations_by_id_dic[ID] # len(mutations)
|
47
|
174 f_num_mutations = float(num_mutations)
|
|
175 num_tandem_muts = len(tandem_muts)
|
|
176 expected_tandem_muts = f_num_mutations * (f_num_mutations - 1.0) / float(region_length)
|
|
177 o.write("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\n".format(ID,
|
|
178 str(num_mutations),
|
|
179 str(num_tandem_muts),
|
|
180 str(region_length),
|
|
181 str(round(expected_tandem_muts, 2)),
|
|
182 str(longest_tandem[1]),
|
|
183 str(tandem_muts)))
|
|
184 gene = genedic[ID]
|
|
185 if gene.find("unmatched") == -1:
|
|
186 tandem_sum_by_class[gene] += num_tandem_muts
|
|
187 expected_tandem_sum_by_class[gene] += expected_tandem_muts
|
0
|
188
|
47
|
189 tandem_sum_by_class["all"] += num_tandem_muts
|
|
190 expected_tandem_sum_by_class["all"] += expected_tandem_muts
|
0
|
191
|
47
|
192 gene = gene[:3]
|
|
193 if gene in ["IGA", "IGG"]:
|
|
194 tandem_sum_by_class[gene] += num_tandem_muts
|
|
195 expected_tandem_sum_by_class[gene] += expected_tandem_muts
|
|
196 else:
|
|
197 tandem_sum_by_class["unmatched"] += num_tandem_muts
|
|
198 expected_tandem_sum_by_class["unmatched"] += expected_tandem_muts
|
|
199
|
40
|
200
|
47
|
201 for tandem_mut in tandem_muts:
|
|
202 tandem_frequency[str(tandem_mut[1])] += 1
|
|
203 #print "\t".join([ID, str(len(tandem_muts)), str(longest_tandem[1]) , str(tandem_muts)])
|
|
204
|
|
205 tandem_freq_file = os.path.join(os.path.dirname(outfile), "tandem_frequency.txt")
|
|
206 with open(tandem_freq_file, 'w') as o:
|
|
207 for frq in sorted([int(x) for x in tandem_frequency.keys()]):
|
|
208 o.write("{0}\t{1}\n".format(frq, tandem_frequency[str(frq)]))
|
0
|
209
|
47
|
210 tandem_row = []
|
|
211 genes_extra = list(genes)
|
|
212 genes_extra.append("all")
|
|
213 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]):
|
|
214 if y != 0:
|
|
215 tandem_row += [x, round(y, 2), round(x / y, 2)]
|
|
216 else:
|
|
217 tandem_row += [x, round(y, 2), 0]
|
0
|
218
|
47
|
219 tandem_freq_file = os.path.join(os.path.dirname(outfile), "shm_overview_tandem_row.txt")
|
|
220 with open(tandem_freq_file, 'w') as o:
|
|
221 o.write("Tandems/Expected (ratio),{0}\n".format(",".join([str(x) for x in tandem_row])))
|
|
222
|
|
223 #print mutationList, linecount
|
|
224
|
|
225 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
|
|
226 if AALength < 60:
|
|
227 AALength = 64
|
|
228
|
|
229 AA_mutation = [0] * AALength
|
|
230 AA_mutation_dic = {"IGA": AA_mutation[:], "IGG": AA_mutation[:], "IGM": AA_mutation[:], "IGE": AA_mutation[:], "unm": AA_mutation[:], "all": AA_mutation[:]}
|
|
231 AA_mutation_empty = AA_mutation[:]
|
|
232
|
|
233 aa_mutations_by_id_file = outfile[:outfile.rindex("/")] + "/aa_id_mutations.txt"
|
|
234 with open(aa_mutations_by_id_file, 'w') as o:
|
|
235 o.write("ID\tbest_match\t" + "\t".join([str(x) for x in range(1,AALength)]) + "\n")
|
|
236 for ID in mutationListByID.keys():
|
|
237 AA_mutation_for_ID = AA_mutation_empty[:]
|
|
238 for mutation in mutationListByID[ID]:
|
|
239 if mutation[4]:
|
|
240 AA_mutation_position = int(mutation[4])
|
|
241 AA_mutation[AA_mutation_position] += 1
|
|
242 AA_mutation_for_ID[AA_mutation_position] += 1
|
|
243 clss = genedic[ID][:3]
|
|
244 AA_mutation_dic[clss][AA_mutation_position] += 1
|
|
245 o.write(ID + "\t" + genedic[ID] + "\t" + "\t".join([str(x) for x in AA_mutation_for_ID[1:]]) + "\n")
|
0
|
246
|
|
247
|
|
248
|
47
|
249 #absent AA stuff
|
|
250 absentAACDR1Dic = defaultdict(list)
|
|
251 absentAACDR1Dic[5] = range(29,36)
|
|
252 absentAACDR1Dic[6] = range(29,35)
|
|
253 absentAACDR1Dic[7] = range(30,35)
|
|
254 absentAACDR1Dic[8] = range(30,34)
|
|
255 absentAACDR1Dic[9] = range(31,34)
|
|
256 absentAACDR1Dic[10] = range(31,33)
|
|
257 absentAACDR1Dic[11] = [32]
|
0
|
258
|
47
|
259 absentAACDR2Dic = defaultdict(list)
|
|
260 absentAACDR2Dic[0] = range(55,65)
|
|
261 absentAACDR2Dic[1] = range(56,65)
|
|
262 absentAACDR2Dic[2] = range(56,64)
|
|
263 absentAACDR2Dic[3] = range(57,64)
|
|
264 absentAACDR2Dic[4] = range(57,63)
|
|
265 absentAACDR2Dic[5] = range(58,63)
|
|
266 absentAACDR2Dic[6] = range(58,62)
|
|
267 absentAACDR2Dic[7] = range(59,62)
|
|
268 absentAACDR2Dic[8] = range(59,61)
|
|
269 absentAACDR2Dic[9] = [60]
|
0
|
270
|
47
|
271 absentAA = [len(IDlist)] * (AALength-1)
|
|
272 for k, cdr1Length in cdr1LengthDic.iteritems():
|
|
273 for c in absentAACDR1Dic[cdr1Length]:
|
|
274 absentAA[c] -= 1
|
0
|
275
|
47
|
276 for k, cdr2Length in cdr2LengthDic.iteritems():
|
|
277 for c in absentAACDR2Dic[cdr2Length]:
|
|
278 absentAA[c] -= 1
|
0
|
279
|
|
280
|
47
|
281 aa_mutations_by_id_file = outfile[:outfile.rindex("/")] + "/absent_aa_id.txt"
|
|
282 with open(aa_mutations_by_id_file, 'w') as o:
|
|
283 o.write("ID\tcdr1length\tcdr2length\tbest_match\t" + "\t".join([str(x) for x in range(1,AALength)]) + "\n")
|
|
284 for ID in IDlist:
|
|
285 absentAAbyID = [1] * (AALength-1)
|
|
286 cdr1Length = cdr1LengthDic[ID]
|
|
287 for c in absentAACDR1Dic[cdr1Length]:
|
|
288 absentAAbyID[c] -= 1
|
0
|
289
|
47
|
290 cdr2Length = cdr2LengthDic[ID]
|
|
291 for c in absentAACDR2Dic[cdr2Length]:
|
|
292 absentAAbyID[c] -= 1
|
|
293 o.write(ID + "\t" + str(cdr1Length) + "\t" + str(cdr2Length) + "\t" + genedic[ID] + "\t" + "\t".join([str(x) for x in absentAAbyID]) + "\n")
|
0
|
294
|
47
|
295 if linecount == 0:
|
|
296 print "No data, exiting"
|
|
297 with open(outfile, 'w') as o:
|
|
298 o.write("RGYW (%)," + ("0,0,0\n" * len(genes)))
|
|
299 o.write("WRCY (%)," + ("0,0,0\n" * len(genes)))
|
|
300 o.write("WA (%)," + ("0,0,0\n" * len(genes)))
|
|
301 o.write("TW (%)," + ("0,0,0\n" * len(genes)))
|
|
302 import sys
|
0
|
303
|
47
|
304 sys.exit()
|
0
|
305
|
47
|
306 hotspotMatcher = re.compile("[actg]+,(\d+)-(\d+)\((.*)\)")
|
|
307 RGYWCount = {}
|
|
308 WRCYCount = {}
|
|
309 WACount = {}
|
|
310 TWCount = {}
|
0
|
311
|
47
|
312 #IDIndex = 0
|
|
313 ataIndex = 0
|
|
314 tatIndex = 0
|
|
315 aggctatIndex = 0
|
|
316 atagcctIndex = 0
|
|
317 first = True
|
|
318 with open(infile, 'ru') as i:
|
|
319 for line in i:
|
|
320 if first:
|
|
321 linesplt = line.split("\t")
|
|
322 ataIndex = linesplt.index("X.a.t.a")
|
|
323 tatIndex = linesplt.index("t.a.t.")
|
|
324 aggctatIndex = linesplt.index("X.a.g.g.c.t..a.t.")
|
|
325 atagcctIndex = linesplt.index("X.a.t..a.g.c.c.t.")
|
|
326 first = False
|
|
327 continue
|
0
|
328 linesplt = line.split("\t")
|
47
|
329 gene = linesplt[best_matchIndex]
|
|
330 ID = linesplt[IDIndex]
|
|
331 RGYW = [(int(x), int(y), z) for (x, y, z) in
|
|
332 [hotspotMatcher.match(x).groups() for x in linesplt[aggctatIndex].split("|") if x]]
|
|
333 WRCY = [(int(x), int(y), z) for (x, y, z) in
|
|
334 [hotspotMatcher.match(x).groups() for x in linesplt[atagcctIndex].split("|") if x]]
|
|
335 WA = [(int(x), int(y), z) for (x, y, z) in
|
|
336 [hotspotMatcher.match(x).groups() for x in linesplt[ataIndex].split("|") if x]]
|
|
337 TW = [(int(x), int(y), z) for (x, y, z) in
|
|
338 [hotspotMatcher.match(x).groups() for x in linesplt[tatIndex].split("|") if x]]
|
|
339 RGYWCount[ID], WRCYCount[ID], WACount[ID], TWCount[ID] = 0, 0, 0, 0
|
0
|
340
|
47
|
341 mutationList = mutationdic[ID + "_FR1"] + mutationdic[ID + "_CDR1"] + mutationdic[ID + "_FR2"] + mutationdic[ID + "_CDR2"] + mutationdic[ID + "_FR3"]
|
|
342 for mutation in mutationList:
|
|
343 frm, where, to, AAfrm, AAwhere, AAto, junk = mutation
|
|
344 mutation_in_RGYW = any([(start <= int(where) <= end) for (start, end, region) in RGYW])
|
|
345 mutation_in_WRCY = any([(start <= int(where) <= end) for (start, end, region) in WRCY])
|
|
346 mutation_in_WA = any([(start <= int(where) <= end) for (start, end, region) in WA])
|
|
347 mutation_in_TW = any([(start <= int(where) <= end) for (start, end, region) in TW])
|
0
|
348
|
47
|
349 in_how_many_motifs = sum([mutation_in_RGYW, mutation_in_WRCY, mutation_in_WA, mutation_in_TW])
|
0
|
350
|
47
|
351 if in_how_many_motifs > 0:
|
|
352 RGYWCount[ID] += (1.0 * int(mutation_in_RGYW)) / in_how_many_motifs
|
|
353 WRCYCount[ID] += (1.0 * int(mutation_in_WRCY)) / in_how_many_motifs
|
|
354 WACount[ID] += (1.0 * int(mutation_in_WA)) / in_how_many_motifs
|
|
355 TWCount[ID] += (1.0 * int(mutation_in_TW)) / in_how_many_motifs
|
0
|
356
|
|
357
|
47
|
358 def mean(lst):
|
|
359 return (float(sum(lst)) / len(lst)) if len(lst) > 0 else 0.0
|
0
|
360
|
|
361
|
47
|
362 def median(lst):
|
|
363 lst = sorted(lst)
|
|
364 l = len(lst)
|
|
365 if l == 0:
|
|
366 return 0
|
|
367 if l == 1:
|
|
368 return lst[0]
|
|
369
|
|
370 l = int(l / 2)
|
0
|
371
|
47
|
372 if len(lst) % 2 == 0:
|
|
373 return float(lst[l] + lst[(l - 1)]) / 2.0
|
|
374 else:
|
|
375 return lst[l]
|
0
|
376
|
47
|
377 funcs = {"mean": mean, "median": median, "sum": sum}
|
0
|
378
|
47
|
379 directory = outfile[:outfile.rfind("/") + 1]
|
|
380 value = 0
|
|
381 valuedic = dict()
|
0
|
382
|
47
|
383 for fname in funcs.keys():
|
|
384 for gene in genes:
|
|
385 with open(directory + gene + "_" + fname + "_value.txt", 'r') as v:
|
|
386 valuedic[gene + "_" + fname] = float(v.readlines()[0].rstrip())
|
|
387 with open(directory + "all_" + fname + "_value.txt", 'r') as v:
|
|
388 valuedic["total_" + fname] = float(v.readlines()[0].rstrip())
|
|
389
|
0
|
390
|
47
|
391 def get_xyz(lst, gene, f, fname):
|
|
392 x = round(round(f(lst), 1))
|
|
393 y = valuedic[gene + "_" + fname]
|
|
394 z = str(round(x / float(y) * 100, 1)) if y != 0 else "0"
|
|
395 return (str(x), str(y), z)
|
0
|
396
|
47
|
397 dic = {"RGYW": RGYWCount, "WRCY": WRCYCount, "WA": WACount, "TW": TWCount}
|
|
398 arr = ["RGYW", "WRCY", "WA", "TW"]
|
0
|
399
|
47
|
400 for fname in funcs.keys():
|
|
401 func = funcs[fname]
|
|
402 foutfile = outfile[:outfile.rindex("/")] + "/hotspot_analysis_" + fname + ".txt"
|
|
403 with open(foutfile, 'w') as o:
|
|
404 for typ in arr:
|
|
405 o.write(typ + " (%)")
|
|
406 curr = dic[typ]
|
|
407 for gene in genes:
|
|
408 geneMatcher = geneMatchers[gene]
|
|
409 if valuedic[gene + "_" + fname] is 0:
|
|
410 o.write(",0,0,0")
|
|
411 else:
|
|
412 x, y, z = get_xyz([curr[x] for x in [y for y, z in genedic.iteritems() if geneMatcher.match(z)]], gene, func, fname)
|
|
413 o.write("," + x + "," + y + "," + z)
|
|
414 x, y, z = get_xyz([y for x, y in curr.iteritems() if not genedic[x].startswith("unmatched")], "total", func, fname)
|
|
415 #x, y, z = get_xyz([y for x, y in curr.iteritems()], "total", func, fname)
|
|
416 o.write("," + x + "," + y + "," + z + "\n")
|
0
|
417
|
|
418
|
47
|
419 # for testing
|
|
420 seq_motif_file = outfile[:outfile.rindex("/")] + "/motif_per_seq.txt"
|
|
421 with open(seq_motif_file, 'w') as o:
|
|
422 o.write("ID\tRGYW\tWRCY\tWA\tTW\n")
|
|
423 for ID in IDlist:
|
|
424 #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")
|
|
425 o.write(ID + "\t" + str(RGYWCount[ID]) + "\t" + str(WRCYCount[ID]) + "\t" + str(WACount[ID]) + "\t" + str(TWCount[ID]) + "\n")
|
|
426
|
|
427 if __name__ == "__main__":
|
|
428 main()
|