Skip to content

Instantly share code, notes, and snippets.

@bicycle1885
Last active April 3, 2016 22:59
Show Gist options
  • Save bicycle1885/4b5a913f42650f0ad8e580828177951d to your computer and use it in GitHub Desktop.
Save bicycle1885/4b5a913f42650f0ad8e580828177951d to your computer and use it in GitHub Desktop.
type PhyNode{I,T<:Tuple}
id::I
metadata::T
children::Vector{PhyNode{I,T}}
parent::PhyNode{I,T}
# root
function PhyNode(id, metadata, children)
node = new(id, metadata, children)
node.parent = node
return node
end
# non-root
function PhyNode(id, metadata, parent, children)
return new(id, metadata, children, parent)
end
end
function PhyNode{I,T}(id::I, metadata::T, children::Vector=[])
return PhyNode{I,T}(id, metadata, children)
end
function PhyNode{I,T}(id::I, metadata::T, parent::PhyNode{I,T}, children::Vector=[])
return PhyNode{I,T}(id, metadata, parent, children)
end
immutable BranchLength data::Float64 end
immutable Confidence data::Float64 end
@generated function branchlength{I,T}(node::PhyNode{I,T})
i = findfirst(T.parameters, BranchLength)
return :(node.metadata[$i].data)
end
@generated function confidence{I,T}(node::PhyNode{I,T})
i = findfirst(T.parameters, Confidence)
return :(node.metadata[$i].data)
end
n = PhyNode(1, (BranchLength(2.3), Confidence(0.9)))
@show branchlength(n)
@show confidence(n)
@code_native branchlength(n)
@code_native confidence(n)
n = PhyNode(2, (Confidence(0.9), BranchLength(2.3)))
@show branchlength(n)
@show confidence(n)
@code_native branchlength(n)
@code_native confidence(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment