AbstractGenealogy

Types

Moonshine.AbstractGenealogyType
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.EdgesIntervalType
struct EdgesInterval{T, I, E}

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

  • buffer::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

  • block_predicates::Array{FunctionWrappers.FunctionWrapper{Bool, Tuple{E}}, 1} where E: Edges for which one of the predicates is true are blocked

Constructors

EdgesInterval(
    genealogy,
    ωs,
    buffer,
    visited,
    min_latitude,
    block_predicates
)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:1048.

EdgesInterval(genealogy, ωs, stack, visited)
EdgesInterval(genealogy, ωs, stack, visited, root)
EdgesInterval(
    genealogy,
    ωs,
    stack,
    visited,
    root,
    min_latitude
)
EdgesInterval(
    genealogy,
    ωs,
    stack,
    visited,
    root,
    min_latitude,
    block_predicates
)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:1062.

EdgesInterval(genealogy, ωs, store, visited)
EdgesInterval(genealogy, ωs, store, visited, root)
EdgesInterval(
    genealogy,
    ωs,
    store,
    visited,
    root,
    min_latitude,
    block_predicates
)
EdgesInterval(
    genealogy,
    ωs,
    store,
    visited,
    root,
    min_latitude
)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:1076.

Internal

source

Functions

Interface

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

General

Vertices/Edges

Moonshine.latitudesFunction
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 /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:80.

latitudes(arg)
latitudes(tree)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/genealogy_common.jl:31.

source
Moonshine.leavesFunction
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.iverticesFunction
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.sequencesFunction
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 /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:147.

sequences(genealogy, e)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:149.

sequences(arg)
sequences(tree)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/genealogy_common.jl:31.

source

Ancestrality

Moonshine.ancestral_intervalsFunction
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 /home/runner/work/Moonshine.jl/Moonshine.jl/src/Arg/Arg.jl:191.

ancestral_intervals(arg, v)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Arg/Arg.jl:204.

ancestral_intervals(genealogy, x)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:204.

source
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, simplify)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Arg/Arg.jl:183.

ancestral_intervals!(ωs, arg, v; wipe)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Arg/Arg.jl:193.

ancestral_intervals!(ωs, _, _)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:221.

source
Moonshine.mrcaFunction
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 /home/runner/work/Moonshine.jl/Moonshine.jl/src/Arg/Arg.jl:107.

mrca(arg, ωs)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Arg/Arg.jl:109.

mrca(tree)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Tree.jl:79.

mrca(tree, _)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Tree.jl:81.

mrca(arg, vs, x; buffer)
mrca(tree, vs, x; buffer)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/genealogy_common.jl:77.

mrca(arg, vs)
mrca(tree, vs)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/genealogy_common.jl:101.

source

Recombinations

Plotting

General

Vertices/Edges

Moonshine.branchlengthFunction
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 /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:615.

branchlength(genealogy)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:618.

branchlength(genealogy, ωs; buffer)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:620.

branchlength(genealogy, s, d)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:1020.

source
Moonshine.edges_intervalFunction
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,
    buffer,
    visited,
    root,
    min_latitude;
    block_predicates
)
edges_interval(genealogy, ωs, buffer, visited, root; ...)
edges_interval(genealogy, ωs, buffer, visited; ...)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:1137.

edges_interval(genealogy, ωs)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:1142.

source
Moonshine.edgesmapFunction
edgesmap(genealogy)

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

source
Moonshine.nliveFunction
nlive(genealogy, lat, ωs; block_predicates, buffer)

Number of live edges in a (marginal) genealogy at a given latitude.

block_predicate is passed directly to edges_interval.

See also nlive!.

source
Moonshine.nlive!Function
nlive!(counts, genealogy, lats, ωs[, stack]; block_predicates = [], buffer = default_buffer())

Number of live edges in a (marginal) genealogy at a given latitude.

Counts are stored in counts which is filled with 0s initially. ̀lats must be the same size as counts.

block_predicate and stack are passed directly to edges_interval.

See also nlive.

Methods

nlive!(
    counts,
    genealogy,
    lats,
    ωs,
    stack;
    block_predicates,
    buffer
)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:1208.

nlive!(
    counts,
    genealogy,
    lats,
    ωs;
    block_predicates,
    buffer
)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:1237.

source

Sequences

Moonshine.sequenceFunction
sequence(genealogy, v)

Sequence of a genealogy associated with a vertex.

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

source
Moonshine.nmutationsFunction
nmutations(genealogy[, e])

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

See also nmutations! for a non-allocating alternative.

Methods

nmutations(genealogy)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:1007.

nmutations(genealogy, e)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:1013.

nmutations(genealogy, s, d)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:1020.

source
Moonshine.nmutations!Function
nmutations!(mask, genealogy, e)

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

See also nmutations.

source

Ancestrality

Moonshine.dadsFunction
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 /home/runner/work/Moonshine.jl/Moonshine.jl/src/Arg/Arg.jl:123.

dads(genealogy, v)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:735.

source
Moonshine.childrenFunction
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 /home/runner/work/Moonshine.jl/Moonshine.jl/src/Arg/Arg.jl:123.

children(genealogy, v)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:735.

source
Moonshine.ancestorsFunction
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 /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:822.

ancestors(genealogy, v, ω)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:855.

source
Moonshine.descendantsFunction
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 /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:822.

descendants(genealogy, v, ω)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:855.

source
Moonshine.siblingsFunction
siblings(genealogy, v[, ωs])
siblings(genealogy, v[, ωs], buf_ptr)

Siblings of a vertex, that is the other vertices in the genealogy that share at least one parent, 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.

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

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

Methods

siblings(genealogy, v, args)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:913.

source
Moonshine.ancestral_maskFunction
ancestral_mask(reference, x; ωs_buf = Set{Ω}())

Mask non ancestral positions to 0. If wipe = true, all markers in η will be initialized to 0.

Methods

ancestral_mask(arg, x)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Arg/Arg.jl:224.

ancestral_mask(e, arg)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Arg/Arg.jl:229.

ancestral_mask(genealogy, x)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:392.

ancestral_mask(sample, x)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Sample.jl:326.

source
Moonshine.ancestral_mask!Function
ancestral_mask!(η, reference, x; ωs_buf = Set{Ω}(), wipe = true)

Mask non ancestral positions to 0. If wipe = true, all markers in η will be initialized to 0.

Methods

ancestral_mask!(η, arg, e; wipe)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Arg/Arg.jl:206.

ancestral_mask!(h, arg, v; wipe)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Arg/Arg.jl:209.

ancestral_mask!(η, genealogy, x; wipe)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Genealogy.jl:408.

ancestral_mask!(v, sample, ω; wipe)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Sample.jl:300.

ancestral_mask!(η, sample, ω; wipe)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Sample.jl:310.

ancestral_mask!(η, sample, ωs; wipe)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Sample.jl:316.

ancestral_mask!(η, sample, pos; wipe)

defined at /home/runner/work/Moonshine.jl/Moonshine.jl/src/Sample.jl:329.

source

Plotting

Moonshine.plot_genealogyFunction
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