twinfer.plotting.network_plots.network_from_scenarios
- twinfer.plotting.network_plots.network_from_scenarios(result, genes=None, time='tb', weight=None, solid_scenarios=(2, 3), dashed_scenarios=(4,), direction_alpha=0.05, scenario_colors=None, z_dag_threshold=1.96, two_way_scenarios=(2,))[source]
Turn the output of infer_with_twinfer into the inputs of plot_grn.
Edge rules
inference scenario in solid_scenarios (default 2 regulation, 3 regulation + heterogeneity): solid edge.
inference scenario in dashed_scenarios (default 4 heterogeneity, a shared state, not regulation): dashed edge without direction.
any other scenario (1 nothing, or undefined): no edge.
direction of a solid edge (only when the table has several time points), twinfer.inference.ranked_edges.pair_directions, the same rule as the z_dag ranked list:
scenario in two_way_scenarios (default 2, regulation): each direction on its own, |z_dag| > z_dag_threshold (z_dag_xy for gene_x -> gene_y, z_dag_yx for gene_y -> gene_x); both can be drawn (mutual regulation, two curved edges); other solid scenarios (3, regulation + a shared state, which correlates both directions): one direction, the sign of delta = |rho_dag_xy| - |rho_dag_yx|, when p_delta < direction_alpha.
Otherwise the edge is drawn without direction.
edge colour = weight. Default (None): “z_dag” when the table has two time points (the z_dag of the drawn direction; an edge without direction takes the larger of |z_dag_xy| and |z_dag_yx|; a pair without cross-time values, see cross_correlation_pairs of infer_with_twinfer, is coloured by z_rho_Delta), otherwise “z_rho_Delta”. Any other column (without _ta / _tb) is used as is.
activation arrow vs repression bar of a directed edge = the sign of its z_dag (the cross-time correlation in the drawn direction), passed to plot_grn as edge_signs, whatever the colour column.
scenario_colors (optional dict {scenario: colour}, e.g. {3: “tab:blue”, 4: “grey”}): edges of these scenarios are drawn in that colour instead of the colour of their weight.
- param result:
DataFrame returned by infer_with_twinfer, one row per gene pair. With several time points, keep one (t_a, t_b) pair of rows.
- param genes:
Node order (default: genes in order of appearance in result).
- param time:
“ta” or “tb”: which twin group’s scenario and weight to use when the table has several time points (default the later, tb).
- param scenario_colors:
Optional dict {inference scenario: Matplotlib colour}; see the edge rules.
- returns:
plot_kwargs – dict with matrix, node_labels, edge_styles, undirected_edges, edge_signs (and edge_colors when scenario_colors is given): call
plot_grn(**plot_kwargs)(other plot_grn options can be added, e.g.plot_grn(**plot_kwargs, colorbar_label="z_rho")).edges – DataFrame, one row per drawn edge: source, target, weight (the colour value), inference_scenario, line_style, directed, z_dag (of the drawn direction; NaN without cross-time values).