Skip to content

Commit

Permalink
update mpa function
Browse files Browse the repository at this point in the history
  • Loading branch information
sdgamboa committed Sep 13, 2023
1 parent 35a209b commit 782fb53
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
21 changes: 15 additions & 6 deletions R/trees.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
#' Get metphlan tree or data v31
#'
#' \code{mpa} gets the metaphlan tree or data v31
#' \code{mpa} gets the metaphlan tree or data v31. In the case of nodes,
#' the node_label is the same as taxid.
#'
#' @param data TRUE for data. FALSE for tree. Default is FALSE.
#' @param x A character string: tree, tips, or nodes. Default is tree.
#'
#' @return A phylo or data.frame (see the `data` param)
#' @export
#'
mpa <- function(data = FALSE) {
if (!data) {
mpa <- function(x = 'tree') {
if (x == 'tree') {
fname <- system.file(
'extdata', 'mpav31.newick', package = 'taxPPro'
)
output <- ape::read.tree(fname)
} else if (data) {
} else if (x == 'tips') {
fname <- system.file(
'extdata', 'mpav31_tips.tsv', package = 'taxPPro'
)
output <- utils::read.table(
file = fname, header = TRUE, sep = '\t',
row.names = NULL
)
} else if (x == 'nodes') {
fname <- system.file(
'extdata', 'mpav31.tsv', package = 'taxPPro'
'extdata', 'mpav31_nodes.tsv', package = 'taxPPro'
)
output <- utils::read.table(
file = fname, header = TRUE, sep = '\t',
Expand Down
2 changes: 1 addition & 1 deletion inst/extdata/mpav31_nodes.tsv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"taxid" "kingdom_taxid" "phylum_taxid" "class_taxid" "order_taxid" "family_taxid" "genus_taxid" "species_taxid" "strain_taxid"
"node_label" "kingdom_taxid" "phylum_taxid" "class_taxid" "order_taxid" "family_taxid" "genus_taxid" "species_taxid" "strain_taxid"
"2157" "2157" NA NA NA NA NA NA NA
"1801616" "2157" "1801616" NA NA NA NA NA NA
"28890" "2157" "28890" NA NA NA NA NA NA
Expand Down
3 changes: 2 additions & 1 deletion inst/scripts/get_mpa_tree_v31.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ nodes_new_taxonomy <- map(nodes_taxonomy, ~ {
order_taxid, family_taxid, genus_taxid, species_taxid
) |>
discard(~ all(is.na(.x)))

nodes_new_taxonomy <- nodes_new_taxonomy |>
rename(node_label = taxid)

# sp_taxid_dups <- mpa_data$species_taxid[which(duplicated(mpa_data$species_taxid))]
#
Expand Down
7 changes: 4 additions & 3 deletions man/mpa.Rd

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

0 comments on commit 782fb53

Please sign in to comment.