macでインフォマティクス

macでインフォマティクス

HTS (NGS) 関連のインフォマティクス情報についてまとめています。

Ancestral recombination graphを可視化するpythonパッケージ tskit_arg_visualizer

 

Ancestral recombination graphs (ARGs)は、組換えを起こす系統間の遺伝的関係を完全に表現したものであり、集団遺伝学において中心的な重要性を担っている。近年のシミュレーションおよび推論手法の飛躍的進歩により、ARGへの関心が高まっている。しかし、ARGのグラフィカルな構造を最大限に活用する方法は、研究者にとって依然として未解決の問題である。本稿では、インタラクティブなD3.js可視化ライブラリを用いてプログラム的にARGを描画するためのPythonパッケージ、tskit_arg_visualizerを紹介する。この可視化ツールは、ARGの概念の教育と、経験的データセットから推論されたARGの探索の両方において有用であることを示す。tskit_arg_visualizerの最新の安定版は、Python Package Index(https://pypi.org/project/tskit-arg-visualizer、現在v0.1.1)から入手できる。ドキュメントとパッケージの開発バージョンは、GitHub (https://github.com/kitchensjn/tskit_arg_visualizer) にある。

 

Tutorial

https://github.com/kitchensjn/tskit_arg_visualizer/blob/main/docs/tutorial.md

 

インストール

Github

mamba create -n tskit_arg_visualizer python=3.13 -y
conda activate tskit_arg_visualizer
pip install tskit_arg_visualizer
pip install jupyterlab

#Github
git clone https://github.com/kitchensjn/tskit_arg_visualizer.git
cd tskit_arg_visualizer
python -m pip install --upgrade pip
pip install -e .
pip install jupyterlab

 

実行方法

tskit_arg_visualizerは、tskitのTreeSequenceやJSONからARGを読み込み、ブラウザまたはJupyter Notebook上に組換えを起こす系統間の遺伝的関係を描画するツール。使い方を簡単に見ていきます。通常、jupyter labで進めます。

 

テストラン

1、jupyter立ち上げ、python環境で進める

jupyter lab

 

2、テストARG(Ancestral recombination graphs)を作成

import msprime
import tskit_arg_visualizer
ts = msprime.sim_ancestry(
    samples=5,
    recombination_rate=1e-8,
    sequence_length=3000,
    population_size=10000,
    record_full_arg=True,
    random_seed=1234
)
ts = msprime.sim_mutations(
    ts,
    rate=1e-7,
    random_seed=4321
)
print(ts)

 

3、D3ARG形式に変換

d3arg = tskit_arg_visualizer.D3ARG.from_ts(
    ts=ts,
    progress=True
)

 

4、描画

d3arg.draw(
    edge_type="line",
    show_mutations=True,
    rotate_tip_labels=True,
    width=800,
    height=600
)

ARGのグラフが出力される。ARGは、組換えを含むゲノムの祖先関係を、1本の系統樹ではなくグラフとして表したもの。

通常の系統樹なら1つのツリーとして読むが、ARGでは組換えがあるため、ゲノムの場所によって系統関係が変わる。

下側のノードは現在のサンプル、上側のノードは過去の祖先を表す。左軸は世代単位の時間であり、上に行くほど古い祖先になる。黒線は祖先から子孫への継承関係を示し、黄色の横線は変異を表す。下部のバーはゲノム座標で、今回の例では0から3000までの領域を表示している。下部のバーの区切りは、組換えなどによってlocal treeが切り替わるbreakpointを示している。

 

ゲノムバーにマウスを重ねると、その区間に対応するlocal treeが強調表示され、ゲノム位置ごとに系統関係が変化することを確認できる。

 

実データで使う場合は、VCFから直接利用できない。ARGを見たい場合は、まずARG推定ツールでTreeSequenceに変換する。推奨はtskit TreeSequenceを出力できるtsinferとtsdateの組み合わせで、これらのツールでVCFからTreeSequenceを作成、さらにdated TreeSequenceを得てtskit_arg_visualizerで可視化する。

 

論文より、

  • tskit_arg_visualizer パッケージは tskit と、より広範な他のパッケージをベースに構築されている。tskit_arg_visualizer は独自の形式を採用しており、tskit とは完全に独立して使用できるが、両者には多くの概念的な類似点があり、両者はシームレスに統合されるように設計されている。

引用

tskit_arg_visualizer: interactive plotting of ancestral recombination graphs Open Access

James Kitchens , Yan Wong

Bioinformatics Advances, Volume 5, Issue 1, 2025

 

> import tskit_arg_visualizer

> help(tskit_arg_visualizer)

help

Help on package tskit_arg_visualizer:

 

NAME

    tskit_arg_visualizer

 

PACKAGE CONTENTS

 

 

CLASSES

    builtins.object

        D3ARG

        DrawInfo

        IncludedObjects

 

    class D3ARG(builtins.object)

     |  D3ARG(nodes, edges, mutations, breakpoints, num_samples, sample_order, default_node_style, time_units)

     |

     |  Stores the ARG in a D3.js friendly format ready for plotting

     |

     |  See 'Alternative Constructors' for common ways of creating this object

     |

     |  Attributes

     |  ----------

     |  nodes : list

     |      List of node dicts that contain info about the nodes

     |  edges : list

     |      List of edge dicts that contain info about the edges

     |  breakpoints : list

     |      List of breakpoint dicts that contain info about the breakpoints

     |  num_samples : int

     |      The number of samples in the ARG (with (ts_flags & 1) == 1)

     |  sample_order : list

     |      Ordered list of sample IDs

     |

     |  Alternative Constructors

     |  ------------------------

     |  from_ts(ts)

     |      Creates a D3ARG from a tskit.TreeSequence

     |

     |  from_json(json)

     |      Creates a D3ARG from a saved custom JSON

     |

     |  Methods

     |  -------

     |  draw(

     |      width=500,

     |      height=500,

     |      tree_highlighting=True,

     |      y_axis_labels=True,

     |      y_axis_scale="rank",

     |      line_type="ortho",

     |      subset_nodes=[],

     |      include_node_labels=True

     |  )

     |      Draws the ARG using D3.js

     |

     |  set_node_labels(labels={})

     |      Customizes node labels in visualization

     |

     |  reset_node_labels()

     |      Sets the node labels back to default values

     |

     |  Methods defined here:

     |

     |  __init__(self, nodes, edges, mutations, breakpoints, num_samples, sample_order, default_node_style, time_units)

     |      Initializes a D3ARG object

     |

     |      This is the generalized function for initializing a D3ARG object. It is most

     |      often called by another method, such as from_ts() or from_json(), though it

     |      can be used separately if the parameters are in the correct format.

     |

     |      Parameters

     |      ----------

     |      nodes : pandas.DataFrame

     |          Contains info about the nodes

     |      edges : pandas.DataFrame

     |          Contains info about the edges

     |      breakpoints : pandas.DataFrame

     |          Contains info about the breakpoints

     |      num_samples : int

     |          Number of samples in the ARG. Useful for various calculations when plotting

     |      sample_order : list or np.array

     |          Order of the sample ID from left to right when plotting

     |      default_node_style : dict

     |      time_units : string

     |          Time units for the node times (example is "generations").

     |

     |  __str__(self)

     |      Prints attributes of D3ARG object

     |

     |  draw(self, width=500, height=500, tree_highlighting=True, y_axis_labels=True, y_axis_title=None, y_axis_scale='rank', edge_type='line', variable_edge_width=False, include_underlink=True, sample_order=None, title=None, show_mutations=False, ignore_mutation_times=True, label_mutations=False, condense_mutations=False, is_notebook=None, rotate_tip_labels=False, zoom=0, styles=None, preamble=None, save_filename=None)

     |      Draws the D3ARG using D3.js by sending a custom JSON object to visualizer.js

     |

     |       Parameters

     |       ----------

     |       width : int

     |           Width of the force layout graph plot in pixels (default=500)

     |       height : int

     |           Height of the force layout graph plot in pixels (default=500)

     |       tree_highlighting : bool

     |           Include the interactive chromosome at the bottom of the figure to

     |           to let users highlight trees in the ARG (default=True)

     |       y_axis_labels : bool, list, or dict

     |           Whether to include the y-axis on the left of the figure. By default, tick marks will be automatically

     |           chosen. You can specify a list of tick marks to use instead. You can also set custom text for tick marks

     |           using a dictionary where key is the time and value is the text. (default=True)

     |       y_axis_title : string

     |           Title of the y-axis that will be plotted on the left hand side of the figure. (default=None, uses

     |           `D3ARG.time_units` attribute)

     |       y_axis_scale : string

     |           Scale used for the positioning nodes along the y-axis. Options:

     |               "rank" (default) - equal vertical spacing between nodes

     |               "time" - vertical spacing is proportional to the time

     |               "log_time" - proportional to the log of time

     |       edge_type : string

     |           Pathing type for edges between nodes. Options:

     |               "line" (default) - simple straight lines between the nodes

     |               "ortho" - custom pathing (see pathing.md for more details, should only be used with full ARGs)

     |       variable_edge_width : bool

     |           Scales the stroke width of edges in the visualization will be proportional to the fraction of

     |           sequence in which that edge is found. (default=False)

     |       include_underlink : bool

     |           Includes an "underlink" for each edge gives a gap during edge crosses. This is currently only

     |           implemented for `edge_type="ortho"`. (default=True)

     |       sample_order : list

     |           Sample nodes IDs in desired order. Must only include sample nodes IDs, but does not

     |           need to include all sample nodes IDs. (default=None, order is set by first tree in tree sequence)

     |       title : str

     |           Title to be put at the top of the figure. (default=None, ignored)

     |       show_mutations : bool

     |           Whether to add mutations to the graph. Only available when `edge_type="line"`. (default=False)

     |       ignore_mutation_times : bool

     |           Whether to plot mutations evenly on edge (True) or at there specified times (False). (default=True, ignored)

     |       label_mutations : bool

     |           Whether to add the full label (position_index:inherited:derived) for each mutation. (default=False)

     |       condense_mutations : bool

     |           Whether to merge all mutations along an edge into a single mutation symbol. (default=False)

     |       is_notebook : bool

     |           Should the visualizer assume a notebook environment or show the visualization

     |           in a standalone HTML page? By default, the function will attempt to autodetect

     |           whether it is being called in a notebook environment. This may not work in

     |           some untested environments, in which case you may wish to set this explicitly

     |           to True (to force a notebook display) or False (to force a standalone HTML page).

     |      rotate_tip_labels : bool

     |           Rotates tip labels by 90 degrees. (default=False)

     |       zoom : int

     |           The level of detail that you want. Larger numbers equate to less detail/more collapsing

     |       styles : list

     |           A list of css strings, one per selector. The ID of the current drawing will be

     |           appended to each string, so that the styles are unique to the current drawing.

     |           For example, [".labels {font-family: Times}"] will change the font of all the

     |           labels. Note that some styles are set from values in the dataframes stored in the

     |           D3ARG object, and cannot be altered using the 'styles' parameter. (default=None)

     |       preamble : str

     |           Extra HTML to be added to the D3ARG visualization. It is the user's

     |           responsibility to ensure that this is valid HTML. The preamble can be used

     |           to add additional information, such as a legend, to the visualization. To

     |           overlay any content on top of the plot, you may wish to wrap the preamble in a

     |           tag which has the "position: absolute" and "z-index: 1" styles set, e.g.

     |           `preamble='<div style="position:absolute; z-index:1; right:2em">My text</div>'`

     |           (default="")

     |       save_filename : str

     |           Filename to use when selecting "Download as" in the visualization

     |           (default=None, treated as "tskit_arg_visualizer")

     |

     |       Returns

     |       -------

     |       info : DrawInfo

     |           An object with information about the drawing, for example

     |           the width and height and the objects (such as which nodes) which

     |           were included in the drawing.

     |

     |  draw_genome_bar(self, width=500, windows=None, show_mutations=False, is_notebook=None)

     |      Draws a genome bar for the D3ARG using D3.js

     |

     |      Parameters

     |      ----------

     |      width : int

     |          Width of the force layout graph plot in pixels (default=500)

     |      windows : list of lists

     |          Each list is are the start and end positions of the windows. Multiple windows can be included.

     |          (Default is None, ignored)

     |      show_mutations : bool

     |          Whether to add ticks for mutations along the genome bar

     |      is_notebook : bool

     |          Should the visualizer assume a notebook environment or show the visualization

     |          in a standalone HTML page? By default, the function will attempt to autodetect

     |          whether it is being called in a notebook environment. This may not work in

     |          some untested environments, in which case you may wish to set this explicitly

     |          to True (to force a notebook display) or False (to force a standalone HTML page).

     |

     |  draw_node(self, seed_nodes, width=500, height=500, depth=1, y_axis_labels=True, y_axis_title=None, y_axis_scale='rank', tree_highlighting=True, title=None, show_mutations=False, ignore_mutation_times=True, label_mutations=False, condense_mutations=False, is_notebook=None, rotate_tip_labels=False, styles=None, preamble=None, save_filename=None)

     |      Draws a subgraph of the D3ARG using D3.js by sending a custom JSON object to visualizer.js.

     |

     |      Parameters

     |      ----------

     |      seed_nodes : int or list

     |          Node ID or list of node IDs that will be central to the subgraph

     |      width : int

     |          Width of the force layout graph plot in pixels (default=500)

     |      height : int

     |          Height of the force layout graph plot in pixels (default=500)

     |      depth : int or list(int, int)

     |          Number of nodes above (older than) and below (younger than) the central

     |          node to include in the subgraph (default=1). If this is a list, the

     |          number of nodes above is taken from the first element and

     |          the number of nodes below from the last element.

     |      y_axis_labels : bool, list, or dict

     |          Whether to include the y-axis on the left of the figure. By default, tick marks will be automatically

     |          chosen. You can specify a list of tick marks to use instead. You can also set custom text for tick marks

     |          using a dictionary where key is the time and value is the text. (default=True)

     |      y_axis_title : string

     |          Title of the y-axis that will be plotted on the left hand side of the figure. (default=None, uses

     |          `D3ARG.time_units` attribute)

     |      y_axis_scale : string

     |          Scale used for the positioning nodes along the y-axis. Options:

     |              "rank" (default) - equal vertical spacing between nodes

     |              "time" - vertical spacing is proportional to the time

     |              "log_time" - proportional to the log of time

     |      tree_highlighting : bool

     |          Include the interactive chromosome at the bottom of the figure to

     |          to let users highlight trees in the ARG (default=True)

     |      title : str

     |          Title to be put at the top of the figure. (default=None, ignored)

     |      show_mutations : bool

     |          Whether to add mutations to the graph. (default=False)

     |      ignore_mutation_times : bool

     |          Whether to plot mutations evenly on edge (True) or at there specified times (False). (default=True, ignored)

     |      label_mutations : bool

     |          Whether to add the full label (position_index:inherited:derived) for each mutation. (default=False)

     |      condense_mutations : bool

     |          Whether to merge all mutations along an edge into a single mutation symbol. (default=False)

     |      is_notebook : bool

     |          Should the visualizer assume a notebook environment or show the visualization

     |          in a standalone HTML page? By default, the function will attempt to autodetect

     |          whether it is being called in a notebook environment. This may not work in

     |          some untested environments, in which case you may wish to set this explicitly

     |          to True (to force a notebook display) or False (to force a standalone HTML page).

     |      rotate_tip_labels : bool

     |          Rotates tip labels by 90 degrees. (default=False)

     |      styles : list

     |          A list of css strings, one per selector. The ID of the current drawing will be

     |          appended to each string, so that the styles are unique to the current drawing.

     |          For example, [".labels {font-family: Times}"] will change the font of all the

     |          labels. Note that some styles are set from values in the dataframes stored in the

     |          D3ARG object, and cannot be altered using the 'styles' parameter. (default=None)

     |      preamble : str

     |          Extra HTML to be added to the D3ARG visualization. It is the user's

     |          responsibility to ensure that this is valid HTML. The preamble can be used

     |          to add additional information, such as a legend, to the visualization. To

     |          overlay any content on top of the plot, you may wish to wrap the preamble in a

     |          tag which has the "position: absolute" and "z-index: 1" styles set, e.g.

     |          `preamble='<div style="position:absolute; z-index:1; right:2em">My text</div>'`

     |          (default="")

     |      save_filename : str

     |          Filename to use when selecting "Download as" in the visualization

     |          (default=None, treated as "tskit_arg_visualizer")

     |

     |      Returns

     |      -------

     |      info : DrawInfo

     |          An object with information about the drawing, for example

     |          the width and height and the objects (such as which nodes) which

     |          were included in the drawing.

     |

     |  draw_nodes = draw_node(self, seed_nodes, width=500, height=500, depth=1, y_axis_labels=True, y_axis_title=None, y_axis_scale='rank', tree_highlighting=True, title=None, show_mutations=False, ignore_mutation_times=True, label_mutations=False, condense_mutations=False, is_notebook=None, rotate_tip_labels=False, styles=None, preamble=None, save_filename=None)

     |

     |  reset_all_breakpoint_fills(self)

     |      Sets the fill of genome bar blocks to the specified color

     |

     |  reset_all_edge_colors(self)

     |      Resets the edge strokes to the default (#053e4e)

     |

     |  reset_all_mutation_styles(self)

     |      Resets mutation styles to default

     |

     |  reset_all_node_labels(self)

     |      Resets node labels to default (based on msprime IDs)

     |

     |  reset_all_node_styles(self)

     |      Resets node styles to default (same as when assigned using D3ARG.from_ts)

     |

     |      WARNING: This might not match the initial styles if using D3ARG.from_json

     |

     |  set_all_breakpoint_fills(self, color)

     |      Sets the fill of genome bar blocks to the specified color

     |

     |  set_all_edge_colors(self, color)

     |      Sets the edge strokes to the specified color

     |

     |  set_all_mutation_styles(self, *, size=None, fill=None, stroke=None)

     |      Set all at once

     |

     |  set_all_node_styles(self, size=None, symbol=None, fill=None, stroke=None, stroke_width=None)

     |      Sets the styling of all of the nodes at once for a specific option.

     |

     |      If optional parameter not provided, that styling option will be ignored and unchanged.

     |

     |      Parameters

     |      ----------

     |      size : int

     |          Size in pixels of the node

     |      symbol : string

     |          D3 symbol (see https://d3js.org/d3-shape/symbol)

     |      fill : string

     |          Color of the node, "#XXXXXX" form

     |      stroke : string

     |          Color of the stroke around the node, "#XXXXXX" form

     |      stroke_width : int

     |          Pixel width for the stroke around the node

     |

     |  set_breakpoint_fills(self, colors)

     |      Set the fill of each breakpoint block in the ARG

     |

     |      Parameters

     |      ----------

     |      colors : dict

     |          ID of the edge and its new color

     |

     |  set_edge_colors(self, colors)

     |      Set the color of each edge in the ARG

     |

     |      Parameters

     |      ----------

     |      colors : dict

     |          ID of the edge and its new color

     |

     |  set_mutation_styles(self, styles)

     |      Individually control the styling of each mutation.

     |

     |      Parameters

     |      ----------

     |      styles : dict

     |          A dictionary whose keys are mutation ids, and whose values are separate

     |          dictionaries containing any of the styling keys: size, fill, stroke.

     |          Only mutations that need styles updated need to be provided, and all

     |          styling keys are optional.

     |

     |  set_node_labels(self, labels)

     |      Sets custom node labels

     |

     |      Updates node labels based on the D3ARG node "id" using the labels dictionary.

     |      Final labels will always be strings. Do not rely on the ordering of the

     |      labels dictionary.

     |

     |      Parameters

     |      ----------

     |      labels : dict

     |          ID of the node and its new label

     |

     |  set_node_styles(self, styles)

     |      Individually control the styling of each node.

     |

     |      Parameters

     |      ----------

     |      styles : dict

     |          A dictionary whose keys are node ids, and whose values are separate dicts

     |          containing any of the styling keys: size, symbol, fill, stroke, stroke_width.

     |          Only nodes that need styles updated need to be provided, and all styling

     |          keys are optional.

     |

     |  set_node_x_positions(self, pos)

     |      Sets the x-axis positions of nodes

     |

     |      Positions must be between 0 and 1

     |

     |      Parameters

     |      ----------

     |      pos : dict

     |          ID of the node and its x-axis position (scaled between 0 and 1)

     |

     |  subset_graph(self, seed_nodes, depth)

     |      Subsets the graph to focus around a specific node

     |

     |      Parameters

     |      ----------

     |      seed_nodes : int or list

     |          Node ID or list of node IDs that will be central to the subgraph

     |      depth : int or list(int, int)

     |          Number of nodes above (older than) and below (younger than) the central

     |          node to include in the subgraph (default=1). If this is a list, the

     |          number of nodes above is taken from the first element and

     |          the number of nodes below from the last element.

     |

     |      Returns

     |      -------

     |      included_nodes : pd.DataFrame

     |          The nodes to be plotted, potentially subset of original graph

     |      included_edges : pd.DataFrame

     |          The edges to be plotted, potentially subset of original graph

     |      included_mutations : pd.DataFrame

     |          The mutations to be plotted, potentially subset of original graph

     |      included_breakpoints : pd.DataFrame

     |          The breakpoints to be plotted, potentially subset of original graph

     |

     |  ----------------------------------------------------------------------

     |  Class methods defined here:

     |

     |  from_json(json)

     |      Converts a saved custom JSON into the D3ARG object

     |

     |      Parameters

     |      ----------

     |      json : list of dictionaries

     |          the custom output of that is downloaded from the visualizer.

     |          See plotting.md for more details on the format of the json structure

     |

     |      Returns

     |      -------

     |      D3ARG : a corresponding D3ARG object ready to be plotted

     |

     |  from_ts(ts, ignore_unattached_nodes=False, progress=None, default_node_style=None)

     |      Converts a tskit tree sequence into a D3ARG object

     |

     |      Parameters

     |      ----------

     |      ts : tskit.TreeSequence

     |          Note: if tree sequence marks recombination nodes, it must use 2-RE format similar to that

     |          used by msprime.sim_ancestry(...,record_full_arg=True).

     |      ignore_unattached_nodes : bool

     |          Whether to include all nodes or ignore nodes that are completely

     |          unattached. Default is False.

     |      progress : bool

     |          Show progress bars during conversion

     |      default_node_style : dict

     |          Customizable node stylings that will be set as default. Options include size, symbol, fill, stroke, and stroke_width

     |

     |      Returns

     |      -------

     |      D3ARG : a corresponding D3ARG object ready to be plotted

     |

     |  ----------------------------------------------------------------------

     |  Data descriptors defined here:

     |

     |  __dict__

     |      dictionary for instance variables

     |

     |  __weakref__

     |      list of weak references to the object

 

    class DrawInfo(builtins.object)

     |  DrawInfo(width: int, height: int, uid: str, is_notebook: bool, included: tskit_arg_visualizer.IncludedObjects) -> None

     |

     |  Stores information returned by drawing an ARG.

     |

     |  Methods defined here:

     |

     |  __eq__(self, other)

     |      Return self==value.

     |

     |  __init__(self, width: int, height: int, uid: str, is_notebook: bool, included: tskit_arg_visualizer.IncludedObjects) -> None

     |      Initialize self.  See help(type(self)) for accurate signature.

     |

     |  __repr__(self)

     |      Return repr(self).

     |

     |  ----------------------------------------------------------------------

     |  Data descriptors defined here:

     |

     |  __dict__

     |      dictionary for instance variables

     |

     |  __weakref__

     |      list of weak references to the object

     |

     |  ----------------------------------------------------------------------

     |  Data and other attributes defined here:

     |

     |  __annotations__ = {'height': <class 'int'>, 'included': <class 'tskit_...

     |

     |  __dataclass_fields__ = {'height': Field(name='height',type=<class 'int...

     |

     |  __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...

     |

     |  __hash__ = None

     |

     |  __match_args__ = ('width', 'height', 'uid', 'is_notebook', 'included')

 

    class IncludedObjects(builtins.object)

     |  IncludedObjects(nodes: list[int] | None = None) -> None

     |

     |  Stores the IDs of the various objects included in a drawing.

     |

     |  Methods defined here:

     |

     |  __eq__(self, other)

     |      Return self==value.

     |

     |  __init__(self, nodes: list[int] | None = None) -> None

     |      Initialize self.  See help(type(self)) for accurate signature.

     |

     |  __repr__(self)

     |      Return repr(self).

     |

     |  ----------------------------------------------------------------------

     |  Data descriptors defined here:

     |

     |  __dict__

     |      dictionary for instance variables

     |

     |  __weakref__

     |      list of weak references to the object

     |

     |  ----------------------------------------------------------------------

     |  Data and other attributes defined here:

     |

     |  __annotations__ = {'nodes': list[int] | None}

     |

     |  __dataclass_fields__ = {'nodes': Field(name='nodes',type=list[int] | N...

     |

     |  __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...

     |

     |  __hash__ = None

     |

     |  __match_args__ = ('nodes',)

     |

     |  nodes = None

 

FUNCTIONS

    calculate_evenly_distributed_positions(num_elements, start=0, end=1, round_to=0)

        Returns a list of `num_elements` evenly distributed positions on a given `length`

 

        Parameters

        ----------

        num_elements : int

            Number of positions to be returned

        start : int

            Start of position range

        end : int

            End of position range

        round_to : int

            The number of decimals to round to

 

        Returns

        -------

        List of float positions

 

    convert_time_to_position(t, min_time, max_time, scale, unique_times, h_spacing, height, y_shift=0)

        Calculates a y-axis position corresponding to a time on various axis scales

 

        Parameters

        ----------

        t : int or float

            Time to convert

        min_time : int or float

            Minimum time along axis

        max_time

            Maximum time along axis

        scale : str

            Axis scale to use (Options: "rank", "time", or "log_time).

        unique_times : list

            All of the node and mutation times used for determining rank of time.

        h_spacing : float

            Gap between ranks

        height : int or float

            Height of the visualizer

        y_shift : int or float

            Translation to add to the position. (default=0)

 

    draw_D3(arg_json, styles=None, is_notebook=None)

 

    extract_x_positions_from_json(arg_json)

        Extracts the x position of nodes from json loaded from a saved ARG. This

        can be passed into D3ARG.set_node_x_positions to retain the same x positions.

 

        Parameters

        ----------

        arg_json : json

            The loaded json from the saved ARG

 

        Returns

        -------

        x_pos_01 : dict

            Nodes' x-axis positions scaled between 0 and 1

 

        Examples

        --------

        >>> import json

        >>> from pathlib import Path

        >>> d3arg.set_node_x_positions(  # assume a D3ARG object named d3arg

        ...     pos=extract_x_positions_from_json(

        ...         json.loads(Path("tskit_arg_visualizer.json").read_text())

        ...     )

        ... )

        >>> d3arg.draw()  # draw, with fixed nodes for loaded x positions

 

    map_value(n, start1, stop1, start2, stop2)

        Map a value to a new range

        From SO: https://stackoverflow.com/questions/44338698/p5-js-map-function-in-python

 

        Parameters

        ----------

        n : int or float

        start1 : int or float

        stop1 : int or float

        start2 : int or float

        stop2 : int or float

 

        Returns

        -------

        mapped

 

    running_in_notebook()

        Checks whether the code is being executed within a Jupyter Notebook.

 

        Adapted from https://stackoverflow.com/questions/15411967/how-can-i-check-if-code-is-executed-in-the-ipython-notebook

 

        Returns

        -------

        bool

            True if being executed within a Jupyter Notebook, False otherwise

 

DATA

    default_mutation_styles = {'condensed': {'fill': 'pink', 'stroke': '#0...

 

VERSION

    Using __version__ is deprecated. Please use `importlib.metadata.version('tskit_arg_visualizer')` instead

 

FILE

    /Users/kazu/Downloads/clinker/tskit_arg_visualizer/tskit_arg_visualizer/__init__.py