comparison shm_csr.py @ 7:ad9be244b104 draft

Uploaded
author davidvanzessen
date Mon, 07 Nov 2016 03:04:07 -0500
parents 275ab5175fd6
children 4e596473c25c
comparison
equal deleted inserted replaced
6:2ddb9a21f635 7:ad9be244b104
245 with open(directory + "all_" + fname + "_value.txt", 'r') as v: 245 with open(directory + "all_" + fname + "_value.txt", 'r') as v:
246 valuedic["total_" + fname] = float(v.readlines()[0].rstrip()) 246 valuedic["total_" + fname] = float(v.readlines()[0].rstrip())
247 247
248 248
249 def get_xyz(lst, gene, f, fname): 249 def get_xyz(lst, gene, f, fname):
250
250 x = int(round(f(lst))) 251 x = int(round(f(lst)))
251 y = valuedic[gene + "_" + fname] 252 y = valuedic[gene + "_" + fname]
252 z = str(round(x / float(y) * 100, 1)) if y != 0 else "0" 253 z = str(round(x / float(y) * 100, 1)) if y != 0 else "0"
254 if gene == "unmatched":
255 print x, y, z
253 return (str(x), str(y), z) 256 return (str(x), str(y), z)
254 257
255 dic = {"RGYW": RGYWCount, "WRCY": WRCYCount, "WA": WACount, "TW": TWCount} 258 dic = {"RGYW": RGYWCount, "WRCY": WRCYCount, "WA": WACount, "TW": TWCount}
256 arr = ["RGYW", "WRCY", "WA", "TW"] 259 arr = ["RGYW", "WRCY", "WA", "TW"]
257 260
269 if valuedic[gene + "_" + fname] is 0: 272 if valuedic[gene + "_" + fname] is 0:
270 o.write(",0,0,0") 273 o.write(",0,0,0")
271 else: 274 else:
272 x, y, z = get_xyz([curr[x] for x in [y for y, z in genedic.iteritems() if geneMatcher.match(z)]], gene, func, fname) 275 x, y, z = get_xyz([curr[x] for x in [y for y, z in genedic.iteritems() if geneMatcher.match(z)]], gene, func, fname)
273 o.write("," + x + "," + y + "," + z) 276 o.write("," + x + "," + y + "," + z)
274
275 x, y, z = get_xyz([y for x, y in curr.iteritems() if not genedic[x].startswith("unmatched")], "total", func, fname) 277 x, y, z = get_xyz([y for x, y in curr.iteritems() if not genedic[x].startswith("unmatched")], "total", func, fname)
278 #x, y, z = get_xyz([y for x, y in curr.iteritems()], "total", func, fname)
276 o.write("," + x + "," + y + "," + z + "\n") 279 o.write("," + x + "," + y + "," + z + "\n")
277 280
278 281
279 # for testing 282 # for testing
280 seq_motif_file = outfile[:outfile.rindex("/")] + "/motif_per_seq.txt" 283 seq_motif_file = outfile[:outfile.rindex("/")] + "/motif_per_seq.txt"