AbstractGenealogy

Types

Moonshine.AbstractGenealogy — Type
abstract type AbstractGenealogy <: Graphs.SimpleGraphs.AbstractSimpleGraph{Int32}

Abstract type for genealogies.

Implements the Graphs.jl interface so that subtypes implementing the AbstractGenealogy interface can additionally be treated as regular graphs.

Tree & Arg are subtypes that implement the AbstractGenealogy interface.

source
Moonshine.EdgesInterval — Type
struct EdgesInterval{T, I, E} <: Moonshine.AbstractEGIterTD

Flexible edge iterators that supports various constraints.

Possible constraints are any combination of the following:

  • An interval of genetic positions. Any non-ancestral edge is ignored.
  • A minimum latitude. Any edge under that latitude is ignored. An edge e is considered under a latitude l if latitude(genealogy, dst(e)) < l.
  • A set of predicates. If any of the predicates evaluate to true for a given edge, that edge is ignored.

Do not construct directly, use edges_interval instead.

Fields

  • genealogy::Any: Genealogy to iterate over
  • ωs::Any: Interval to consider
  • stack::CheapStack: Edges buffer
  • visited::UnsafeArrays.UnsafeArray{Bool, 1}: True is associated recombination vertex has been visited previously
  • min_latitude::Float64: Only consider edges located above this latitude

Constructors

EdgesInterval(genealogy, ωs, stack, visited, min_latitude)EdgesInterval{T, I, E}(    genealogy,    ωs,    stack,    visited,    min_latitude)

defined at src/Genealogy.jl:1413.

EdgesInterval(    genealogy,    ωs,    store_ptr,    visited,    min_latitude,    root)

defined at src/Genealogy.jl:1435.

–Internal–

source

Edge Iteration

Moonshine.AbstractEGIter — Type
abstract type AbstractEGIter <: Graphs.AbstractEdgeIter

Iterator over the edges of a genealogy.

Implementation

The block_predicate method allows for early termination. Its default implementation always return true.

–Internal–

source
Moonshine.EIterTD — Function
EIterTD(
    EITD,
    genealogy,
    ωs,
    store_ptr,
    visited,
    bp_pars,
    root
)

defined at src/Genealogy.jl:1262.

Helper for constructing instances of subtypes of AbstractEGIterTD.

Arguments

  • EITD: type to instantiate
  • genealogy: a genealogy
  • ωs: ancestral interval
  • store_ptr: pointer to a container for edges
  • visited: array of boolean values; the kth entry is true if the kth recombination vertex has been visited
  • bp_pars: parameters for the block predicate
  • root: source edge of the initial edge

–Internal–

source
Moonshine.EIterBU — Function
EIterBU(
    EIBU,
    genealogy,
    ωs,
    store_ptr,
    visited,
    roots,
    bp_pars...
)

defined at src/Genealogy.jl:1339.

Helper for constructing instances of subtypes of AbstractEGIterBU.

Arguments

  • EIBU: type to instantiate
  • genealogy: a genealogy
  • ωs: ancestral interval
  • store_ptr: pointer to a container for edges
  • visited: array of boolean values; the kth entry is true if the kth coalescence vertex has been visited
  • roots: destination vertices of the initial edges
  • bp_pars: parameters for the block predicate

–Internal–

source

Functions

Interface

AbstractGenealogy interface. Subtypes must implement every method unless otherwise specified.

General

Moonshine.dens — Function
dens(genealogy; logscale = false)

Likelihood of a genealogy.

Implementation

Only mandatory if copulas are to be fitted on the genealogy.

Methods

dens(tree; logscale)dens(arg; logscale)

defined at src/genealogy_common.jl:58.

source

Vertices/Edges

Moonshine.latitudes — Function
latitudes(genealogy[, vs])

Return the latitudes of (a subset of) the internal vertices of a genealogy.

See also latitude to get the latitude of a single vertex.

Implementation

A default implementation for latitudes(::AbstractGenealogy, ::Any) is available; only latitudes(::T) is required.

Methods

latitudes(genealogy, vs)

defined at src/Genealogy.jl:88.

latitudes(tree)latitudes(arg)

defined at src/genealogy_common.jl:33.

source
Moonshine.leaves — Function
leaves(genealogy)

Return an interable containing the leaves of a genealogy.

See also ivertices for internal vertices and nleaves for the number of leaves.

Implementation

Default implementations assume that the first nleaves(genealogy) vertices are the leaves of the genealogy. If this is the case for your type, you do not need to implement this method.

source
Moonshine.ivertices — Function
ivertices(genealogy)

Return an interable containing the internal vertices of a genealogy.

See also leaves for leaves and nivertices for the number of leaves and internal vertices.

Implementation

Default implementations assume that the first nleaves(genealogy) vertices are the leaves of the genealogy. If this is the case for your type, you do not need to implement this method.

source

Sequences

Moonshine.sequences — Function
sequences(genealogy[, e])
sequences(genealogy[, vs])

Sequences of a genealogy. If an edge is specified, return the sequences associated with the vertices incident to that edge. If an iterable of vertices is specified, return the sequences associated with these vertices.

See also sequence to get the sequence associated with a vertex.

Implementation

Custom types only need to implement sequences(::T).

Methods

sequences(genealogy, vs)

defined at src/Genealogy.jl:160.

sequences(genealogy, e)

defined at src/Genealogy.jl:162.

sequences(s)

defined at src/Sample.jl:325.

sequences(tree)sequences(arg)

defined at src/genealogy_common.jl:33.

source

Ancestrality

Coalescences

Recombinations

Plotting

General

Vertices/Edges

Moonshine.branchlength — Function
branchlength(genealogy)
branchlength(genealogy, ωs)
branchlength(genealogy, e)

Total branch length of a genealogy. If an interval is specified, returns the branch length of the associated marginal genealogy. If an edge is specified, returns the length of that edge.

Methods

branchlength(genealogy, e)

defined at src/Genealogy.jl:699.

branchlength(genealogy)

defined at src/Genealogy.jl:702.

branchlength(genealogy, ωs; buffer)

defined at src/Genealogy.jl:705.

branchlength(genealogy, s, d)

defined at src/Genealogy.jl:1192.

source
Moonshine.edges_interval — Function
edges_interval(genealogy, ωs)
edges_interval(genealogy, ωs, buffer, visited, root = mrca(genealogy), min_latitude = zero(Float64), block_predicates = [])

Iterage over a genealogy's edges via EdgesInterval.

buffer can be either a CheapStack or an UnsafeArray that will be used as buffer for a newly constructed CheapStack.

Methods

edges_interval(    genealogy,    ωs,    store_ptr,    visited;    root,    min_latitude)

defined at src/Genealogy.jl:1457.

edges_interval(genealogy, ωs)

defined at src/Genealogy.jl:1473.

edges_interval(genealogy, x)

defined at src/Genealogy.jl:1483.

source
Moonshine.edgesmap — Function
edgesmap(genealogy)

Return a Dict that maps every edge of a genealogy to an integer in 1:ne(genealogy).

source
Moonshine.nlive! — Function
nlive!(counts, genealogy, lats, edges_iterator)

Number of live edges in a (marginal) genealogy at specified latitudes. Counts are stored in counts, which is initially filled with zeros. Graph traversal is performed downward from the mrca.

Methods

nlive!(counts, genealogy, lats, edges_iterator)

defined at src/Genealogy.jl:1516.

source

Sequences

Moonshine.sequence — Function
sequence(genealogy, v)

Sequence of a genealogy associated with a vertex.

See also sequences to get all the sequences of a genealogy.

source
Moonshine.nmutations — Function

Number of mutation on a genealogy. If an edge is specified, return the number of mutations on that edge.

source

Ancestrality

Moonshine.dads — Function
dads(genealogy, v[, ωs])

Parents of a vertex, optionally restricted to a marginal genealogy. If you know in advance that v has a single dad, use dad instead.

The following rules are used to decide if an edge e is ancestral:

  • If ωs is a number, the ancestral interval of e must cover ωs.
  • If ωs is an Ω or a set of Ωs, the intersection of the ancestral interval of e with ωs must be non-empty.
Danger

Return a reference to the underlying adjacency lists. No touchy!

See also child, children, sibling, siblings, descendants and ancestors.

Methods

dads(arg, v, ωs)dads(arg, v, ωs)dads(arg, v, ωs)

defined at src/Arg/Arg.jl:154.

dads(genealogy, v)

defined at src/Genealogy.jl:832.

source
Moonshine.children — Function
children(genealogy, v[, ωs])

Children of a vertex, optionally restricted to a marginal genealogy. If you know in advance that v has a single child, use child instead.

The following rules are used to decide if an edge e is ancestral:

  • If ωs is a number, the ancestral interval of e must cover ωs.
  • If ωs is an Ω or a set of Ωs, the intersection of the ancestral interval of e with ωs must be non-empty.
Danger

Return a reference to the underlying adjacency lists. No touchy!

See also dad, dads, sibling, siblings, descendants and ancestors.

Methods

children(arg, v, ωs)children(arg, v, ωs)children(arg, v, ωs)

defined at src/Arg/Arg.jl:154.

children(genealogy, v)

defined at src/Genealogy.jl:832.

source
Moonshine.ancestors — Function
ancestors(genealogy, v[, ωs])
ancestors(genealogy, v[, ωs], buf_ptr)

Ancestors of a vertex, optionally restricted to a marginal genealogy.

A pointer to some kind of buffer (an array for instance) can be provided to avoid allocation. In that case, an UnsafeArray wrapped around it will be returned.

The following rules are used to decide if an edge e is ancestral:

  • If ωs is a number, the ancestral interval of e must cover ωs.
  • If ωs is an Ω or a set of Ωs, the intersection of the ancestral interval of e with ωs must be non-empty.

See also child, dad, children, dads, sibling, siblings and descendants.

Methods

ancestors(genealogy, v)

defined at src/Genealogy.jl:923.

ancestors(genealogy, v, ω)

defined at src/Genealogy.jl:955.

source
Moonshine.descendants — Function
descendants(genealogy, v[, ωs])
descendants(genealogy, v[, ωs], buf_ptr)

Descendants of a vertex, optionally restricted to a marginal genealogy.

A pointer to some kind of buffer (an array for instance) can be provided to avoid allocation. In that case, an UnsafeArray wrapped around it will be returned.

The following rules are used to decide if an edge e is ancestral:

  • If ωs is a number, the ancestral interval of e must cover ωs.
  • If ωs is an Ω or a set of Ωs, the intersection of the ancestral interval of e with ωs must be non-empty.

See also child, dad, children, dads, sibling, siblings and ancestors.

Methods

descendants(genealogy, v)

defined at src/Genealogy.jl:923.

descendants(genealogy, v, ω)

defined at src/Genealogy.jl:955.

source
Moonshine.siblings! — Function
siblings!(x, genealogy, v[, u], args)

Siblings of a vertex, that is the other vertices in the genealogy that share at least one parent, optionally restricted to a marginal genealogy.

If you know in advance that v has a single sibling, you can use sibling instead.

As a convenience, siblings! returns an UnsafeArray wrapping pointer x.

See also child, dad, children, dads, descendants and ancestors.

Methods

siblings!(x, genealogy, v, u, ancargs)

defined at src/Genealogy.jl:997.

siblings!(x, genealogy, v, ancargs)

defined at src/Genealogy.jl:1009.

Arguments

  • x: pointer to preallocated memory
  • genealogy: a genealogy
  • v: vertex for which siblings should be computed
  • u: parent with respect to which siblings should be computed
  • args: arguments for dads/children calls
source
Moonshine.siblings — Function
siblings(genealogy, v[, u], args)

This is the allocating version of siblings!.

Note that siblings! is way more efficient than its allocating counterpart. It should be used in any performance sensitive code. siblings is mainly intended for interactive use and quick-and-dirty testing.

Methods

siblings(genealogy, v, u, ancargs)

defined at src/Genealogy.jl:1046.

siblings(genealogy, v, ancargs)

defined at src/Genealogy.jl:1053.

Arguments

  • genealogy: a genealogy
  • v: vertex for which siblings should be computed
  • u: parent with respect to which siblings should be computed
  • args: arguments for dads/children calls
source
Moonshine.sibling — Function
sibling(genealogy, v[, u], args)

Sibling of a vertex, that is the other vertex in the genealogy that have the same parent. It only makes sense to use this method if you know v has a single sibling. Otherwise use siblings!.

See also child, dad, children, dads, descendants and ancestors.

Methods

sibling(genealogy, v, args)

defined at src/Genealogy.jl:1084.

sibling(genealogy, v, u, args)

defined at src/Genealogy.jl:1094.

Arguments

  • genealogy: a genealogy
  • v: vertex for which siblings should be computed
  • u: parent with respect to which siblings should be computed
  • args: arguments for dads/children calls
source

Visualization

Moonshine.lorax — Function
lorax([x; host = "127.0.0.1", port = 3000])

Visualize ancestries interactively with Lorax.

x can either be an AbstractGenealogy or the path to a file in a format supported by Lorax. If argument x is missing, Lorax is launched in interactive mode.

host and port default to Lorax default values, see https://lorax.ucsc.edu/documentation.

Example

arg = Arg(Xoshiro(42), 10, 1e-7, 1e-7, 10000, 1e6)
build!(Xoshiro(666), arg)
lorax(arg)
source
Moonshine.plot_genealogy — Function
plot_genealogy(genealogy[, ω]; kwargs...)

Plot a genealogy.

Only edges and vertices ancestral for ω are plotted.

Implemented as an extension to Moonshine.jl. To use this method, you have to import GraphMakie (and a Makie backend).

See also plot_layout.

Arguments

  • wild_color (:blue): color of wild vertices, that is those having only wild markers in ω.
  • derived_color (:red): color of derived (non-wild) vertices
  • arrow_show (false): whether or not to draw arrows
  • edge_color (:gray): color of edges
  • edge_width (3): width of edges
  • layout (plot_layout(genealogy)): layout function
  • attributes...: attributes passed directly to GraphMakie.graphplot
source

Other