Skip to content

Commit

Permalink
feat: new function get_coverage_tax #2
Browse files Browse the repository at this point in the history
  • Loading branch information
atn38 committed Apr 26, 2022
1 parent 5d6c2f0 commit 5b5c7d9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 13 deletions.
13 changes: 0 additions & 13 deletions R/get_attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,9 @@ parse_attribute <- function(x) {
att <- att[!grepl("methods", names(att))]

## Alter names to be consistent with other tools
names(att) <- gsub("missingValueCode.code",
"missingValueCode",
names(att),
fixed = TRUE)
names(att) <- gsub("standardUnit|customUnit",
"unit",
names(att))
## Alter names of annotation label fields for accessibility
names(att) <- gsub("annotation.valueURI.label",
"valueLabel",
names(att),
fixed = TRUE)
names(att) <- gsub("annotation.propertyURI.label",
"propertyLabel",
names(att),
fixed = TRUE)
names(att) <- gsub(".+\\.+",
"",
names(att))
Expand Down
72 changes: 72 additions & 0 deletions R/get_coverage_tax.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#' Title
#'
#' @param corpus
#'
#' @return
#' @export
#'
#' @examples
get_coverage_tax <- function(corpus) {
get_multilevel_element(
corpus = corpus,
element_names = c("coverage", "taxonomicCoverage"),
parse_function = parse_taxcov
)
}

#' Title
#'
#' @param x
#'
#' @return
#'
#' @examples
parse_taxcov <- function(x) {
a <- handle_one(x$taxonomicClassification)
return(data.table::rbindlist(
lapply(seq_along(a), function(x)
parse_taxonomic_classification(a[[x]], i = x)),
fill = TRUE
))
}

#' Title
#'
#' @param x
#' @param i
#' @param j
#'
#' @return
#'
#' @examples
parse_taxonomic_classification <- function(x, i, j) {
t <- list()
j <- i
if ("taxonomicClassification" %in% names(x)) {
i <- i + 1
t[[j]] <-
data.frame(
taxonrecordid = i,
parenttaxonid = j,
taxonrankname = null2na(x$taxonRankName),
taxonrankvalue = null2na(x$taxonRankValue),
commonname = handle_multiple(null2na(x$commonname)),
taxonid = handle_multiple(null2na(x$taxonId$taxonId)),
taxonidprovider = handle_multiple(null2na(x$taxonId$provider))
)
j <- j + 1
a <- handle_one(x$taxonomicClassification)
t[[j]] <- data.table::rbindlist(lapply(seq_along(a), function(x) parse_taxonomic_classification(a[[x]], i = i, j = j)), fill = TRUE)
} else {
t[[j]] <-
data.frame(
taxonrecordid = i,
parenttaxonid = j,
taxonrankname = null2na(x$taxonRankName),
taxonrankvalue = null2na(x$taxonRankValue),
commonname = handle_multiple(null2na(x$commonname)),
taxonid = handle_multiple(null2na(x$taxonId$taxonId)),
taxonidprovider = handle_multiple(null2na(x$taxonId$provider)))
}
return(data.table::rbindlist(t, fill = TRUE))
}

0 comments on commit 5b5c7d9

Please sign in to comment.