Skip to content

Commit

Permalink
Merge pull request #12 from jangevaare/alpha
Browse files Browse the repository at this point in the history
PhyloTrees rewrite using Dicts
  • Loading branch information
jangevaare authored Feb 17, 2017
2 parents 2b38d78 + 8fcd400 commit 2aed689
Show file tree
Hide file tree
Showing 8 changed files with 425 additions and 633 deletions.
94 changes: 14 additions & 80 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,22 @@ To enable plotting, install [Plots.jl](https://github.com/tbreloff/Plots.jl) and

## Usage

### Tree initialization
To initialize a `Tree`, you must declare the data type of each `Node` and `Branch`:

> # Node data type
> N = Float64
>
> # Branch data type
> B = Void
>
There are several ways to add nodes and branches to our `Tree`, see below for examples

> # Initialize the tree
> exampletree = Tree{N, B}()
> exampletree = Tree()

Phylogenetic tree with 0 nodes and 0 branches

### The basics
There are several ways to add nodes and branches to our `Tree`, see below for examples

> # Add a node to the tree
> addnode!(exampletree)

Phylogenetic tree with 1 nodes and 0 branches

> # Add a node, connect it to node 1 with a branch
> branch!(exampletree, 1)
Branches have `Float64` lengths

> # Add a node, connect it to node 1 with a branch 5.0 units in length
> branch!(exampletree, 1, 5.0)

Phylogenetic tree with 2 nodes and 1 branches

Expand All @@ -45,81 +37,29 @@ There are several ways to add nodes and branches to our `Tree`, see below for ex

Phylogenetic tree with 4 nodes and 1 branches

> # Connect node 3 to node 2
> addbranch!(exampletree, 2, 3)
> # Add a branch from node 2 to node 3 10.0 units in length
> addbranch!(exampletree, 2, 3, 10.0)

Phylogenetic tree with 4 nodes and 2 branches

### Nodes

We can quickly look at the nodes present in our `Tree`:

> exampletree.nodes
4-element Array{PhyloTrees.Node{Float64},1}:
[root node]-->[branch 1]
> collect(exampletree.nodes)

[unattached node]
[branch 1]-->[internal node]-->[branch 2]
[branch 2]-->[leaf node]
We can label nodes:

> # Set a label for node 1
> setlabel!(exampletree.nodes[1], "Test label")
[branch 2]-->[leaf node]
[root node]-->[branch 1]

> # Test if node 1 now has a label
> haslabel(exampletree.nodes[1])
true

> # Get the label of node 1
> getlabel(exampletree.nodes[1])
"Test label"

> # Create a labelled node
> addnode!(exampletree, "Another test label")
Phylogenetic tree with 5 nodes and 2 branches

Node data is contained in a `Nullable{N}` field named `data`:

> node 1
> exampletree.nodes[1].data
Nullable{Float64}()

> Get the data in node 1
> getdata(exampletree.nodes[1])
ERROR: NullException()

### Branches

Branches have `Float64` lengths

> # Add a branch of length 10.0 from node 2 to 4
> addbranch!(exampletree, 2, 4, 10.0)
Phylogenetic tree with 5 nodes and 3 branches

> Retrieve the length of branch 3
> exampletree.branches[3].length
10.0

Branches are not labelled, but they do have a `Nullable{B}` field named `data`:

> Get the data in branch 1
> getdata(exampletree.branches[1])
ERROR: NullException()

### Other capabilities

Distance between nodes can be calculated using the `distance` function. A node visit ordering for postorder traversal of a tree can be found with `postorder`.

Trees can be plotted using `plot`.

There are many other functions available that are helpful when dealing with trees including:
`addsubtree!`,
`subtree`,
`changesource!`,
`changetarget!`,
`validnode`,
`validnodes`,
`validbranch`,
`validbranches`,
`indegree`,
`outdegree`,
`isroot`,
Expand All @@ -140,10 +80,4 @@ There are many other functions available that are helpful when dealing with tree
`descendantnodes`,
`ancestorcount`,
`ancestornodes`, and
`nodetype`,
`haslabel`,
`setlabel!`,
`getlabel`,
`hasdata`,
`setdata!`,
`getdata`
`nodetype`
17 changes: 4 additions & 13 deletions src/PhyloTrees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@ module PhyloTrees
addnodes!,
addbranch!,
branch!,
addsubtree!,
subtree,
changesource!,
changetarget!,
validnode,
validnodes,
validbranch,
validbranches,
deletenode!,
deletebranch!,
indegree,
outdegree,
isroot,
Expand All @@ -53,12 +49,6 @@ module PhyloTrees
ancestorcount,
ancestornodes,
nodetype,
setlabel!,
haslabel,
getlabel,
setdata!,
hasdata,
getdata,

# Distance
distance,
Expand All @@ -67,8 +57,9 @@ module PhyloTrees
postorder

# Package files
include("core.jl")
include("structure.jl")
include("show.jl")
include("construction.jl")
include("utilities.jl")
include("distance.jl")
include("traversal.jl")
Expand Down
Loading

0 comments on commit 2aed689

Please sign in to comment.