I've thought about it a bit, and I wonder if this is a better solution.... instead of expecting nodes of the tree structure to be able to work with many different possible types, rather using dictionaries that pair a set of nodes with one type of data are better:
type TreeAnnotations{T} x::Phylogeny dict::Dict{PhyNode, T} end So if you have a load of DNA data, you could annotate the tree by having the dict associate PhyNodes with Ts - in this case DNA sequence types. Then if you had some other data like comments, you'd make another such dictionary, where T would be String, and so on. Best, Ben. On Tuesday, February 24, 2015 at 1:30:57 AM UTC, Ben Ward wrote: > > Hi, > > In Julia, if you are not sure of an arguments type beforehand, you can use > 'Any', or if you know it comes under an abstract type, you can use that. > > I've been working on a type for BioJulia which allows for representation > of a node of a phylogenetic tree that will allow annotation with biological > data in the form of other types from the packages from BioJulia: > > @doc """ > PhyExtension allows defining arbitrary metadata to annotate nodes. > > > This allows the PhyNode type to support any phylogenetic tree format > that includes annotations (e.g. PhyloXML, NeXML), and allows programmatic > extension of nodes with annotations. > """ -> > type PhyExtension{T} > value::T > end > > > @doc """ > PhyNode represents a node in a phylogenetic tree. > > > A node can have: > > > - `name` > - `branchlength` > - one or more `extensions` > - a reference to its `parent` PhyNode > - reference to one or more `children` > """ -> > type PhyNode > name::String > branchlength::Float64 > confidence::Float64 > extensions::Vector{PhyExtension} > children::Vector{PhyNode} > parent::PhyNode > # Inner constructor goes here. > > As you can see - PhyExtension is parametric so can be constructed to > contain any type. > > I'm wondering, though is this the best that can be done, can I handle the > potential to hold any number of types with unknown variables any better - > if so, how? > > Is specifying a Vector of PhyExtension, where a PhyExtenision is a type > that contains any other type really giving that much information to the > Julia system to work on efficiently? > > My understanding is that PhyExtension is parametric so a version is > effectively defined for every possible {T} (including user defined > composite types they might come up with). But then I imagine that's not > much information when creating the Vector{PhyExtension} as an element could > be any of the many possible PhyExtensions - the compiler has to allow for > an array that can store any PhyExtension? Or is it that the array contains > references to PhyExtensions so actually the array is simple? > > Thanks, > Ben. >