internal documentation

Documentation for PhyloPlots's internal functions. Those functions are not exported, but can still be used (like: PhyloPlots.foo() for a function named foo()).

index

functions

PhyloPlots.check_nodedataframeMethod
check_nodedataframe(net, nodelabel)

Check data frame for node annotations:

  • check that the data has at least 2 columns (if it has any)
  • check that the first column has integers (to serve as node numbers)
  • remove rows with no node numbers
  • warning if some node numbers in the data are not in the network.
source
PhyloPlots.edgenode_coordinatesFunction
edgenode_coordinates(
    net::HybridNetwork,
    useedgelength::Bool,
    usedirecthybridline::Bool,
    majorcurved::Bool,
    preorder::Bool=true,
)

Calculate coordinates of edges segments and node midpoints & segments, that can be used later for plotting.

Actually modifies some (minor) attributes of the network, as it calls directedges! and preorder!, unless with argument preorder=false.

output: tuple with the following elements, in which the order of nodes corresponds to the order in net.node, and the order of edges corresponds to that in net.edge (filtered to minor edges as needed).

  1. edge_xB: x coordinate for the Beginning and ...

  2. edge_xE: ... End of each edge, in the same order as in net.edge

  3. edge_yB: y coordinate for edges, Begin ...

  4. edge_yE: ... and End.

    • Each major edge is drawn as a horizontal line if majorcurved is false, and curved otherwise. This choice affects the beginning yB of hybrid edges; and the node_yB/E interval of node segments, which covers the y positions of a node's children drawn as straight line only.
    • Minor hybrid edges are drawn as:
      • a single diagonal segment (straight or curved) if usedirecthybridline is true,
      • or as 2 connected segments otherwise: one horizontal whose length on the x axis can be used to represent the edge length, and the other diagonal (straight or curved) to connect the horizontal segment to the child node.

    edge_* contains the coordinates for the horizontal segment only, which is reduced to a single point (Begin = End) when usedirecthybridline is true. minoredge_* (see below) contains information for the diagonal segment. Agreed, edge_yB = edge_yE always (relic from before v0.3: no minoredge output back then, and simple diagonal lines only)

  5. node_x: x and ...

  6. node_y: ... y coordinate along the vertical bar that represents a node. The (or each) parent edge of the node connects to this central point, but the node itself is drawn as a vertical bar connected to all it children edges. order: same as in net.node

  7. node_yB: y coordinates of the Beginning and the ...

  8. node_yE: ... End of the vertical bar representing each node. The x coordinate (Begin & End) of the end points of the vertical bar is the same as that of the mid-point, given by node_x.

  9. minoredge_xB: x coordinate for the Beginning and ...

  10. minoredge_xE: ... End of the diagonal segment of each minor hybrid edge, in the same order as in filter(e -> !e.ismajor, net.edge).

  11. minoredge_yB: y coordinate for the beginning and ...

  12. minoredge_yE: ... end of the diagonal segment of each minor hybrid edge.

13-16. xmin, xmax, ymin, ymax: ranges for the x and y axes.

source
PhyloPlots.prepare_edgedataframeMethod
prepare_edgedataframe(net, edgelabel::DataFrame, style::Symbol,
    edge_xB, edge_xE, edge_yB, edge_yE,
    minoredge_xB, minoredge_xE, minoredge_yB, minoredge_yE,
    curved, bend)

Check data frame for edge annotation. edge_*: Float64 vectors giving the coordinates for the beginning and end of edges. Return data frame with columns

  • x, y: coordinates on the plots
  • len: node name
  • gam: gamma (inheritance value)
  • num: node number
  • lab: node label
  • hyb: is hybrid?
  • min: is minor?
source
PhyloPlots.prepare_nodedataframeMethod
prepare_nodedataframe(net, nodelabel::DataFrame,
    shownodenumber::Bool, shownodename::Bool, labelnodes::Bool,
    node_x, node_y)

Make data frame for node annotation. node_* should be Float64 vectors. nodelabel should have columns as required by check_nodedataframe. shownodename is to show the name of internal nodes. Leaf names are always included.

Columns of output data frame:

  • x, y: coordinates on the plots (from node_*)
  • name: node name
  • num: node number
  • lab: node label
  • lea: is leaf?
source
PhyloPlots.quadraticbezier_controlFunction
quadraticbezier_control(x0, y0, x2, y2, bend, rtol=1e-10)

Coordinates of point P1 to serve as middle control point for a quadratic Bézier curve between the anchor points P0 = (x0,y0) and P2 = (x2,y2).

  • P1 = (x0,y2) if x0 ≤ x2, which is most frequent (i.e. when not using branch lengths, or if the network is time-consistent).
  • P1 = (x2,y0) if x0 > x2, which looks like the edge goes back in time.

If P1≈P0 (P0 → P2 is horizontal) or if P1≈P2 (P0 → P2 is vertical), then the Bézier curve is almost straight. In this case:

  • if P1≈P2 (vertical) or if bend is not 0, (missing, missing) is returned
  • if bend==0 and if P1≈P2 (the default Bézier curve would be horizontal), then ((x0+x2)/2, y2 + bend) is returned to force a bend.
source
PhyloPlots.quadraticbezier_midpointMethod
quadraticbezier_midpoint(x0, y0, x2, y2, bend)

Midpoint around the Bézier curve from quadraticbezier_control, with x = (x0+x2)/2. In most cases, the Bézier control point is (x0,y2) and the midpoint is at time t=1/sqrt(2). It is at t=1/2 if a bent is forced to avoid a straight horizontal curve.

source
PhyloPlots.rexportMethod
rexport(net::HybridNetwork; maintree=false, useedgelength=true)

Create an RObject of class phylo (and evonet depending on the number of hybridizations) recognized by the ape library in R (S3 object). This RObject can be evaluated using the tools available in the ape library in R. For example, we can visualize the network using ape's plot function.

not exported: sexp is the best way to go.

Arguments

  • useedgelength: if true, export edge lengths from net.
  • maintree: if true, minor hybrid edges are omitted.

Examples

julia> net = readnewick("(((A,(B)#H1:::0.9),(C,#H1:::0.1)),D);");

julia> phy = PhyloPlots.rexport(net)
RObject{VecSxp}

    Evolutionary network with 1 reticulation

               --- Base tree ---
Phylogenetic tree with 4 tips and 5 internal nodes.

Tip labels:
  A, B, C, D

Rooted; no branch lengths.

julia> using RCall

julia> R"library(ape)";

julia> phy
RObject{VecSxp}

    Evolutionary network with 1 reticulation

               --- Base tree ---
Phylogenetic tree with 4 tips and 5 internal nodes.

Tip labels:
  A, B, C, D

Rooted; no branch lengths.

R> phy

    Evolutionary network with 1 reticulation

               --- Base tree ---
Phylogenetic tree with 4 tips and 5 internal nodes.

Tip labels:
  A, B, C, D

Rooted; no branch lengths.

R> str(phy)
List of 5
 $ Nnode             : int 5
 $ edge              : int [1:8, 1:2] 5 5 6 6 7 8 8 9 6 4 ...
 $ tip.label         : chr [1:4] "A" "B" "C" "D"
 $ reticulation      : int [1, 1:2] 7 9
 $ reticulation.gamma: num 0.1
 - attr(*, "class")= chr [1:2] "evonet" "phylo"
source