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.
Moonshine.EdgesInterval — Type
struct EdgesInterval{T, I, E} <: Moonshine.AbstractEGIterTDFlexible 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
eis considered under a latitudeliflatitude(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–
Edge Iteration
Moonshine.AbstractEGIter — Type
abstract type AbstractEGIter <: Graphs.AbstractEdgeIterIterator over the edges of a genealogy.
Implementation
The block_predicate method allows for early termination. Its default implementation always return true.
–Internal–
Moonshine.AbstractEGIterTD — Type
abstract type AbstractEGIterTD <: Moonshine.AbstractEGIterTop-down edge iteration.
See also AbstractEGIterBU, block_predicate.
Implementation
Subtypes instances can be constructed with a call to EIterTD.
–Internal–
Moonshine.AbstractEGIterBU — Type
abstract type AbstractEGIterBU <: Moonshine.AbstractEGIterBottom-up edge iteration.
See also AbstractEGIterTD, block_predicate.
Implementation
Subtypes instances can be constructed with a call to EIterBU.
–Internal–
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 instantiategenealogy: a genealogyωs: ancestral intervalstore_ptr: pointer to a container for edgesvisited: array of boolean values; the kth entry is true if the kth recombination vertex has been visitedbp_pars: parameters for the block predicateroot: source edge of the initial edge
–Internal–
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 instantiategenealogy: a genealogyωs: ancestral intervalstore_ptr: pointer to a container for edgesvisited: array of boolean values; the kth entry is true if the kth coalescence vertex has been visitedroots: destination vertices of the initial edgesbp_pars: parameters for the block predicate
–Internal–
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.
Moonshine.describe — Function
describe(genealogy, long = true)Return a string containing a long or short description of a genealogy. Used internally by pretty printing functions.
Methods
describe(::Arg)describe(::Arg, long)defined at src/Arg/Arg.jl:104.
describe(::Tree)describe(::Tree, long)defined at src/Tree.jl:85.
Moonshine.graph — Function
graph(genealogy)Return the underlying graph of a genealogy.
Methods
graph(tree)graph(arg)defined at src/genealogy_common.jl:33.
Moonshine.block_predicate — Function
block_predicate(edge_iterator, edge)Returns true if edge should be iterated over.
See also AbstractEGIter.
–Internal–
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.
Moonshine.latitude — Function
latitude(genealogy, v)Latitude of a vertex.
See also latitudes to get the latitudes of internal vertices stored in a genealogy.
Methods
latitude(tree, v)latitude(arg, v)defined at src/genealogy_common.jl:52.
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.
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.
Moonshine.maxdads — Function
maxdads(genealogy)Maximum possible number of parents for a vertex. See also maxchildren.
Implementation
Must be a generated function.
Methods
maxdads(::Type{Arg})defined at src/Arg/Arg.jl:138.
maxdads(::T)defined at src/Genealogy.jl:394.
maxdads(::Type{Tree})defined at src/Tree.jl:91.
–Internal–
Moonshine.maxchildren — Function
maxchildren(genealogy)Maximum possible number of children for a vertex. See also maxdads.
Implementation
Must be a generated function.
Methods
maxchildren(::Type{Arg})defined at src/Arg/Arg.jl:140.
maxchildren(::T)defined at src/Genealogy.jl:394.
maxchildren(::Type{Tree})defined at src/Tree.jl:93.
–Internal–
Sequences
Moonshine.positions — Function
positions(genealogy)Positions of the markers.
Methods
positions(sample)defined at src/Sample.jl:248.
positions(tree)positions(arg)defined at src/genealogy_common.jl:37.
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.
Ancestrality
Moonshine.ancestral_intervals — Function
ancestral_intervals(genealogy, x)Interval for which x is ancestral. Default implementation assumes that anything is ancestral for [0, ∞).
See also ancestral_intervals! for a non-allocating alternative.
Methods
ancestral_intervals(arg, e)defined at src/Arg/Arg.jl:207.
ancestral_intervals(arg, v)defined at src/Arg/Arg.jl:220.
ancestral_intervals(genealogy, x)defined at src/Genealogy.jl:222.
Moonshine.ancestral_intervals! — Function
ancestral_intervals!(ωs, genealogy, x)Interval for which x is ancestral. Default implementation assumes that anything is ancestral for [0, ∞).
See also ancestral_intervals.
Methods
ancestral_intervals!(ωs, arg, e; wipe)defined at src/Arg/Arg.jl:199.
ancestral_intervals!(ωs, arg, v; wipe)defined at src/Arg/Arg.jl:209.
ancestral_intervals!(ωs, _, _)defined at src/Genealogy.jl:240.
Moonshine.mrca — Function
mrca(genealogy[, vs = leaves(genealogy), ωs = Ω(0, ∞)])Most recent common ancestor of a set of vertices.
See also tmrca for the time to the most recent common ancestor.
Methods
mrca(arg)defined at src/Arg/Arg.jl:134.
mrca(arg, ωs)defined at src/Arg/Arg.jl:136.
mrca(tree)defined at src/Tree.jl:87.
mrca(tree, _...)defined at src/Tree.jl:89.
mrca(tree, vs, x; buffer)mrca(arg, vs, x; buffer)defined at src/genealogy_common.jl:80.
Coalescences
Moonshine.iscoalescence — Function
iscoalescence(genealogy, v)Returns true if vertex v is a coalescence vertex for genealogy.
Methods
iscoalescence(arg, v)defined at src/Arg/Arg.jl:110.
iscoalescence(tree, v)defined at src/Tree.jl:95.
Recombinations
Moonshine.recombinations — Function
recombinations(genealogy)Iterator over the recombination vertices of a genealogy.
Implementation
Default implementation returns an empty iterator.
Methods
recombinations(arg)defined at src/Arg/Arg.jl:120.
recombinations(_)defined at src/Genealogy.jl:281.
Moonshine.isrecombination — Function
isrecombination(genealogy, v)Returns true if vertex v is a recombination vertex for genealogy.
Default implementation always returns false.
Methods
isrecombination(::Arg, v, n)defined at src/Arg/Arg.jl:106.
isrecombination(arg, v)defined at src/Arg/Arg.jl:108.
isrecombination(_, _)defined at src/Genealogy.jl:297.
Moonshine.nrecombinations — Function
nrecombinations(genealogy)Number of recombinations.
Implementation
Default implementation returns 0.
Methods
nrecombinations(arg)defined at src/Arg/Arg.jl:130.
nrecombinations(arg, ωs)defined at src/Arg/Arg.jl:132.
nrecombinations(_)defined at src/Genealogy.jl:263.
Plotting
Moonshine.plot_layout — Function
plot_layout(genealogy)Layout function for genealogy plotting.
Implementation
Defaults to Spring().
Methods
plot_layout(arg)defined at src/Arg/Arg.jl:182.
plot_layout(::AbstractGenealogy)defined at src/Genealogy.jl:328.
–Internal–
General
Vertices/Edges
Moonshine.nleaves — Function
nleaves(genealogy)Number of leaves in a genealogy.
See also leaves for an iterable over leaves and nivertices for an internal vertices counterpart.
Methods
nleaves(arg)defined at src/Arg/Arg.jl:102.
nleaves(genealogy)defined at src/Genealogy.jl:645.
nleaves(tree)defined at src/Tree.jl:83.
Moonshine.nivertices — Function
nivertices(genealogy)Number of internal vertices in a genealogy.
See also ivertices for an iterable over internal vertices and nleaves for a leaves counterpart.
Moonshine.isleaf — Function
Moonshine.isroot — Function
Moonshine.isivertex — Function
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.
Moonshine.edge — Function
edge([T,] p)Returns a Graphs.Edge with incident vertices of the specified type. Defaults to VertexType if no type is specified.
Methods
edge(T, p)defined at src/Genealogy.jl:549.
edge(p)defined at src/Genealogy.jl:551.
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.
Moonshine.edgesmap — Function
edgesmap(genealogy)Return a Dict that maps every edge of a genealogy to an integer in 1:ne(genealogy).
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.
Moonshine.ismutation_edge — Function
ismutation_edge(genealogy, e, idx)Determines if an edge is a mutation edge for a given marker.
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.
Moonshine.idxtopos — Function
idxtopos(genealogy, idx)Return the position of the marker given its index.
Methods
idxtopos(genealogy, idx)defined at src/Genealogy.jl:427.
idxtopos(sample, idx)defined at src/Sample.jl:257.
Moonshine.postoidx — Function
postoidx(genealogy, pos)Return the largest marker's index that is at a position lesser than the one given.
Methods
postoidx(genealogy, pos)defined at src/Genealogy.jl:427.
postoidx(sample, pos)defined at src/Sample.jl:265.
postoidx(sample, ω)defined at src/Sample.jl:312.
Moonshine.nmarkers — Function
nmarkers(genealogy[, ωs])Number of markers in the sequences of a genealogy. If an interval ωs is specified, returns the number of markers contained in that interval.
Methods
nmarkers(genealogy, ωs...)defined at src/Genealogy.jl:681.
nmarkers(sample)defined at src/Sample.jl:250.
nmarkers(sample, ω)defined at src/Sample.jl:252.
Moonshine.nmutations — Function
Number of mutation on a genealogy. If an edge is specified, return the number of mutations on that edge.
Ancestrality
Moonshine.dad — Function
dad(genealogy, v)Return the parent of a vertex or 0 if none. It only makes sense to use this method if you know v has a single parent. Otherwise use dads.
See also child, descendants, ancestors and siblings.
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
emust cover ωs. - If ωs is an Ω or a set of Ωs, the intersection of the ancestral interval of
ewith ωs must be non-empty.
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.
Moonshine.child — Function
child(genealogy, v)Return the child of a vertex or 0 if none. It only makes sense to use this method if you know v has a single child. Otherwise use children.
See also dad, ancestors, descendants and siblings.
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
emust cover ωs. - If ωs is an Ω or a set of Ωs, the intersection of the ancestral interval of
ewith ωs must be non-empty.
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.
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
emust cover ωs. - If ωs is an Ω or a set of Ωs, the intersection of the ancestral interval of
ewith ω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.
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
emust cover ωs. - If ωs is an Ω or a set of Ωs, the intersection of the ancestral interval of
ewith ω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.
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 memorygenealogy: a genealogyv: vertex for which siblings should be computedu: parent with respect to which siblings should be computedargs: arguments fordads/childrencalls
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 genealogyv: vertex for which siblings should be computedu: parent with respect to which siblings should be computedargs: arguments fordads/childrencalls
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 genealogyv: vertex for which siblings should be computedu: parent with respect to which siblings should be computedargs: arguments fordads/childrencalls
Moonshine.tmrca — Function
tmrca(genealogy[, vs])Time to the most recent common ancestor (MRCA) of (a subset of) vertices.
Methods
tmrca(genealogy)defined at src/Genealogy.jl:730.
tmrca(genealogy, vs)defined at src/Genealogy.jl:737.
tmrca(tree, vs, ωs)tmrca(arg, vs, ωs)defined at src/genealogy_common.jl:105.
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)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) verticesarrow_show(false): whether or not to draw arrowsedge_color(:gray): color of edgesedge_width(3): width of edgeslayout(plot_layout(genealogy)): layout functionattributes...: attributes passed directly toGraphMakie.graphplot
Moonshine.plot_latitudes — Function
plot_latitudes(genealogy; kwargs...)Unicode histogram of a genealogy's latitudes. Additional keywords arguments are passed directly to UnicodePlots.histogram.
Other
Moonshine.ts — Function
ts(genealogy)Convert a genealogy to a tskit.TreeSequence.
Methods
ts(arg)defined at src/Arg/Arg.jl:576.
ts(tree)defined at src/Tree.jl:364.