LineageTree

public final class LineageTree

The LineageTree reference type manages a collection of nodes representing the lineage items associated with a particular set of taxa, and can be used to perform calculations based on the relationship between these taxa.

  • The Node type represents a particular taxon in the lineage tree and holds references to both its parent and its children (if any).

    See more

    Declaration

    Swift

    public class Node : TaxonRepresenting, Hashable, CustomDebugStringConvertible
  • Returns the tree’s root node. This node’s identifier is -1, its name is set to origin and its rank property to TaxonomicRank.origin.

    Declaration

    Swift

    public private(set) var rootNode: LineageTree.Node
  • Initializes a new empty tree containing the root node only.

    Declaration

    Swift

    public init()
  • Registers a given taxon with all its lineage items in the lineage tree and returns the node that was created to represent it.

    Declaration

    Swift

    @discardableResult
    public func register(_ taxon: Taxon) -> Node

    Parameters

    taxon

    The taxon to be registered. If the supplied taxon is already registered in the tree, this method does nothing.

    Return Value

    A LineageTree.Node object that represents the supplied taxon.

  • Returns the node that represents a given taxon in the tree.

    Declaration

    Swift

    public func node<T>(for taxon: T) -> Node? where T : TaxonRepresenting

    Parameters

    taxon

    The taxon-representing object whose identifier will be looked for.

    Return Value

    The node that represents taxon in the tree or nil if there is no registered node for the taxon.

  • Returns the number of nodes managed by this tree (including the ones representing the registered taxa’s lineages).

    Declaration

    Swift

    public var nodeCount: Int { get }
  • Returns a set with every node registered in the tree (including their full lineage)

    Declaration

    Swift

    public var allNodes: Set<Node> { get }
  • Returns a set containing the registered nodes that have no children.

    Declaration

    Swift

    public var endPoints: Set<Node> { get }
  • Evaluates whether the tree contains a node representing a given taxon by comparing their identifiers.

    Declaration

    Swift

    public func contains<T>(taxon: T) -> Bool where T : TaxonRepresenting

    Parameters

    taxon

    The taxon-representing object whose identifier will be looked for.

    Return Value

    true if the tree contains a node for the given taxon or false instead.

  • Evaluates whether the tree contains a node representing every taxon in a given set by comparing their identifiers.

    Declaration

    Swift

    public func contains<T>(taxa: Set<T>) -> Bool where T : TaxonRepresenting

    Parameters

    taxa

    The taxa-representing object set whose identifiers will be looked for.

    Return Value

    true if the tree contains a node for every given taxon or false instead.

  • Returns the deepest ancestor common to all elements in a given taxa set.

    Throws

    TaxonomyError.unregisteredTaxa when any of the specified taxa was not registered, or TaxonomyError.insufficientTaxa when less than 2 taxa were passed.

    Declaration

    Swift

    public func closestCommonAncestor<T>(for taxa: Set<T>) throws -> Node where T : TaxonRepresenting

    Parameters

    taxa

    The taxa to be evaluated.

    Return Value

    The deepest ancestor common to all elements in a given taxa set. If no common ancestor can be found, the LineageTree’s rootNode is returned.