Skip to content

Commit 601389b

Browse files
committed
Test for saving edges in compact ("split") format
An example of how you might address #187
1 parent 658e60d commit 601389b

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

tskit_arg_visualizer/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,18 @@ def from_json(cls, json):
301301
nodes = pd.DataFrame(json["data"]["nodes"])
302302
nodes["x_pos_01"] = (nodes["x"] - x_shift) / (width-100)
303303
if json["plot_type"] == "full":
304-
samples = nodes.loc[bool(nodes["ts_flags"] & tskit.NODE_IS_SAMPLE),["id", "fx"]]
304+
samples = nodes.loc[(nodes["ts_flags"] & tskit.NODE_IS_SAMPLE) != 0,["id", "fx"]]
305305
num_samples = samples.shape[0]
306306
sample_order = [sample for _, sample in sorted(zip(samples["fx"], samples["id"]))]
307307
else:
308308
num_samples = -1
309309
sample_order = []
310310
return cls(
311311
nodes=nodes,
312-
edges=pd.DataFrame(json["data"]["links"]),
312+
edges=pd.DataFrame(
313+
json["data"]["links"]["data"],
314+
columns=json["data"]["links"]["columns"],
315+
),
313316
mutations=pd.DataFrame(json["data"]["mutations"]),
314317
breakpoints=pd.DataFrame(json["data"]["breakpoints"]),
315318
num_samples=num_samples,
@@ -1065,7 +1068,6 @@ def _prepare_json(
10651068
transformed_bps["x_pos"] = transformed_bps["x_pos_01"] * width + y_axis_left_spacing
10661069
transformed_bps["width"] = transformed_bps["width_01"] * width
10671070
transformed_bps["included"] = "true"
1068-
transformed_bps = transformed_bps.to_dict("records")
10691071

10701072
if shift_for_y_axis:
10711073
width += 50
@@ -1078,9 +1080,9 @@ def _prepare_json(
10781080
arg = {
10791081
"data":{
10801082
"nodes":transformed_nodes,
1081-
"links":edges.to_dict("records"),
1083+
"links":edges.to_dict("split"),
10821084
"mutations":transformed_muts,
1083-
"breakpoints":transformed_bps,
1085+
"breakpoints":transformed_bps.to_dict("records"),
10841086
"evenly_distributed_positions":sample_positions,
10851087
},
10861088
"width":width,

tskit_arg_visualizer/visualizer.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ function main_visualizer(
104104
var stepAfter = d3.line().curve(d3.curveStepAfter);
105105
var stepBefore = d3.line().curve(d3.curveStepBefore);
106106

107+
var links = graph.links.data.map(array => {
108+
let obj = {}; // New object will have column names as keys
109+
graph.links.columns.forEach((colName, index) => {obj[colName] = array[index];});
110+
return obj;
111+
});
107112

108113
// https://gist.github.com/Rokotyan/0556f8facbaf344507cdc45dc3622177
109114
// Below are the functions that handle actual exporting:
@@ -347,7 +352,7 @@ function main_visualizer(
347352
.forceSimulation(graph.nodes)
348353
.force("link", d3.forceLink()
349354
.id(d => d.id)
350-
.links(graph.links)
355+
.links(links)
351356
)
352357
//.force("center", d3.forceCenter(275,250).strength(-10))
353358
.force("charge", d3.forceManyBody().strength(-100))
@@ -357,11 +362,10 @@ function main_visualizer(
357362
.append("g")
358363
.attr("class", "links")
359364
.selectAll("path")
360-
.data(graph.links)
365+
.data(links)
361366
.enter()
362367
.append("g")
363-
.attr("bounds", d => d.bounds);
364-
368+
.attr("bounds", d => d.bounds)
365369
if ((edge_styles.type == "ortho") & eval(edge_styles.include_underlink)) {
366370
var underlink = link_container
367371
.append("path")

0 commit comments

Comments
 (0)