/
exact_daligner_venn.py
79 lines (59 loc) · 2.21 KB
/
exact_daligner_venn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
import matplotlib.pyplot as plt
from matplotlib_venn import venn2
import seaborn
import yaml
from phasm.io import gfa
BASE_DIR = os.path.dirname(__file__)
with open(os.path.join(BASE_DIR, "config.yml")) as f:
config = yaml.load(f)
seaborn.set_style("whitegrid")
c1, c2, c3 = seaborn.color_palette("RdBu_r", n_colors=3)
for assembly, asm_config in config['assemblies'].items():
if assembly.endswith('-lh'):
continue
parts = assembly.split('-')
ploidy = int(parts[0].replace("ploidy", ""))
coverage = int(parts[1].replace("x", ""))
asm_folder = os.path.join(BASE_DIR, "assemblies", assembly)
if coverage != 60:
continue
exact_gfa = os.path.join(asm_folder, "01_overlap", "exact.gfa")
daligner_gfa = os.path.join(asm_folder, "01_overlap", "alignments.gfa")
exact_overlaps = set()
daligner_overlaps = set()
with open(exact_gfa) as f:
edge_lines = (l for l in f if l.startswith('E'))
for line in edge_lines:
sid1, sid2, arange, brange, alignment, tags = gfa.gfa2_parse_edge(
line)
# Remove orientation
read1 = sid1[:-1]
read2 = sid2[:-1]
exact_overlaps.add((read1, read2))
exact_overlaps.add((read2, read1))
daligner_in_count = 0
daligner_out_count = 0
with open(daligner_gfa) as f:
edge_lines = (l for l in f if l.startswith('E'))
for line in edge_lines:
sid1, sid2, arange, brange, alignment, tags = gfa.gfa2_parse_edge(
line)
# Remove orientation
read1 = sid1[:-1]
read2 = sid2[:-1]
daligner_overlaps.add((read1, read2))
daligner_overlaps.add((read2, read1))
plt.figure()
v = venn2(
[exact_overlaps, daligner_overlaps],
set_labels=("Exact overlapper", "DALIGNER")
)
v.get_patch_by_id('10').set_color(c1)
v.get_patch_by_id('01').set_color(c3)
v.get_patch_by_id('11').set_color(c2)
v.get_patch_by_id('10').set_alpha(0.8)
v.get_patch_by_id('01').set_alpha(0.5)
v.get_patch_by_id('11').set_alpha(0.8)
plt.savefig(os.path.join(
BASE_DIR, 'figures', 'exact-vs-daligner-p{}.png'.format(ploidy)))