Skip to content

Commit 86ed7d3

Browse files
committed
speed up writing hdf5 by a huge factor
1 parent 9b41a80 commit 86ed7d3

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

edgehog/hdf5.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
sys.exit(2)
1717

1818

19+
def fast_max_except_minus1(x):
20+
arr = x.values
21+
mask = arr != -1
22+
return arr[mask].max() if mask.any() else -1
23+
1924
class HDF5Writer:
2025
def __init__(self, fname, oma_db_fn, date_edges=False, orient_edges=False):
2126
self.fname = fname
@@ -95,8 +100,8 @@ def add_graph_at_level(self, taxid, tree_node):
95100
"Weight": "max",
96101
"Evidence": "min",
97102
# -1 indicates 'n/a', all other values should be consistent.
98-
"LCA_taxid": lambda x: x[x != -1].max() if not x[x != -1].empty else -1,
99-
"Orientation": lambda x: x[x != -1].max() if not x[x != -1].empty else -1,
103+
"LCA_taxid": fast_max_except_minus1,
104+
"Orientation": fast_max_except_minus1,
100105
"OrientationScore": "max",
101106

102107
})
@@ -167,8 +172,8 @@ def add_extant_graph(self, taxid, tree_node):
167172
"Weight": "max",
168173
"Evidence": "min",
169174
# -1 indicates 'n/a', all other values should be consistent.
170-
"LCA_taxid": lambda x: x[x != -1].max() if not x[x != -1].empty else -1,
171-
"Orientation": lambda x: x[x != -1].max() if not x[x != -1].empty else -1,
175+
"LCA_taxid": fast_max_except_minus1,
176+
"Orientation": fast_max_except_minus1,
172177
"OrientationScore": "max",
173178
})
174179
as_array = sumdf.astype({col: dtype.fields[col][0] for col in dtype.names}).to_records(index=False)

edgehog/infer_ancestral_synteny_graphs.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ def build_transitive_graph(graph, orient_edges, max_gap_length = 2):
138138
children = list(set(graph[left_gene][gene]["children"] + graph[gene][right_gene]["children"])),
139139
extant_descendants = list(set(graph[left_gene][gene]["extant_descendants"] + graph[gene][right_gene]["extant_descendants"])))
140140
if orient_edges:
141-
try:
142-
print(left_gene.hog_id, right_gene.hog_id)
143-
except:
144-
print(left_gene.prot_id, right_gene.prot_id)
145141
wA, uA, cA, dA = graph[left_gene][gene]["weight"], graph[left_gene][gene]["unidirectional"], graph[left_gene][gene]["convergent"], graph[left_gene][gene]["divergent"]
146142
wB, uB, cB, dB = graph[gene][right_gene]["weight"], graph[gene][right_gene]["unidirectional"], graph[gene][right_gene]["convergent"], graph[gene][right_gene]["divergent"]
147143
u, c, d = orient_reconnected_edges(wA, uA, cA, dA, wB, uB, cB, dB)

0 commit comments

Comments
 (0)