R/readinput.R

# readinput.R

library(treeio)
treeset = makeTreeset()

#' Reads in input from raw treefiles using treeio package.
#'
#'@param filepath The path of the raw tree file
#'@param inputType The type of input format (beast | mrbayes | paml | hyphy | r8 | raxml | nhx | phylip | epa | jtree)
#'@return A hash of the current different types of trees
#'@examples
readInput <- function(filepath, inputType){
  #Check valid inputType:
  #Citation: switches (https://stackoverflow.com/questions/10393508/how-to-use-the-switch-statement-in-r-functions)
  switch(inputType,
         beast={
           beast <- read.beast(filepath)
           treeset[["beast"]] <- beast
         },
         mrbayes={
           mrbayes <- read.mrbayes(filepath)
           treeset[["mrbayes"]] <- mrbayes
         },
         paml={
           paml <- read.paml_rst(filepath)
           treeset[["paml"]] <- paml
         },
         r8s={
           r8s <- read.r8s(filepath)
           treeset[["r8s"]] <- r8s
         },
         raxml={
           raxml <- read.raxml(filepath)
           treeset[["raxml"]] <- raxml
         },
         nhx={
           nhx <- read.nhx(filepath)
           treeset[["nhx"]] <- nhx
         },
         phylip={
           phylip <- read.phylip(filepath)
           treeset[["phylip"]] <- phylip
         },
         epa={
           epa <- read.jplace(filepath)
           treeset[["epa"]] <- epa
         },
         {
           stop('Invalid inputType: beast | mrbayes | paml | r8 | raxml | nhx | phylip | epa')
         }
  )
  return(treeset)
}

# Citations:
# https://bioconductor.org/packages/devel/bioc/vignettes/treeio/inst/doc/Importer.html#parsing-mrbayes-output
# Guangchuang Yu (2018). treeio: Base Classes and Functions for Phylogenetic
# Tree Input and Output. R package version 1.5.5.
# https://guangchuangyu.github.io/software/treeio
raywoo32/phylogetree documentation built on May 14, 2019, 7:22 p.m.