~ubuntu-branches/debian/stretch/r-cran-rnexml/stretch

« back to all changes in this revision

Viewing changes to R/nexml_get.R

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2016-04-08 13:58:39 UTC
  • Revision ID: package-import@ubuntu.com-20160408135839-ilq08z8v8p414qpn
Tags: upstream-2.0.6
ImportĀ upstreamĀ versionĀ 2.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#' Get the desired element from the nexml object
 
2
#' 
 
3
#' Get the desired element from the nexml object
 
4
#' @aliases nexml_get get_item
 
5
#' @param nexml a nexml object (from read_nexml)
 
6
#' @param element the kind of object desired, see details.  
 
7
#' @param ... additional arguments, if applicable to certain elements 
 
8
#' @details
 
9
#'  
 
10
#' \itemize{
 
11
#'  \item{"tree"}{ an ape::phylo tree, if only one tree is represented.  Otherwise returns a list of lists of multiphylo trees.  To consistently recieve the list of lists format (preserving the heriarchical nature of the nexml), use \code{trees} instead.}
 
12
#'  \item{"trees"}{ returns a list of lists of multiphylo trees, even if all trees are in the same `trees` node (and hence the outer list will be of length 1) or if there is only a single tree (and hence the inner list will also be of length 1.  This guarentees a consistent return type regardless of the number of trees present in the nexml file, and also preserves any heirarchy/grouping of trees.  }
 
13
#'  \item{"flat_trees"}{ a multiPhylo object (list of ape::phylo objects) Note that this method collapses any heirachical structure that may have been present as multiple `trees` nodes in the original nexml (though such a feature is rarely used).  To preserve that structure, use `trees` instead.}
 
14
#'  \item{"metadata"}{Get metadata from the specified level (default is top/nexml level) }
 
15
#'  \item{"otu"}{ returns a named character vector containing all available metadata.  names indicate \code{property} (or \code{rel} in the case of links/resourceMeta), while values indicate the \code{content} (or \code{href} for links). }
 
16
#'  \item{"taxa"}{ alias for otu }
 
17
#' }
 
18
#' For a slightly cleaner interface, each of these elements is also defined as an S4 method
 
19
#' for a nexml object.  So in place of `get_item(nexml, "tree")`, one could use `get_tree(nexml)`,
 
20
#' and so forth for each element type.  
 
21
#' @return return type depends on the element requested.  See details.  
 
22
#' @export
 
23
#' @seealso \code{\link{get_trees}}
 
24
#' @include classes.R
 
25
#' @examples
 
26
#' comp_analysis <- system.file("examples", "comp_analysis.xml", package="RNeXML")
 
27
#' nex <- nexml_read(comp_analysis)
 
28
#' nexml_get(nex, "trees")
 
29
#' nexml_get(nex, "characters_list")
 
30
nexml_get <- function(nexml, 
 
31
                     element = c("trees", 
 
32
                                 "trees_list", 
 
33
                                 "flat_trees", 
 
34
                                 "metadata", 
 
35
                                 "otu",
 
36
                                 "taxa",
 
37
                                 "characters", 
 
38
                                 "characters_list",
 
39
                                 "namespaces"), 
 
40
                     ...){
 
41
  element <- match.arg(element)
 
42
 
 
43
  switch(element,
 
44
         trees = get_trees(nexml), # will warn if more than one tree is available
 
45
         trees_list = get_trees_list(nexml),
 
46
         flat_trees = get_flat_trees(nexml),
 
47
         metadata = get_metadata(nexml, ...),
 
48
         otu = get_taxa(nexml),
 
49
         taxa = get_taxa(nexml),
 
50
         characters = get_characters(nexml),
 
51
         characters_list = get_characters_list(nexml),
 
52
         namespaces = get_namespaces(nexml))
 
53
}
 
54
 
 
55
get_item <- nexml_get
 
56
 
 
57