Skip to content

Commit

Permalink
update documentation with new functions for propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
sdgamboa committed Oct 2, 2023
1 parent d67f4a7 commit cd5df44
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 2 deletions.
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -39,4 +43,5 @@ export(removeDuplicates)
export(resolveAgreements)
export(resolveConflicts)
export(scores2Freq)
export(taxPool)
export(taxname2taxid)
51 changes: 50 additions & 1 deletion R/taxPPro.R
Original file line number Diff line number Diff line change
@@ -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'){
Expand Down Expand Up @@ -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)
Expand All @@ -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'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions man/filterData.Rd

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

17 changes: 17 additions & 0 deletions man/getDataReady.Rd

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

20 changes: 20 additions & 0 deletions man/inh1.Rd

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

20 changes: 20 additions & 0 deletions man/inh2.Rd

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

22 changes: 22 additions & 0 deletions man/taxPool.Rd

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

2 changes: 1 addition & 1 deletion vignettes/articles/phytools2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit cd5df44

Please sign in to comment.