Defines functions makePhyloTree

Documented in makePhyloTree

#' Make phylogenetic tree (internal)
#' This function is called by \code{\link{getLabGenealogy}} to turn an edge list and corresponding lengths and root node number into a tree of class \code{phylo}
#' @author Caroline Colijn \email{c.colijn@imperial.ac.uk}
#' @author Michelle Kendall \email{michelle.louise.kendall@@gmail.com}
#' @param Edges a two-column matrix representing the edges of a tree. (It corresponds to the $edge entry of a \code{phylo} object, although the rows may not be in an expected order.) In each row the first entry is an internal node and the second entry is one of its immediate descendants.
#' @param Lengths a numeric vector of the same length as the columns of \code{Edges}. Each entry corresponds to the length of that edge.
#' @param Root the number of the internal node which is to be the root (usually the number of tips + 1)
#' @return An object of class \code{phylo}. When called by \code{\link{getLabGenealogy}} this represents the genealogical transmission tree from infectors to infectees.
#' @importFrom igraph graph
#' @importFrom igraph graph.dfs
#' @keywords internal
#' @export
makePhyloTree <- function(Edges, Lengths, Root) {
  G <- graph(edges=t(Edges))
  orderT <- graph.dfs(G,Root)$order
  Edges <- Edges[oE, ]  
  Lengths <-Lengths[oE]
  newEdges <- matrix(NA, nrow(Edges), ncol(Edges)) 
  newEdges[ooT,] <- Edges
  newLengths[ooT]= Lengths
  # newLengths[newLengths==0]=0.01
  Nnode <- (length(orderT)-1)/2;
  Ntips <- Nnode+1; 
  pt <- rtree(Ntips); 
  pt$Nnode <- Nnode; #
  pt$edge <-  newEdges;

Try the phyloTop package in your browser

Any scripts or data that you put into this service are public.

phyloTop documentation built on May 2, 2019, 11:03 a.m.