wepy.analysis.contig_tree module

Classes providing a contig and branching contigs abstractions over the underlying WepyHDF5 simulation data store.

Routines

ContigTree Contig

wepy.analysis.contig_tree.RESAMPLING = 'resampling'

Record key for resampling records.

wepy.analysis.contig_tree.RESAMPLER = 'resampler'

Record key for resampler records.

wepy.analysis.contig_tree.WARPING = 'warping'

Record key for warping records.

wepy.analysis.contig_tree.PROGRESS = 'progress'

Record key for progress records.

wepy.analysis.contig_tree.BC = 'boundary_conditions'

Record key for boundary condition records.

class wepy.analysis.contig_tree.BaseContigTree(wepy_h5, continuations=Ellipsis, runs=Ellipsis, boundary_condition_class=None, decision_class=None)[source]

Bases: object

A base class for the contigtree which doesn’t contain a WepyHDF5 object. Useful for serialization of the object and can then be reattached later to a WepyHDF5.

The only required argument is an WepyHDF5 object from which to draw data.

If continuations is given it specifies the (continuing_run_idx, continued_run_idx) continuations the contig tree will use. This overrides anything in the WepyHDF5 file. Only use this if you know what you are doing. If continuations is Ellipsis the continuations from the WepyHDF5 will be used.

If runs is not Ellipsis only these runs will be included in the ContigTree and the continuations relvant to this subset will be used.

If a valid decision_class is given walker lineages will be generated. This class is largely useless without this.

The boundary_condition_class is only used in the presence of a decision_class. A valid boundary_condition_class will detect the discontinuities in walker trajectories and will automatically apply them to divide up logical trajectories. Otherwise, if discontinuous boundary condition warping events in data are present logical trajectories will have discontinuities in them.

Parameters
  • wepy_h5 (closed WepyHDF5 object) –

  • continuations (Ellipsis (use continuations in wepy_h5) or) –

    list of tuple of int (run_idx, run_idx)

    The continuations to apply to the runs in this contig tree.

    (Default value = Ellipsis)

  • runs (Ellipsis (use all runs in wepy_h5) or) –

    list of idx

    The indices of the runs to use in the contig tree

    (Default value = Ellipsis)

  • boundary_condition_class (class implementing BoundaryCondition) – interface (Default value = None)

decision_classclass implementing Decision interface

(Default value = None)

Warning

Only set continuations if you know what you are doing.

A decision_class must be given to be able to detect cloning and merging and get parental lineages.

Make sure to give the boundary_condition_class if there was discontinuous warping events in the simulation or else you will get erroneous contiguous trajectories.

RESAMPLING_PANEL_KEY = 'resampling_steps'

Key for resampling panel node attributes in the tree graph.

PARENTS_KEY = 'parent_idxs'

Key for parent indices node attributes in the tree graph.

DISCONTINUITY_KEY = 'discontinuities'

Key for discontinuity node attributes in the tree graph.

property graph

The underlying networkx.DiGraph object.

property decision_class

The decision class used to determine parental lineages.

property boundary_condition_class

The boundary condition class is used to determine discontinuities in lineages.

property span_traces

Dictionary mapping the spand indices to their run traces.

span_contig(span_idx)[source]

Generates a contig object for the specified spanning contig.

_create_tree(wepy_h5)[source]

Generate the tree of cycles from the WepyHDF5 object/file.

_set_resampling_panels(wepy_h5)[source]

Generates resampling panels for each cycle and sets them as node attributes.

_initialize_discontinuities(wepy_h5)[source]

Initialize the nodes with discontinuities attributes but set to 0s indicating no discontinuities.

_set_discontinuities(wepy_h5, boundary_conditions_class)[source]

Given the boundary condition class sets node attributes for where there are discontinuities in the parental lineages.

Parameters

boundary_conditions_class (class implementing BoundaryCondition interface) –

_set_parents(decision_class)[source]

Determines the net parents for each cycle and sets them in-place to the cycle tree given.

Parameters

decision_class (class implementing Decision interface) –

property run_idxs

Indices of runs in WepyHDF5 used in this contig tree.

property continuations

The continuations that are used in this contig tree over the runs.

static contig_trace_to_run_trace(contig_trace, contig_walker_trace)[source]

Combine a contig trace and a walker trace to get the equivalent run trace.

The contig_walker_trace cycle_idxs must be a subset of the frame indices given by the contig_trace.

Parameters
  • contig_trace (list of tuples of ints (run_idx, cycle_idx)) –

  • contig_walker_trace (list of tuples of ints (traj_idx, cycle_idx)) –

Returns

run_trace

Return type

list of tuples of ints (run_idx, traj_idx, cycle_idx)

walker_trace_to_run_trace(contig_walker_trace)[source]

Combine a walker trace to get the equivalent run trace for this contig.

The contig_walker_trace cycle_idxs must be a subset of the frame indices given by the contig_trace.

Parameters

contig_walker_trace (list of tuples of ints (traj_idx, cycle_idx)) –

Returns

run_trace

Return type

list of tuples of ints (run_idx, traj_idx, cycle_idx)

See also

Contig.contig_trace_to_run_trace

calls this static method

run_trace_to_contig_trace(run_trace)[source]

Assumes that the run trace goes along a valid contig.

Parameters

run_trace (list of tuples of ints (run_idx, traj_idx, cycle_idx)) –

Returns

contig_walker_trace

Return type

list of tuples of ints (traj_idx, contig_cycle_idx)

contig_cycle_idx(run_idx, cycle_idx)[source]

Convert an in-run cycle index to an in-contig cyle_idx.

Parameters
  • run_idx (int) – Index of a run in the contig tree

  • cycle_idx (int) – Index of a cycle index within a run

Returns

contig_cycle_idx – The cycle idx in the contig

Return type

int

get_branch_trace(run_idx, cycle_idx, start_contig_idx=0)[source]

Get a contig trace for a branch of the contig tree from an end point back to a set point (defaults to root of contig tree).

Parameters
  • run_idx (int) –

  • cycle_idx (int) – An in-contig cycle index

  • start_contig_idx (int, optional) –

    The in-contig cycle index where the “root” of the branch will start

    (Default value = 0)

Returns

contig_trace

Return type

list of tuples of ints (run_idx, cycle_idx)

trace_parent_table(contig_trace, discontinuities=True)[source]

Given a contig trace returns a parent table for that contig.

Parameters
  • contig_trace (list of tuples (run_idx, cycle_idx)) –

  • discontinuities (bool) – Whether or not to include discontinuities in the table.

Returns

parent_table

Return type

list of list of int

classmethod _tree_leaves(root, tree)[source]

Given the root node ID and the tree as a networkX DiGraph returns the leaves of the tree.

Must give it the reversed tree because it is recursive.

Parameters
  • root (node_id) –

  • tree (networkx.DiGraph) – The reversed tree from the contigtree

Returns

leaves – The leaf node IDs of the tree.

Return type

list of node_id

_subtree_leaves(root)[source]

Given a root defining a subtree on the full tree returns the leaves of that subtree.

Parameters

root (node_id) –

Returns

leaves – The leaf node IDs of the tree.

Return type

list of node_id

leaves()[source]

All of the leaves of this contig tree.

Returns

leaves – The leaf node IDs of the tree.

Return type

list of node_id

root_leaves()[source]

Return a dictionary mapping the roots to their leaves.

_subtree_root(node)[source]

Given a node find the root of the tree it is on

Parameters

node (node_id) –

Returns

root

Return type

node_id

roots()[source]

Returns all of the roots in this contig tree (which is technically a forest and can have multiple roots).

Returns

root

Return type

list of node_id

subtrees()[source]

Returns all of the subtrees (with unique roots) in this contig tree (which is technically a forest and can have multiple roots).

Returns

subtrees

Return type

list of networkx.DiGraph trees

get_subtree(node)[source]

Given a node defining a subtree root return that subtree.

Parameters

node (node_id) –

Returns

subtree

Return type

networkx.DiGraph tree

contig_sliding_windows(contig_trace, window_length)[source]

Given a contig trace get the sliding windows of length ‘window_length’ as contig walker traces.

Parameters
  • contig_trace (list of tuples of ints (run_idx, cycle_idx)) – Trace defining a contig in the contig tree.

  • window_length (int) – The length of the sliding windows to return.

Returns

windows – List of contig walker traces

Return type

list of list of tuples of ints (traj_idx, cycle_idx)

sliding_contig_windows(window_length)[source]

Given a ‘window_length’ return all the windows over the contig tree as contig traces.

Parameters

window_length (int) –

Returns

contig_windows – List of contig traces

Return type

list of list of tuples of ints (run_idx, cycle_idx)

_subtree_sliding_contig_windows(subtree_root, window_length)[source]

Get all the sliding windows of length ‘window_length’ from the subtree defined by the subtree root as run traces.

Parameters
  • subtree_root (node_id) –

  • window_length (int) –

Returns

subtree_windows – List of the contig tree windows as contig traces

Return type

list of list of tuples of ints (run_idx, cycle_idx)

sliding_windows(window_length)[source]

Returns all the sliding windows over walker trajectories as run traces for a given window length.

Parameters

window_length (int) –

Returns

windows – List of run traces.

Return type

list of list of tuples of ints (run_idx, traj_idx, cycle_idx)

classmethod _rec_spanning_paths(edges, root)[source]

Given a set of directed edges (source, target) and a root node id of a tree imposed over the edges, returns all the paths over that tree which span from the root to a leaf.

This is a recursive function and has pretty bad performance for nontrivial simulations.

Parameters
  • edges ((node_id, node_id)) –

  • root (node_id) –

Returns

spanning_paths

Return type

list of edges

_spanning_paths(root)[source]
Parameters

root (node_id) –

Returns

spanning_paths

Return type

list of list of edges

spanning_contig_traces()[source]

Returns a list of all possible spanning contigs given the continuations present in this file. Spanning contigs are paths through a tree that must start from a root node and end at a leaf node.

This algorithm always returns them in a canonical order (as long as the runs are not rearranged after being added). This means that the indices here are the indices of the contigs.

Returns

spanning_contig_traces – List of all spanning contigs which are contig traces.

Return type

list of list of tuples of ints (run_idx, cycle_idx)

_root_spanning_contig_traces()[source]

Returns a list of all possible spanning contigs given the continuations present in this file. Spanning contigs are paths through a tree that must start from a root node and end at a leaf node.

This algorithm always returns them in a canonical order (as long as the runs are not rearranged after being added). This means that the indices here are the indices of the contigs.

Returns

spanning_contig_traces – Dictionary mapping the root ids to all spanning contigs for it which are contig traces.

Return type

dict of root_id to list of tuples of ints (run_idx, cycle_idx)

classmethod _contig_trace_to_contig_runs(contig_trace)[source]

Convert a contig trace to a list of runs.

Parameters

contig_trace (list of tuples of ints (run_idx, cycle_idx)) –

Returns

contig_runs

Return type

list of int

classmethod _contig_runs_to_continuations(contig_runs)[source]

Helper function to convert a list of run indices defining a contig to continuations.

Parameters

contig_runs (list of int) –

Returns

continuations

Return type

list of tuple of int (run_idx, run_idx)

classmethod _continuations_to_contig_runs(continuations)[source]

Helper function that converts a list of continuations to a list of the runs in the order of the contigs defined by the continuations.

Parameters

continuations (list of tuple of int (run_idx, run_idx)) –

Returns

contig_runs

Return type

list of int

class wepy.analysis.contig_tree.ContigTree(wepy_h5, base_contigtree=None, continuations=Ellipsis, runs=Ellipsis, boundary_condition_class=None, decision_class=None)[source]

Bases: wepy.analysis.contig_tree.BaseContigTree

Wraps a WepyHDF5 object and gives access to logical trajectories.

The contig tree is technically a forest (a collection of trees) and can have multiple roots.

The only required argument is an WepyHDF5 object from which to draw data.

If continuations is given it specifies the (continuing_run_idx, continued_run_idx) continuations the contig tree will use. This overrides anything in the WepyHDF5 file. Only use this if you know what you are doing. If continuations is Ellipsis the continuations from the WepyHDF5 will be used.

If runs is not Ellipsis only these runs will be included in the ContigTree and the continuations relvant to this subset will be used.

If a valid decision_class is given walker lineages will be generated. This class is largely useless without this.

The boundary_condition_class is only used in the presence of a decision_class. A valid boundary_condition_class will detect the discontinuities in walker trajectories and will automatically apply them to divide up logical trajectories. Otherwise, if discontinuous boundary condition warping events in data are present logical trajectories will have discontinuities in them.

Parameters
  • wepy_h5 (closed WepyHDF5 object) –

  • continuations (Ellipsis (use continuations in wepy_h5) or) –

    list of tuple of int (run_idx, run_idx)

    The continuations to apply to the runs in this contig tree.

    (Default value = Ellipsis)

  • runs (Ellipsis (use all runs in wepy_h5) or) –

    list of idx

    The indices of the runs to use in the contig tree

    (Default value = Ellipsis)

  • boundary_condition_class (class implementing BoundaryCondition) – interface (Default value = None)

decision_classclass implementing Decision interface

(Default value = None)

Warning

Only set continuations if you know what you are doing.

A decision_class must be given to be able to detect cloning and merging and get parental lineages.

Make sure to give the boundary_condition_class if there was discontinuous warping events in the simulation or else you will get erroneous contiguous trajectories.

_set_base_contigtree_to_self(base_contigtree)[source]
open(mode=None)[source]
close()[source]
property base_contigtree
property wepy_h5

The WepyHDF5 source object for which the contig tree is being constructed.

make_contig(contig_trace)[source]

Create a Contig object given a contig trace.

Parameters

contig_trace (list of tuples of ints (run_idx, cycle_idx)) –

Returns

contig

Return type

Contig object

warp_trace()[source]

Get the trace for all unique warping events from all contigs.

resampling_trace(decision_id)[source]

Return full run traces for every specified type of resampling event.

Parameters

decision_id (int) – The string ID of the decision you want to match on and get lineages for.

final_trace()[source]

Return a trace of all the walkers at the end of the contig.

lineages(trace, discontinuities=True)[source]

Get the ancestry lineage for each element of the trace as a run trace.

DISCONTINUITY_KEY = 'discontinuities'

Key for discontinuity node attributes in the tree graph.

PARENTS_KEY = 'parent_idxs'

Key for parent indices node attributes in the tree graph.

RESAMPLING_PANEL_KEY = 'resampling_steps'

Key for resampling panel node attributes in the tree graph.

classmethod _contig_runs_to_continuations(contig_runs)

Helper function to convert a list of run indices defining a contig to continuations.

Parameters

contig_runs (list of int) –

Returns

continuations

Return type

list of tuple of int (run_idx, run_idx)

classmethod _contig_trace_to_contig_runs(contig_trace)

Convert a contig trace to a list of runs.

Parameters

contig_trace (list of tuples of ints (run_idx, cycle_idx)) –

Returns

contig_runs

Return type

list of int

classmethod _continuations_to_contig_runs(continuations)

Helper function that converts a list of continuations to a list of the runs in the order of the contigs defined by the continuations.

Parameters

continuations (list of tuple of int (run_idx, run_idx)) –

Returns

contig_runs

Return type

list of int

_create_tree(wepy_h5)

Generate the tree of cycles from the WepyHDF5 object/file.

_initialize_discontinuities(wepy_h5)

Initialize the nodes with discontinuities attributes but set to 0s indicating no discontinuities.

classmethod _rec_spanning_paths(edges, root)

Given a set of directed edges (source, target) and a root node id of a tree imposed over the edges, returns all the paths over that tree which span from the root to a leaf.

This is a recursive function and has pretty bad performance for nontrivial simulations.

Parameters
  • edges ((node_id, node_id)) –

  • root (node_id) –

Returns

spanning_paths

Return type

list of edges

_root_spanning_contig_traces()

Returns a list of all possible spanning contigs given the continuations present in this file. Spanning contigs are paths through a tree that must start from a root node and end at a leaf node.

This algorithm always returns them in a canonical order (as long as the runs are not rearranged after being added). This means that the indices here are the indices of the contigs.

Returns

spanning_contig_traces – Dictionary mapping the root ids to all spanning contigs for it which are contig traces.

Return type

dict of root_id to list of tuples of ints (run_idx, cycle_idx)

_set_discontinuities(wepy_h5, boundary_conditions_class)

Given the boundary condition class sets node attributes for where there are discontinuities in the parental lineages.

Parameters

boundary_conditions_class (class implementing BoundaryCondition interface) –

_set_parents(decision_class)

Determines the net parents for each cycle and sets them in-place to the cycle tree given.

Parameters

decision_class (class implementing Decision interface) –

_set_resampling_panels(wepy_h5)

Generates resampling panels for each cycle and sets them as node attributes.

_spanning_paths(root)
Parameters

root (node_id) –

Returns

spanning_paths

Return type

list of list of edges

_subtree_leaves(root)

Given a root defining a subtree on the full tree returns the leaves of that subtree.

Parameters

root (node_id) –

Returns

leaves – The leaf node IDs of the tree.

Return type

list of node_id

_subtree_root(node)

Given a node find the root of the tree it is on

Parameters

node (node_id) –

Returns

root

Return type

node_id

_subtree_sliding_contig_windows(subtree_root, window_length)

Get all the sliding windows of length ‘window_length’ from the subtree defined by the subtree root as run traces.

Parameters
  • subtree_root (node_id) –

  • window_length (int) –

Returns

subtree_windows – List of the contig tree windows as contig traces

Return type

list of list of tuples of ints (run_idx, cycle_idx)

classmethod _tree_leaves(root, tree)

Given the root node ID and the tree as a networkX DiGraph returns the leaves of the tree.

Must give it the reversed tree because it is recursive.

Parameters
  • root (node_id) –

  • tree (networkx.DiGraph) – The reversed tree from the contigtree

Returns

leaves – The leaf node IDs of the tree.

Return type

list of node_id

property boundary_condition_class

The boundary condition class is used to determine discontinuities in lineages.

contig_cycle_idx(run_idx, cycle_idx)

Convert an in-run cycle index to an in-contig cyle_idx.

Parameters
  • run_idx (int) – Index of a run in the contig tree

  • cycle_idx (int) – Index of a cycle index within a run

Returns

contig_cycle_idx – The cycle idx in the contig

Return type

int

contig_sliding_windows(contig_trace, window_length)

Given a contig trace get the sliding windows of length ‘window_length’ as contig walker traces.

Parameters
  • contig_trace (list of tuples of ints (run_idx, cycle_idx)) – Trace defining a contig in the contig tree.

  • window_length (int) – The length of the sliding windows to return.

Returns

windows – List of contig walker traces

Return type

list of list of tuples of ints (traj_idx, cycle_idx)

static contig_trace_to_run_trace(contig_trace, contig_walker_trace)

Combine a contig trace and a walker trace to get the equivalent run trace.

The contig_walker_trace cycle_idxs must be a subset of the frame indices given by the contig_trace.

Parameters
  • contig_trace (list of tuples of ints (run_idx, cycle_idx)) –

  • contig_walker_trace (list of tuples of ints (traj_idx, cycle_idx)) –

Returns

run_trace

Return type

list of tuples of ints (run_idx, traj_idx, cycle_idx)

property continuations

The continuations that are used in this contig tree over the runs.

property decision_class

The decision class used to determine parental lineages.

get_branch_trace(run_idx, cycle_idx, start_contig_idx=0)

Get a contig trace for a branch of the contig tree from an end point back to a set point (defaults to root of contig tree).

Parameters
  • run_idx (int) –

  • cycle_idx (int) – An in-contig cycle index

  • start_contig_idx (int, optional) –

    The in-contig cycle index where the “root” of the branch will start

    (Default value = 0)

Returns

contig_trace

Return type

list of tuples of ints (run_idx, cycle_idx)

get_subtree(node)

Given a node defining a subtree root return that subtree.

Parameters

node (node_id) –

Returns

subtree

Return type

networkx.DiGraph tree

property graph

The underlying networkx.DiGraph object.

leaves()

All of the leaves of this contig tree.

Returns

leaves – The leaf node IDs of the tree.

Return type

list of node_id

root_leaves()

Return a dictionary mapping the roots to their leaves.

roots()

Returns all of the roots in this contig tree (which is technically a forest and can have multiple roots).

Returns

root

Return type

list of node_id

property run_idxs

Indices of runs in WepyHDF5 used in this contig tree.

run_trace_to_contig_trace(run_trace)

Assumes that the run trace goes along a valid contig.

Parameters

run_trace (list of tuples of ints (run_idx, traj_idx, cycle_idx)) –

Returns

contig_walker_trace

Return type

list of tuples of ints (traj_idx, contig_cycle_idx)

sliding_contig_windows(window_length)

Given a ‘window_length’ return all the windows over the contig tree as contig traces.

Parameters

window_length (int) –

Returns

contig_windows – List of contig traces

Return type

list of list of tuples of ints (run_idx, cycle_idx)

sliding_windows(window_length)

Returns all the sliding windows over walker trajectories as run traces for a given window length.

Parameters

window_length (int) –

Returns

windows – List of run traces.

Return type

list of list of tuples of ints (run_idx, traj_idx, cycle_idx)

span_contig(span_idx)

Generates a contig object for the specified spanning contig.

property span_traces

Dictionary mapping the spand indices to their run traces.

spanning_contig_traces()

Returns a list of all possible spanning contigs given the continuations present in this file. Spanning contigs are paths through a tree that must start from a root node and end at a leaf node.

This algorithm always returns them in a canonical order (as long as the runs are not rearranged after being added). This means that the indices here are the indices of the contigs.

Returns

spanning_contig_traces – List of all spanning contigs which are contig traces.

Return type

list of list of tuples of ints (run_idx, cycle_idx)

subtrees()

Returns all of the subtrees (with unique roots) in this contig tree (which is technically a forest and can have multiple roots).

Returns

subtrees

Return type

list of networkx.DiGraph trees

trace_parent_table(contig_trace, discontinuities=True)

Given a contig trace returns a parent table for that contig.

Parameters
  • contig_trace (list of tuples (run_idx, cycle_idx)) –

  • discontinuities (bool) – Whether or not to include discontinuities in the table.

Returns

parent_table

Return type

list of list of int

walker_trace_to_run_trace(contig_walker_trace)

Combine a walker trace to get the equivalent run trace for this contig.

The contig_walker_trace cycle_idxs must be a subset of the frame indices given by the contig_trace.

Parameters

contig_walker_trace (list of tuples of ints (traj_idx, cycle_idx)) –

Returns

run_trace

Return type

list of tuples of ints (run_idx, traj_idx, cycle_idx)

See also

Contig.contig_trace_to_run_trace

calls this static method

class wepy.analysis.contig_tree.Contig(wepy_h5, **kwargs)[source]

Bases: wepy.analysis.contig_tree.ContigTree

Wraps a WepyHDF5 object and gives access to logical trajectories from a single contig.

This class is very similar to the ContigTree class and inherits all of those methods. It adds methods for getting records and other data about a single contig.

The only required argument is an WepyHDF5 object from which to draw data.

If continuations is given it specifies the (continuing_run_idx, continued_run_idx) continuations the contig tree will use. This overrides anything in the WepyHDF5 file. Only use this if you know what you are doing. If continuations is Ellipsis the continuations from the WepyHDF5 will be used.

If runs is not Ellipsis only these runs will be included in the ContigTree and the continuations relvant to this subset will be used.

If a valid decision_class is given walker lineages will be generated. This class is largely useless without this.

The boundary_condition_class is only used in the presence of a decision_class. A valid boundary_condition_class will detect the discontinuities in walker trajectories and will automatically apply them to divide up logical trajectories. Otherwise, if discontinuous boundary condition warping events in data are present logical trajectories will have discontinuities in them.

Parameters
  • wepy_h5 (closed WepyHDF5 object) –

  • continuations (Ellipsis (use continuations in wepy_h5) or) –

    list of tuple of int (run_idx, run_idx)

    The continuations to apply to the runs in this contig tree.

    (Default value = Ellipsis)

  • runs (Ellipsis (use all runs in wepy_h5) or) –

    list of idx

    The indices of the runs to use in the contig tree

    (Default value = Ellipsis)

  • boundary_condition_class (class implementing BoundaryCondition) – interface (Default value = None)

decision_classclass implementing Decision interface

(Default value = None)

Warning

Only set continuations if you know what you are doing.

A decision_class must be given to be able to detect cloning and merging and get parental lineages.

Make sure to give the boundary_condition_class if there was discontinuous warping events in the simulation or else you will get erroneous contiguous trajectories.

contig_fields(fields)[source]

Returns trajectory field data for the specified fields.

Parameters

fields (list of str) – The field keys you want to retrieve data for.

Returns

fields_dict

Return type

dict of str: numpy.ndarray

property contig_trace

Returns the contig trace corresponding to this contig.

Returns

Return type

contig_trace :: list of tuples of ints (run_idx, cycle_idx)

property num_cycles

The number of cycles in this contig.

Returns

num_cycles

Return type

int

num_walkers(cycle_idx)[source]

Get the number of walkers at a given cycle in the contig.

Parameters

cycle_idx (int) –

Returns

n_walkers

Return type

int

records(record_key)[source]

Returns the records for the given key.

Parameters

record_key (str) –

Returns

records

Return type

list of namedtuple records

records_dataframe(record_key)[source]

Returns the records as a pandas.DataFrame for the given key.

Parameters

record_key (str) –

Returns

records_df

Return type

pandas.DataFrame

resampling_records()[source]

Returns the resampling records.

Returns

resampling_records

Return type

list of namedtuple records

resampling_records_dataframe()[source]

Returns the resampling records as a pandas.DataFrame.

Returns

resampling_df

Return type

pandas.DataFrame

resampler_records()[source]

Returns the resampler records.

Returns

resampler_records

Return type

list of namedtuple records

resampler_records_dataframe()[source]

Returns the resampler records as a pandas.DataFrame.

Returns

resampler_df

Return type

pandas.DataFrame

warping_records()[source]

Returns the warping records.

Returns

warping_records

Return type

list of namedtuple records

warping_records_dataframe()[source]

Returns the warping records as a pandas.DataFrame.

Returns

warping_df

Return type

pandas.DataFrame

bc_records()[source]

Returns the boundary conditions records.

Returns

bc_records

Return type

list of namedtuple records

bc_records_dataframe()[source]

Returns the boundary conditions records as a pandas.DataFrame.

Returns

bc_df

Return type

pandas.DataFrame

progress_records()[source]

Returns the progress records.

Returns

progress_records

Return type

list of namedtuple records

progress_records_dataframe()[source]

Returns the progress records as a pandas.DataFrame.

Returns

progress_df

Return type

pandas.DataFrame

resampling_panel()[source]

Returns the full resampling panel for this contig.

Returns

resampling_panel

Return type

list of list of list of namedtuple records

parent_table(discontinuities=True)[source]

Returns the full parent table for this contig.

Notes

This requires the decision class to be given to the Contig at construction.

Warning

If the simulation was run with boundary conditions that result in discontinuous warping events and that class is not provided at construction time to this class these discontinuities will not be taken into account and not added to this parent table.

Returns

parent_table

Return type

list of list of int

DISCONTINUITY_KEY = 'discontinuities'

Key for discontinuity node attributes in the tree graph.

PARENTS_KEY = 'parent_idxs'

Key for parent indices node attributes in the tree graph.

RESAMPLING_PANEL_KEY = 'resampling_steps'

Key for resampling panel node attributes in the tree graph.

classmethod _contig_runs_to_continuations(contig_runs)

Helper function to convert a list of run indices defining a contig to continuations.

Parameters

contig_runs (list of int) –

Returns

continuations

Return type

list of tuple of int (run_idx, run_idx)

classmethod _contig_trace_to_contig_runs(contig_trace)

Convert a contig trace to a list of runs.

Parameters

contig_trace (list of tuples of ints (run_idx, cycle_idx)) –

Returns

contig_runs

Return type

list of int

classmethod _continuations_to_contig_runs(continuations)

Helper function that converts a list of continuations to a list of the runs in the order of the contigs defined by the continuations.

Parameters

continuations (list of tuple of int (run_idx, run_idx)) –

Returns

contig_runs

Return type

list of int

_create_tree(wepy_h5)

Generate the tree of cycles from the WepyHDF5 object/file.

_initialize_discontinuities(wepy_h5)

Initialize the nodes with discontinuities attributes but set to 0s indicating no discontinuities.

classmethod _rec_spanning_paths(edges, root)

Given a set of directed edges (source, target) and a root node id of a tree imposed over the edges, returns all the paths over that tree which span from the root to a leaf.

This is a recursive function and has pretty bad performance for nontrivial simulations.

Parameters
  • edges ((node_id, node_id)) –

  • root (node_id) –

Returns

spanning_paths

Return type

list of edges

_root_spanning_contig_traces()

Returns a list of all possible spanning contigs given the continuations present in this file. Spanning contigs are paths through a tree that must start from a root node and end at a leaf node.

This algorithm always returns them in a canonical order (as long as the runs are not rearranged after being added). This means that the indices here are the indices of the contigs.

Returns

spanning_contig_traces – Dictionary mapping the root ids to all spanning contigs for it which are contig traces.

Return type

dict of root_id to list of tuples of ints (run_idx, cycle_idx)

_set_base_contigtree_to_self(base_contigtree)
_set_discontinuities(wepy_h5, boundary_conditions_class)

Given the boundary condition class sets node attributes for where there are discontinuities in the parental lineages.

Parameters

boundary_conditions_class (class implementing BoundaryCondition interface) –

_set_parents(decision_class)

Determines the net parents for each cycle and sets them in-place to the cycle tree given.

Parameters

decision_class (class implementing Decision interface) –

_set_resampling_panels(wepy_h5)

Generates resampling panels for each cycle and sets them as node attributes.

_spanning_paths(root)
Parameters

root (node_id) –

Returns

spanning_paths

Return type

list of list of edges

_subtree_leaves(root)

Given a root defining a subtree on the full tree returns the leaves of that subtree.

Parameters

root (node_id) –

Returns

leaves – The leaf node IDs of the tree.

Return type

list of node_id

_subtree_root(node)

Given a node find the root of the tree it is on

Parameters

node (node_id) –

Returns

root

Return type

node_id

_subtree_sliding_contig_windows(subtree_root, window_length)

Get all the sliding windows of length ‘window_length’ from the subtree defined by the subtree root as run traces.

Parameters
  • subtree_root (node_id) –

  • window_length (int) –

Returns

subtree_windows – List of the contig tree windows as contig traces

Return type

list of list of tuples of ints (run_idx, cycle_idx)

classmethod _tree_leaves(root, tree)

Given the root node ID and the tree as a networkX DiGraph returns the leaves of the tree.

Must give it the reversed tree because it is recursive.

Parameters
  • root (node_id) –

  • tree (networkx.DiGraph) – The reversed tree from the contigtree

Returns

leaves – The leaf node IDs of the tree.

Return type

list of node_id

property base_contigtree
property boundary_condition_class

The boundary condition class is used to determine discontinuities in lineages.

close()
contig_cycle_idx(run_idx, cycle_idx)

Convert an in-run cycle index to an in-contig cyle_idx.

Parameters
  • run_idx (int) – Index of a run in the contig tree

  • cycle_idx (int) – Index of a cycle index within a run

Returns

contig_cycle_idx – The cycle idx in the contig

Return type

int

contig_sliding_windows(contig_trace, window_length)

Given a contig trace get the sliding windows of length ‘window_length’ as contig walker traces.

Parameters
  • contig_trace (list of tuples of ints (run_idx, cycle_idx)) – Trace defining a contig in the contig tree.

  • window_length (int) – The length of the sliding windows to return.

Returns

windows – List of contig walker traces

Return type

list of list of tuples of ints (traj_idx, cycle_idx)

static contig_trace_to_run_trace(contig_trace, contig_walker_trace)

Combine a contig trace and a walker trace to get the equivalent run trace.

The contig_walker_trace cycle_idxs must be a subset of the frame indices given by the contig_trace.

Parameters
  • contig_trace (list of tuples of ints (run_idx, cycle_idx)) –

  • contig_walker_trace (list of tuples of ints (traj_idx, cycle_idx)) –

Returns

run_trace

Return type

list of tuples of ints (run_idx, traj_idx, cycle_idx)

property continuations

The continuations that are used in this contig tree over the runs.

property decision_class

The decision class used to determine parental lineages.

get_branch_trace(run_idx, cycle_idx, start_contig_idx=0)

Get a contig trace for a branch of the contig tree from an end point back to a set point (defaults to root of contig tree).

Parameters
  • run_idx (int) –

  • cycle_idx (int) – An in-contig cycle index

  • start_contig_idx (int, optional) –

    The in-contig cycle index where the “root” of the branch will start

    (Default value = 0)

Returns

contig_trace

Return type

list of tuples of ints (run_idx, cycle_idx)

get_subtree(node)

Given a node defining a subtree root return that subtree.

Parameters

node (node_id) –

Returns

subtree

Return type

networkx.DiGraph tree

property graph

The underlying networkx.DiGraph object.

leaves()

All of the leaves of this contig tree.

Returns

leaves – The leaf node IDs of the tree.

Return type

list of node_id

lineages_contig(contig_trace, discontinuities=True)[source]
make_contig(contig_trace)

Create a Contig object given a contig trace.

Parameters

contig_trace (list of tuples of ints (run_idx, cycle_idx)) –

Returns

contig

Return type

Contig object

open(mode=None)
root_leaves()

Return a dictionary mapping the roots to their leaves.

roots()

Returns all of the roots in this contig tree (which is technically a forest and can have multiple roots).

Returns

root

Return type

list of node_id

property run_idxs

Indices of runs in WepyHDF5 used in this contig tree.

run_trace_to_contig_trace(run_trace)

Assumes that the run trace goes along a valid contig.

Parameters

run_trace (list of tuples of ints (run_idx, traj_idx, cycle_idx)) –

Returns

contig_walker_trace

Return type

list of tuples of ints (traj_idx, contig_cycle_idx)

sliding_contig_windows(window_length)

Given a ‘window_length’ return all the windows over the contig tree as contig traces.

Parameters

window_length (int) –

Returns

contig_windows – List of contig traces

Return type

list of list of tuples of ints (run_idx, cycle_idx)

sliding_windows(window_length)

Returns all the sliding windows over walker trajectories as run traces for a given window length.

Parameters

window_length (int) –

Returns

windows – List of run traces.

Return type

list of list of tuples of ints (run_idx, traj_idx, cycle_idx)

span_contig(span_idx)

Generates a contig object for the specified spanning contig.

property span_traces

Dictionary mapping the spand indices to their run traces.

spanning_contig_traces()

Returns a list of all possible spanning contigs given the continuations present in this file. Spanning contigs are paths through a tree that must start from a root node and end at a leaf node.

This algorithm always returns them in a canonical order (as long as the runs are not rearranged after being added). This means that the indices here are the indices of the contigs.

Returns

spanning_contig_traces – List of all spanning contigs which are contig traces.

Return type

list of list of tuples of ints (run_idx, cycle_idx)

subtrees()

Returns all of the subtrees (with unique roots) in this contig tree (which is technically a forest and can have multiple roots).

Returns

subtrees

Return type

list of networkx.DiGraph trees

trace_parent_table(contig_trace, discontinuities=True)

Given a contig trace returns a parent table for that contig.

Parameters
  • contig_trace (list of tuples (run_idx, cycle_idx)) –

  • discontinuities (bool) – Whether or not to include discontinuities in the table.

Returns

parent_table

Return type

list of list of int

walker_trace_to_run_trace(contig_walker_trace)

Combine a walker trace to get the equivalent run trace for this contig.

The contig_walker_trace cycle_idxs must be a subset of the frame indices given by the contig_trace.

Parameters

contig_walker_trace (list of tuples of ints (traj_idx, cycle_idx)) –

Returns

run_trace

Return type

list of tuples of ints (run_idx, traj_idx, cycle_idx)

See also

Contig.contig_trace_to_run_trace

calls this static method

property wepy_h5

The WepyHDF5 source object for which the contig tree is being constructed.

lineages(contig_trace, discontinuities=True)[source]

Get the ancestry lineage for each element of the trace as a run trace.

warp_contig_trace()[source]

Return a trace that gives all of the walkers that were warped.

resampling_contig_trace(decision_id)[source]

Return full run traces for every specified type of resampling event.

Parameters

decision_id (int) – The integer ID of the decision you want to match on and get lineages for. This is the integer value of the decision enumeration value.

final_contig_trace()[source]
warp_trace()[source]

Return a run trace that gives all of the walkers that were warped.

resampling_trace(decision_id)[source]

Return full run traces for every specified type of resampling event.

Parameters

decision_id (int) – The string ID of the decision you want to match on and get lineages for.

final_trace()[source]

Return a trace of all the walkers at the end of the contig.

resampling_tree_layout_graph(bc_class=None, progress_key=None, node_shape='disc', discontinuous_node_shape='square', colormap_name='plasma', node_radius=None, row_spacing=None, step_spacing=None, central_axis=None)[source]