Skip to content

Commit

Permalink
internal and external nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
jangevaare committed Oct 12, 2017
1 parent 698e516 commit 00a9eab
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Branches have `Float64` lengths
We can quickly look at the nodes present in our `Tree`:

> collect(exampletree.nodes)

[unattached node]
[branch 1]-->[internal node]-->[branch 2]
[branch 2]-->[leaf node]
Expand All @@ -64,13 +64,13 @@ There are many other functions available that are helpful when dealing with tree
`outdegree`,
`isroot`,
`isleaf`,
`isnode`,
`isinternal`,
`findroots`,
`findleaves`,
`findnodes`,
`findinternal`,
`findnonroots`,
`findnonleaves`,
`findnonnodes`,
`findexternal`,
`areconnected`,
`nodepath`,
`branchpath`,
Expand Down
6 changes: 3 additions & 3 deletions src/PhyloTrees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ module PhyloTrees
outdegree,
isroot,
isleaf,
isnode,
isinternal,
findroots,
findroot,
findleaves,
findnodes,
findinternals,
findexternals,
findnonroots,
findnonleaves,
findnonnodes,
areconnected,
nodepath,
branchpath,
Expand Down
36 changes: 18 additions & 18 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ end


"""
isnode(tree::Tree,
node::Int64)
isinternal(tree::Tree,
node::Int64)
Determine if a `Node` is an internal `Node`
"""
function isnode(tree::Tree,
node::Int64)
function isinternal(tree::Tree,
node::Int64)
if outdegree(tree, node) > 0 && indegree(tree, node) == 1
return true
else
Expand Down Expand Up @@ -145,14 +145,14 @@ end


"""
findnodes(tree::Tree)
findinternals(tree::Tree)
Find the internal `Node`s of a `Tree`
"""
function findnodes(tree::Tree)
function findinternals(tree::Tree)
nodes = Int64[]
for i in keys(tree.nodes)
if isnode(tree, i)
if isinternal(tree, i)
push!(nodes, i)
end
end
Expand Down Expand Up @@ -202,21 +202,21 @@ end


"""
findnonnodes(tree::Tree)
findexternals(tree::Tree)
Find the non-internal `Node`s of a `Tree`
Find the external `Node`s of a `Tree`
"""
function findnonnodes(tree::Tree)
nonnodes = Int64[]
function findexternals(tree::Tree)
externals = Int64[]
for i in keys(tree.nodes)
if !isnode(tree, i)
push!(nonnodes, i)
if !isinternal(tree, i)
push!(externals, i)
end
end
if length(nonnodes) == 0
warn("No non-internal nodes detected")
if length(externals) == 0
warn("No external nodes detected")
end
return nonnodes
return externals
end


Expand Down Expand Up @@ -312,7 +312,7 @@ nodepath(tree::Tree,
function nodepath(tree::Tree,
node::Int64)
path = [node]
while isleaf(tree, path[end]) || isnode(tree, path[end])
while isleaf(tree, path[end]) || isinternal(tree, path[end])
push!(path, parentnode(tree, path[end]))
end
return path
Expand Down Expand Up @@ -414,7 +414,7 @@ Branch pathway through which a specified node connects to a root
function branchpath(tree::Tree,
node::Int64)
path = Int64[]
while isleaf(tree, node) || isnode(tree, node)
while isleaf(tree, node) || isinternal(tree, node)
push!(path, tree.nodes[node].in[1])
node = tree.branches[path[end]].source
end
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ branch!(g, 1, 5.0)
branch!(g, 2, 20.0)

@test length(findroots(g)) == 1
@test length(findleaves(g)) - 1 == length(findnodes(g))
@test length(findleaves(g)) - 1 == length(findinternals(g))

for i = 1:length(g.nodes)
@test length(g.nodes[i].out) <= 2
Expand All @@ -22,4 +22,4 @@ end
@test distance(g, 1, 4) == 30.0
@test distance(g, 4, 3) == 35.0

@test sum(distance(g)) > 0.
@test sum(distance(g)) > 0.

0 comments on commit 00a9eab

Please sign in to comment.