From cd5df445e957950db397028090ab82e28908a02b Mon Sep 17 00:00:00 2001 From: sdgamboa Date: Mon, 2 Oct 2023 17:41:51 -0400 Subject: [PATCH] update documentation with new functions for propagation --- NAMESPACE | 5 ++++ R/taxPPro.R | 51 +++++++++++++++++++++++++++++++- man/filterData.Rd | 17 +++++++++++ man/getDataReady.Rd | 17 +++++++++++ man/inh1.Rd | 20 +++++++++++++ man/inh2.Rd | 20 +++++++++++++ man/taxPool.Rd | 22 ++++++++++++++ vignettes/articles/phytools2.Rmd | 2 +- 8 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 man/filterData.Rd create mode 100644 man/getDataReady.Rd create mode 100644 man/inh1.Rd create mode 100644 man/inh2.Rd create mode 100644 man/taxPool.Rd diff --git a/NAMESPACE b/NAMESPACE index 77e9b9e..372d0fd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -17,15 +17,19 @@ export(classif2Table) export(cleanNode) export(conf2Fct) export(fillNAs) +export(filterData) export(freq2Scores) export(getAgreements) export(getConflicts) +export(getDataReady) export(getDoubleAnnotations) export(getDuplicates) export(getMpaTable) export(getMpaTree) export(getNCBI) export(inh) +export(inh1) +export(inh2) export(inhDownstreamLogical) export(inhDownstreamNumeric) export(inhDownstreamRange) @@ -39,4 +43,5 @@ export(removeDuplicates) export(resolveAgreements) export(resolveConflicts) export(scores2Freq) +export(taxPool) export(taxname2taxid) diff --git a/R/taxPPro.R b/R/taxPPro.R index a590b3a..4147d35 100644 --- a/R/taxPPro.R +++ b/R/taxPPro.R @@ -1,3 +1,12 @@ +#' Filter data +#' +#' \code{filterData} +#' +#' @param tbl A data.frame. +#' +#' @return A data.frame +#' @export +#' filterData <- function(tbl) { attr_type <- unique(tbl$Attribute_type) if(attr_type == 'logical'){ @@ -38,6 +47,13 @@ filterDataMulti <- function(tbl) { return(phys_data) } +#' Get data ready for propagation +#' +#' @param tbl A data.frame. +#' +#' @return A data.frame. +#' @export +#' getDataReady <- function(tbl) { set_With_ids <- getSetWithIDs(tbl) set_without_ids <- getSetWithoutIDs(tbl, set_with_ids = set_with_ids) @@ -46,7 +62,6 @@ getDataReady <- function(tbl) { dplyr::arrange(NCBI_ID, Attribute) } - getSetWithIDs <- function(tbl) { valid_ranks <- c('genus', 'species', 'strain') lgl_vct <- is.na(tbl$NCBI_ID) | tbl$NCBI_ID == 'unknown' @@ -147,6 +162,18 @@ getSetWithoutIDs <- function(tbl, set_with_ids = NULL) { ) } +#' Perform taxonomic pooling +#' +#' \code{taxPool} performs taxonomic pooling at the strain, species, and +#' genus ranks. Only use in the data.tree NCBI tree. +#' +#' @param node A node in a data.tree object. +#' @param grp A character string. Attribute group. +#' @param typ A character string. Attribute_type. +#' +#' @return A table for the attribute of a node. +#' @export +#' taxPool <- function(node, grp, typ) { if (!node$isLeaf) { children_names <- names(node$children) @@ -205,6 +232,17 @@ taxPool <- function(node, grp, typ) { } } +#' Inheritance first round +#' +#' \code{inh1} First round of inheritance. Only use with Do in a data.tree +#' object. +#' +#' @param node A node in a data.tree. +#' @param adjF Adjustment factor for penalty. Default is 1.0. +#' +#' @return A table for a node attribute. +#' @export +#' inh1 <- function(node, adjF = 0.1) { if (node$isRoot) return(NULL) @@ -229,6 +267,17 @@ inh1 <- function(node, adjF = 0.1) { } } +#' Inheritance second round +#' +#' \code{inh2} Second round of inheritance. Only use with Do in a data.tree +#' object. +#' +#' @param node A node in a data.tree. +#' @param adjF Adjustment factor for penalty. Default is 1.0. +#' +#' @return A table for a node attribute. +#' @export +#' inh2 <- function(node, adjF = 0.1) { cond1 <- !node$isRoot cond2 <- is.null(node$attribute_tbl) diff --git a/man/filterData.Rd b/man/filterData.Rd new file mode 100644 index 0000000..520bd5f --- /dev/null +++ b/man/filterData.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/taxPPro.R +\name{filterData} +\alias{filterData} +\title{Filter data} +\usage{ +filterData(tbl) +} +\arguments{ +\item{tbl}{A data.frame.} +} +\value{ +A data.frame +} +\description{ +\code{filterData} +} diff --git a/man/getDataReady.Rd b/man/getDataReady.Rd new file mode 100644 index 0000000..6ee3a50 --- /dev/null +++ b/man/getDataReady.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/taxPPro.R +\name{getDataReady} +\alias{getDataReady} +\title{Get data ready for propagation} +\usage{ +getDataReady(tbl) +} +\arguments{ +\item{tbl}{A data.frame.} +} +\value{ +A data.frame. +} +\description{ +Get data ready for propagation +} diff --git a/man/inh1.Rd b/man/inh1.Rd new file mode 100644 index 0000000..379ed54 --- /dev/null +++ b/man/inh1.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/taxPPro.R +\name{inh1} +\alias{inh1} +\title{Inheritance first round} +\usage{ +inh1(node, adjF = 0.1) +} +\arguments{ +\item{node}{A node in a data.tree.} + +\item{adjF}{Adjustment factor for penalty. Default is 1.0.} +} +\value{ +A table for a node attribute. +} +\description{ +\code{inh1} First round of inheritance. Only use with Do in a data.tree +object. +} diff --git a/man/inh2.Rd b/man/inh2.Rd new file mode 100644 index 0000000..c7cfee6 --- /dev/null +++ b/man/inh2.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/taxPPro.R +\name{inh2} +\alias{inh2} +\title{Inheritance second round} +\usage{ +inh2(node, adjF = 0.1) +} +\arguments{ +\item{node}{A node in a data.tree.} + +\item{adjF}{Adjustment factor for penalty. Default is 1.0.} +} +\value{ +A table for a node attribute. +} +\description{ +\code{inh2} Second round of inheritance. Only use with Do in a data.tree +object. +} diff --git a/man/taxPool.Rd b/man/taxPool.Rd new file mode 100644 index 0000000..94385a1 --- /dev/null +++ b/man/taxPool.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/taxPPro.R +\name{taxPool} +\alias{taxPool} +\title{Perform taxonomic pooling} +\usage{ +taxPool(node, grp, typ) +} +\arguments{ +\item{node}{A node in a data.tree object.} + +\item{grp}{A character string. Attribute group.} + +\item{typ}{A character string. Attribute_type.} +} +\value{ +A table for the attribute of a node. +} +\description{ +\code{taxPool} performs taxonomic pooling at the strain, species, and +genus ranks. Only use in the data.tree NCBI tree. +} diff --git a/vignettes/articles/phytools2.Rmd b/vignettes/articles/phytools2.Rmd index 86beec8..7353e30 100644 --- a/vignettes/articles/phytools2.Rmd +++ b/vignettes/articles/phytools2.Rmd @@ -252,7 +252,7 @@ ncbi_tree$Do( ncbi_tree$Do(inh2, traversal = 'pre-order') ``` -Generate final output +## Generate final output ```{r} output <- ncbi_tree$Get(