Skip to content

Commit

Permalink
Merge pull request #23 from matsengrp/21-fix-names
Browse files Browse the repository at this point in the history
21 Fix Names
  • Loading branch information
willdumm authored Sep 14, 2022
2 parents 30c2b15 + f1b5a0d commit 0122aef
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 258 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ with open('sample_data/toy_trees.p', 'rb') as fh:
ete_trees = pickle.load(fh)

dag = hdag.history_dag_from_etes(ete_trees, ['sequence'])
dag.count_trees() # 1041
dag.count_histories() # 1041

dag.add_all_allowed_edges()
dag.count_trees() # 3431531
dag.make_complete()
dag.count_histories() # 3431531

dag.hamming_parsimony_count() # Shows counts of trees of different parsimony scores
dag.trim_optimal_weight()
Expand Down Expand Up @@ -59,7 +59,7 @@ trees = [tree for tree in dag]

# Another method for fetching all trees in the dag is provided, but the order
# will not match index order:
scrambled_trees = list(dag.get_trees())
scrambled_trees = list(dag.get_histories())


# Union is implemented as dag merging, including with sequences of dags
Expand All @@ -74,7 +74,7 @@ newdag = dag[0] | (dag[i] for i in range(3,5))
* `history_dag_from_newicks`
* `history_dag_from_etes`
* Trees can be extracted from the history DAG with methods like
* `HistoryDag.get_trees`
* `HistoryDag.get_histories`
* `HistoryDag.sample`
* `HistoryDag.to_ete`
* `HistoryDag.to_newick` and `HistoryDag.to_newicks`
Expand Down
27 changes: 14 additions & 13 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ A history DAG is a way to represent a collection of trees whose nodes
sequence.

In its simplest form, a history DAG may represent a single tree. To construct
such a history DAG from a tree, we annotate each node in the tree with its child clades.
The **clade** beneath a tree node is the set of leaf node labels
such a history DAG from a tree, we annotate each node in the tree with its
child clades. The **clade** beneath a tree node is the set of leaf node labels
reachable from that node, or the set containing the node's own label if it is
itself a leaf. The **child clades** of a node are the set of clades
beneath that node's children.
itself a leaf. We also refer to this set as a node's **clade union**, since it
is the union of the node's child clades. The **child clades** of a node are the
set of clades beneath that node's children.

After annotating each node with its child clades, a **UA (universal ancestor)
node** is added as a parent of the original tree's root node. The resulting
structure is an example of a history DAG which we call a **clade tree**:
structure is an example of a history DAG which we call a **history**:

|pic1| -> |pic2|

Expand All @@ -35,13 +36,13 @@ parent node associated to an edge, must be the same as the clade below the
child node that the edge targets.

After converting multiple trees with the same set of leaf labels to clade
trees, those clade trees can be unioned to create a history DAG that represents
trees, those histories can be unioned to create a history DAG that represents
at least those trees used to create it. Any structure in the resulting history
DAG which contains the UA node and all leaves, and has exactly one edge for
each node-child clade pair, is a clade tree. Clade trees represent labeled
each node-child clade pair, is a history. Histories represent labeled
trees by the inverse of the correspondence introduced above:

For example, the clade tree highlighted in red in this image:
For example, the history highlighted in red in this image:

.. image:: figures/history_dag_example.svg
:width: 100%
Expand Down Expand Up @@ -105,7 +106,7 @@ Now, we will create a history DAG using the ``sequence`` attribute as the data
for node labels:

>>> dag = hdag.history_dag_from_etes(ete_trees, ['sequence'])
>>> dag.count_trees()
>>> dag.count_histories()
1041
>>> dag.count_topologies()
389
Expand All @@ -132,9 +133,9 @@ of ``explode_nodes``).
We can find even more new trees by adding all edges which connect
nodes whose child clades are compatible:

>>> dag.add_all_allowed_edges()
>>> dag.make_complete()
1048
>>> dag.count_trees()
>>> dag.count_histories()
3431531

After such edge additions, all the trees in the DAG are no longer guaranteed to
Expand Down Expand Up @@ -191,7 +192,7 @@ Now we can trim to only the trees with 48 unique node labels:

>>> dag.trim_optimal_weight(** node_count_funcs, optimal_func=min)

Finally, we can sample a single clade tree from the history DAG, and make it an
Finally, we can sample a single history from the history DAG, and make it an
ete tree for further rendering/processing:

>>> t = dag.sample().to_ete()
Expand All @@ -208,7 +209,7 @@ index-order:
Another method for fetching all trees in the dag is provided, but the order
will not match index order:

>>> scrambled_trees = list(dag.get_trees())
>>> scrambled_trees = list(dag.get_histories())


History DAGs can be merged using the :meth:`historydag.HistoryDag.merge`
Expand Down
2 changes: 1 addition & 1 deletion historydag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from_newick,
history_dag_from_newicks,
history_dag_from_etes,
history_dag_from_clade_trees,
history_dag_from_histories,
)

from . import _version
Expand Down
Loading

0 comments on commit 0122aef

Please sign in to comment.