Skip to content

Commit

Permalink
Went through docs, resolves #109, added classification to get_data
Browse files Browse the repository at this point in the history
…for taxonomy and taxmap
  • Loading branch information
zachary-foster committed Dec 19, 2017
1 parent e2dcdfc commit 1fcd540
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Description: Provides taxonomic classes for
with data. Methods provided are "taxonomically aware", in
that they know about ordering of ranks, and methods that
filter based on taxonomy also filter associated data.
Version: 0.1.0.9115
Version: 0.1.0.9116
Authors@R: c(
person("Scott", "Chamberlain", role = c("aut", "cre"), email = "[email protected]"),
person("Zachary", "Foster", role = "aut", email = "[email protected]")
Expand Down
7 changes: 4 additions & 3 deletions R/taxmap--class.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#' A class designed to store a taxonomy and associated information. This class
#' builds on the [taxonomy()] class. User defined data can be stored in the list
#' `obj$data`, where `obj` is a taxmap object. Data that is associated with taxa
#' can be manipulated in a variety of ways using functions like `filter_taxa`
#' and `filter_obs`. To associate the items of lists/vectors with taxa, name
#' can be manipulated in a variety of ways using functions like [filter_taxa()]
#' and [filter_obs()]. To associate the items of lists/vectors with taxa, name
#' them by [taxon_ids()]. For tables, add a column named `taxon_id` that stores
#' [taxon_ids()].
#'
Expand All @@ -18,7 +18,7 @@
#' [hierarchy()] or character vectors in a list. Cannot be used with `...`.
#' @param data A list of tables with data associated with the taxa.
#' @param funcs A named list of functions to include in the class. Referring to
#' the names of these in functions like `filter_taxa` will execute the
#' the names of these in functions like [filter_taxa()] will execute the
#' function and return the results. If the function has at least one argument,
#' the taxmap object is passed to it.
#' @family classes
Expand Down Expand Up @@ -467,6 +467,7 @@ Taxmap <- R6::R6Class(
"taxon_names",
"taxon_ids",
"taxon_indexes",
"classifications",
"n_supertaxa",
"n_supertaxa_1",
"n_subtaxa",
Expand Down
22 changes: 17 additions & 5 deletions R/taxonomy--class.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,15 @@ Taxonomy <- R6::R6Class(
output <- unname(subset[is_root])

# Look up values
if (!is.null(value)) {
if (! is.null(value)) {
possible_values <- self$get_data(value)[[1]]
if (is.null(names(possible_values))) {
output <- possible_values[output]
} else {
output <- possible_values[self$taxon_ids()[output]]
}
} else {
names(output) <- self$taxon_ids()[output]
}

return(output)
Expand Down Expand Up @@ -975,10 +977,20 @@ Taxonomy <- R6::R6Class(
),

private = list(
nse_accessible_funcs = c("taxon_names", "taxon_ids", "taxon_indexes",
"n_supertaxa", "n_supertaxa_1", "n_subtaxa",
"n_subtaxa_1", "taxon_ranks", "is_root", "is_stem",
"is_branch", "is_leaf", "is_internode"),
nse_accessible_funcs = c("taxon_names",
"taxon_ids",
"taxon_indexes",
"classifications",
"n_supertaxa",
"n_supertaxa_1",
"n_subtaxa",
"n_subtaxa_1",
"taxon_ranks",
"is_root",
"is_stem",
"is_branch",
"is_leaf",
"is_internode"),

make_graph = function() {
apply(self$edge_list, 1, paste0, collapse = "->")
Expand Down
14 changes: 6 additions & 8 deletions R/taxonomy--docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ NULL
#' Get "branch" taxa
#'
#' Return the "branch" taxa for a [taxonomy()] or [taxmap()] object. A branch is
#' anything that is not a root, stem, or, leaf. Its the interior of the tree
#' anything that is not a root, stem, or leaf. Its the interior of the tree
#' after the first split starting from the roots. Can also be used to get the
#' branches of a subset of taxa.
#' \preformatted{
Expand Down Expand Up @@ -302,10 +302,6 @@ NULL
#' # Return something besides taxon indexes
#' internodes(ex_taxmap, value = "taxon_names")
#'
#' # Visualize which taxa are internodes
#' library(metacoder)
#' heat_tree(ex_taxmap, node_label = taxon_names,
#' node_color = ifelse(is_internode, "red", "grey"))
#' }
#' @name internodes
NULL
Expand Down Expand Up @@ -736,13 +732,15 @@ NULL

#' Get data in a taxonomy or taxmap object by name
#'
#' Given a vector of names, return a list of data (usually lists/vectors)
#' contained in a [taxonomy()] or [taxmap()] object. Each item will be named by
#' taxon ids when possible.
#' Given a vector of names, return a table of the indicated data
#' contained in a [taxonomy()] or [taxmap()] object.
#' \preformatted{
#' obj$get_data_frame(name = NULL, ...)
#' get_data_frame(obj, name = NULL, ...)}
#'
#' Note: This function will not work with variables in datasets in [taxmap()]
#' objects unless their rows correspond 1:1 with all taxa.
#'
#' @param obj A [taxonomy()] or [taxmap()] object
#' @param name (`character`) Names of data to return. If not supplied, return
#' all data listed in [all_names()].
Expand Down
Binary file modified data/ex_taxmap.rda
Binary file not shown.
Binary file modified data/ex_taxonomy.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion man/branches.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions man/get_data_frame.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions man/internodes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/taxmap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1fcd540

Please sign in to comment.