R/plotMutTree.R

Defines functions plotMutTree

Documented in plotMutTree

#' plotMutTree plots phylogenetic tree of mutations
#'
#' @param maf Maf or MafList object generated by readMaf function.
#' @param patient.id Select the specific patients.
#' @param method Approach to construct phylogenetic trees.
#' Choose one of "NJ"(Neibor-Joining), "MP"(maximum parsimony),
#'  "ML"(maximum likelihood), "FASTME.ols" or "FASTME.bal".
#' @param bootstrap.rep.num Bootstrap iterations. Default 500.
#' @param min.vaf The minimum value of vaf. Default 0.
#' @param group a list that used to indicate the sample groups
#' @param group.colors an array indicates the colors of sample groups.
#' @param title title of the plot.
#' @param hexpand_ratio: hexpand ratio. see \code{\link[ggtree]{hexpand}}
#'
#' @examples
#' library(MesKit)
#' data.type <- "split1"
#'
#' maf <- readMaf(
#'   mafFile = system.file(package = "MPTevol", "extdata", sprintf("meskit.%s.mutation.txt", data.type)),
#'   ccfFile = system.file(package = "MPTevol", "extdata", sprintf("meskit.%s.CCF.txt", data.type)),
#'   clinicalFile = system.file(package = "MPTevol", "extdata", sprintf("meskit.%s.clinical.txt", data.type)),
#'   refBuild = "hg19",
#'   ccf.conf.level = 0.95
#' )
#'
#' # construct a group
#' group <- list(
#'   Coad = paste0("Coad_", 1:5),
#'   OveryLM = paste0("OveryLM_", 1:5),
#'   OveryRM = paste0("OveryRM_", 1:6),
#'   UterusM = paste0("UterusM_", c(1, 3))
#' )
#'
#' plotMutTree(maf, patient.id = "Met1", group = group, title = "CRC Met")
#' @param ... parameters in the getPhyloTree function.
#'
#' @export

plotMutTree <- function(maf,
                        patient.id,
                        method = "NJ",
                        min.vaf = 0.02,
                        bootstrap.rep.num = 500,
                        group = NULL,
                        group.colors = NULL,
                        title = "cancer",
                        hexpand_ratio = 0.3,
                        ...) {
  message("Building trees")
  phyloTree <- MesKit::getPhyloTree(maf,
    patient.id = patient.id,
    method = method, min.vaf = min.vaf,
    bootstrap.rep.num = bootstrap.rep.num,
    ...
  )

  message("Viewing trees")

  p_trees <- viewTrees(
    phyloTree = phyloTree,
    group = group,
    group.colors = group.colors,
    title = title,
    hexpand_ratio = hexpand_ratio
  )

  return(
    list(
      phyloTree = phyloTree,
      plot = p_trees
    )
  )
}
qingjian1991/MPTevol documentation built on Jan. 30, 2023, 10:16 p.m.