comparison read2mut.py @ 86:97bd9c7a1b44 draft

planemo upload for repository https://github.com/Single-Molecule-Genetics/VariantAnalyzerGalaxy/tree/master/tools/variant_analyzer commit ee4a8e6cf290e6c8a4d55f9cd2839d60ab3b11c8-dirty
author mheinzl
date Sat, 22 Apr 2023 09:28:36 +0000
parents d1cd4cd9f18d
children 49b4a9ca7400
comparison
equal deleted inserted replaced
85:d1cd4cd9f18d 86:97bd9c7a1b44
375 375
376 # output summary with threshold 376 # output summary with threshold
377 workbook = xlsxwriter.Workbook(outfile) 377 workbook = xlsxwriter.Workbook(outfile)
378 workbook2 = xlsxwriter.Workbook(outfile2) 378 workbook2 = xlsxwriter.Workbook(outfile2)
379 workbook3 = xlsxwriter.Workbook(outfile3) 379 workbook3 = xlsxwriter.Workbook(outfile3)
380 ws1 = workbook.add_worksheet("Results") 380 count_sheet = 1
381 ws1 = workbook.add_worksheet("Results" + str(count_sheet))
381 ws2 = workbook2.add_worksheet("Allele frequencies") 382 ws2 = workbook2.add_worksheet("Allele frequencies")
382 ws3 = workbook3.add_worksheet("Tiers") 383 ws3 = workbook3.add_worksheet("Tiers")
384 current_result_sheet = ws1
385
383 386
384 format1 = workbook.add_format({'bg_color': '#BCF5A9'}) # green 387 format1 = workbook.add_format({'bg_color': '#BCF5A9'}) # green
385 format2 = workbook.add_format({'bg_color': '#FFC7CE'}) # red 388 format2 = workbook.add_format({'bg_color': '#FFC7CE'}) # red
386 format3 = workbook.add_format({'bg_color': '#FACC2E'}) # yellow 389 format3 = workbook.add_format({'bg_color': '#FACC2E'}) # yellow
387 390
688 # elif variant_type == "ref": 691 # elif variant_type == "ref":
689 # used_keys_ref.append(key2[:-5]) 692 # used_keys_ref.append(key2[:-5])
690 counts_mut += 1 693 counts_mut += 1
691 694
692 if (variant_type == "alt" and ((alt1f + alt2f + alt3f + alt4f) > 0.5)) or (variant_type == "ref" and ((ref1f + ref2f + ref3f + ref4f) > 0.5)): 695 if (variant_type == "alt" and ((alt1f + alt2f + alt3f + alt4f) > 0.5)) or (variant_type == "ref" and ((ref1f + ref2f + ref3f + ref4f) > 0.5)):
696 if row > 1000000:
697 count_sheet += 1
698 ws_new = workbook.add_worksheet("Results" + str(count_sheet))
699 current_result_sheet = ws_new
700
693 if variant_type == "alt": 701 if variant_type == "alt":
694 tier1ff, tier2ff, tier3ff, tier4ff = alt1f, alt2f, alt3f, alt4f 702 tier1ff, tier2ff, tier3ff, tier4ff = alt1f, alt2f, alt3f, alt4f
695 tier1ff_trim, tier2ff_trim, tier3ff_trim, tier4ff_trim = alt1f, alt2f, alt3f, alt4f 703 tier1ff_trim, tier2ff_trim, tier3ff_trim, tier4ff_trim = alt1f, alt2f, alt3f, alt4f
696 elif variant_type == "ref": 704 elif variant_type == "ref":
697 tier1ff, tier2ff, tier3ff, tier4ff = ref1f, ref2f, ref3f, ref4f 705 tier1ff, tier2ff, tier3ff, tier4ff = ref1f, ref2f, ref3f, ref4f
1336 if (read_pos3 == -1): 1344 if (read_pos3 == -1):
1337 read_pos3 = read_len_median3 = None 1345 read_pos3 = read_len_median3 = None
1338 line = (var_id, tier, variant_type, key2[:-5], 'ab1.ba2', read_pos1, read_pos4, read_len_median1, read_len_median4, dcs_median) + details1 + (sscs_mut_ab, sscs_mut_ba, sscs_ref_ab, sscs_ref_ba, add_mut14, chimera) 1346 line = (var_id, tier, variant_type, key2[:-5], 'ab1.ba2', read_pos1, read_pos4, read_len_median1, read_len_median4, dcs_median) + details1 + (sscs_mut_ab, sscs_mut_ba, sscs_ref_ab, sscs_ref_ba, add_mut14, chimera)
1339 line2 = ("", "", "", key2[:-5], 'ab2.ba1', read_pos2, read_pos3, read_len_median2, read_len_median3, dcs_median) + details2 + (sscs_mut_ab, sscs_mut_ba, sscs_ref_ab, sscs_ref_ba, add_mut23, chimera) 1347 line2 = ("", "", "", key2[:-5], 'ab2.ba1', read_pos2, read_pos3, read_len_median2, read_len_median3, dcs_median) + details2 + (sscs_mut_ab, sscs_mut_ba, sscs_ref_ab, sscs_ref_ba, add_mut23, chimera)
1340 if tier != "4": 1348 if tier != "4":
1341 ws1.write_row(row, 0, line) 1349 current_result_sheet.write_row(row, 0, line)
1342 csv_writer.writerow(line) 1350 csv_writer.writerow(line)
1343 ws1.write_row(row + 1, 0, line2) 1351 current_result_sheet.write_row(row + 1, 0, line2)
1344 csv_writer.writerow(line2) 1352 csv_writer.writerow(line2)
1345 if variant_type == "alt": 1353 if variant_type == "alt":
1346 ws1.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="1.1", $B${}="1.2")'.format(row + 1, row + 1), 'format': format1, 'multi_range': 'M{}:N{} U{}:V{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)}) 1354 current_result_sheet.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="1.1", $B${}="1.2")'.format(row + 1, row + 1), 'format': format1, 'multi_range': 'M{}:N{} U{}:V{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)})
1347 ws1.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="2.1", $B${}="2.2", $B${}="2.3", $B${}="2.4", $B${}="2.5")'.format(row + 1, row + 1, row + 1, row + 1, row + 1), 'format': format3, 'multi_range': 'M{}:N{} U{}:V{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)}) 1355 current_result_sheet.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="2.1", $B${}="2.2", $B${}="2.3", $B${}="2.4", $B${}="2.5")'.format(row + 1, row + 1, row + 1, row + 1, row + 1), 'format': format3, 'multi_range': 'M{}:N{} U{}:V{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)})
1348 ws1.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=$B${}>="3"'.format(row + 1), 'format': format2, 'multi_range': 'M{}:N{} U{}:V{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)}) 1356 current_result_sheet.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=$B${}>="3"'.format(row + 1), 'format': format2, 'multi_range': 'M{}:N{} U{}:V{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)})
1349 elif variant_type == "ref": 1357 elif variant_type == "ref":
1350 ws1.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="1.1", $B${}="1.2")'.format(row + 1, row + 1), 'format': format1, 'multi_range': 'M{}:N{} S{}:T{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)}) 1358 current_result_sheet.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="1.1", $B${}="1.2")'.format(row + 1, row + 1), 'format': format1, 'multi_range': 'M{}:N{} S{}:T{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)})
1351 ws1.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="2.1", $B${}="2.2", $B${}="2.3", $B${}="2.4", $B${}="2.5")'.format(row + 1, row + 1, row + 1, row + 1, row + 1), 'format': format3, 'multi_range': 'M{}:N{} S{}:T{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)}) 1359 current_result_sheet.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="2.1", $B${}="2.2", $B${}="2.3", $B${}="2.4", $B${}="2.5")'.format(row + 1, row + 1, row + 1, row + 1, row + 1), 'format': format3, 'multi_range': 'M{}:N{} S{}:T{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)})
1352 ws1.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=$B${}>="3"'.format(row + 1), 'format': format2, 'multi_range': 'M{}:N{} S{}:T{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)}) 1360 current_result_sheet.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=$B${}>="3"'.format(row + 1), 'format': format2, 'multi_range': 'M{}:N{} S{}:T{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)})
1353 row += 3 1361 row += 3
1354 else: 1362 else:
1355 change_tier_after_print.append((line, line2, trimmed_actual_high_tier)) 1363 change_tier_after_print.append((line, line2, trimmed_actual_high_tier))
1356 1364
1357 if chimera_correction: 1365 if chimera_correction:
1403 line1 = tuple(line1) 1411 line1 = tuple(line1)
1404 counter_tier25 += 1 1412 counter_tier25 += 1
1405 counter_tier4 -= 1 1413 counter_tier4 -= 1
1406 tier_dict_ref[key1]["tier 2.5"] += 1 1414 tier_dict_ref[key1]["tier 2.5"] += 1
1407 tier_dict_ref[key1]["tier 4"] -= 1 1415 tier_dict_ref[key1]["tier 4"] -= 1
1408 ws1.write_row(row, 0, line1) 1416 current_result_sheet.write_row(row, 0, line1)
1409 csv_writer.writerow(line1) 1417 csv_writer.writerow(line1)
1410 ws1.write_row(row + 1, 0, line2) 1418 current_result_sheet.write_row(row + 1, 0, line2)
1411 csv_writer.writerow(line2) 1419 csv_writer.writerow(line2)
1412 if line1[2] == "alt": 1420 if line1[2] == "alt":
1413 ws1.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="1.1", $B${}="1.2")'.format(row + 1, row + 1), 'format': format1, 'multi_range': 'M{}:N{} U{}:V{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)}) 1421 current_result_sheet.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="1.1", $B${}="1.2")'.format(row + 1, row + 1), 'format': format1, 'multi_range': 'M{}:N{} U{}:V{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)})
1414 ws1.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="2.1", $B${}="2.2", $B${}="2.3", $B${}="2.4", $B${}="2.5")'.format(row + 1, row + 1, row + 1, row + 1, row + 1), 'format': format3, 'multi_range': 'M{}:N{} U{}:V{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)}) 1422 current_result_sheet.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="2.1", $B${}="2.2", $B${}="2.3", $B${}="2.4", $B${}="2.5")'.format(row + 1, row + 1, row + 1, row + 1, row + 1), 'format': format3, 'multi_range': 'M{}:N{} U{}:V{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)})
1415 ws1.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=$B${}>="3"'.format(row + 1), 'format': format2, 'multi_range': 'M{}:N{} U{}:V{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)}) 1423 current_result_sheet.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=$B${}>="3"'.format(row + 1), 'format': format2, 'multi_range': 'M{}:N{} U{}:V{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)})
1416 elif line1[2] == "ref": 1424 elif line1[2] == "ref":
1417 ws1.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="1.1", $B${}="1.2")'.format(row + 1, row + 1), 'format': format1, 'multi_range': 'M{}:N{} S{}:T{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)}) 1425 current_result_sheet.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="1.1", $B${}="1.2")'.format(row + 1, row + 1), 'format': format1, 'multi_range': 'M{}:N{} S{}:T{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)})
1418 ws1.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="2.1", $B${}="2.2", $B${}="2.3", $B${}="2.4", $B${}="2.5")'.format(row + 1, row + 1, row + 1, row + 1, row + 1), 'format': format3, 'multi_range': 'M{}:N{} S{}:T{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)}) 1426 current_result_sheet.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=OR($B${}="2.1", $B${}="2.2", $B${}="2.3", $B${}="2.4", $B${}="2.5")'.format(row + 1, row + 1, row + 1, row + 1, row + 1), 'format': format3, 'multi_range': 'M{}:N{} S{}:T{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)})
1419 ws1.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=$B${}>="3"'.format(row + 1), 'format': format2, 'multi_range': 'M{}:N{} S{}:T{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)}) 1427 current_result_sheet.conditional_format('M{}:N{}'.format(row + 1, row + 2), {'type': 'formula', 'criteria': '=$B${}>="3"'.format(row + 1), 'format': format2, 'multi_range': 'M{}:N{} S{}:T{} B{}'.format(row + 1, row + 2, row + 1, row + 2, row + 1, row + 2)})
1420 row += 3 1428 row += 3
1421 1429
1422 # sheet 2 1430 # sheet 2
1423 if refalttiers: 1431 if refalttiers:
1424 if chimera_correction: 1432 if chimera_correction: