Skip to content

Commit

Permalink
tweaks to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ehwenk committed Nov 3, 2023
1 parent f45722f commit cfa098c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 10 additions & 4 deletions R/build_align_taxon_names.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
build_align_taxon_names <- function(austraits, dataset) {

library(APCalign)
library(traits.build)
resources <- APCalign::load_taxonomic_resources()

names_to_align <- austraits$taxonomic_updates %>%
dplyr::filter(stringr::str_detect(dataset_id, dataset)) %>%
dplyr::filter(!cleaned_name %in% resources$APC$canonical_name & !cleaned_name %in% resources$APNI$canonical_name) %>%
dplyr::filter(!aligned_name %in% resources$APC$canonical_name & !aligned_name %in% resources$APNI$canonical_name) %>%
dplyr::filter(is.na(taxonomic_resolution)) %>%
dplyr::distinct(original_name)

names_aligned <-
APCalign::align_taxa(original_name = names_to_align$original_name) %>%
dplyr::select(find = original_name, replace = aligned_name, reason = aligned_reason, taxonomic_resolution = taxon_rank)
dplyr::select(all_of(c("original_name", "aligned_name", "aligned_reason", "taxon_rank"))) %>%
dplyr::rename(all_of(c(
"find" = "original_name",
"replace" = "aligned_name",
"reason" = "aligned_reason",
"taxonomic_resolution" = "taxon_rank"
)))

traits.build::metadata_add_taxonomic_changes_list(dataset, names_aligned)

}
3 changes: 1 addition & 2 deletions R/build_update_taxon_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ build_update_taxon_list <- function(austraits, taxon_list, replace = FALSE) {
rename(aligned_name = canonical_name, taxon_rank_APNI = taxon_rank)

# List of taxa that are explicitly excluded in metadata - don't want these in the taxon_list
# These should now be being excluded from `taxonomic_updates` table during processing, but good to check
# These should be excluded from `taxonomic_updates` table during processing, but good to check
excluded_in_metadata <- austraits$excluded_data %>% filter(error == "Observation excluded in metadata") %>% distinct(original_name)

# Start with taxonomic_updates table, which is all original names, aligned names, by dataset
all_taxa <-
austraits$taxonomic_updates %>%
#filter(str_detect(aligned_name, "Cynochloris")) %>% ##temporary
dplyr::select(dplyr::all_of(c("original_name", "aligned_name", "taxonomic_resolution"))) %>%
# In case the same `original_name`, `aligned_name` combination occurs twice, but only once with `taxonomic_resolution` attached, arrange names, taxon_ranks
dplyr::arrange(aligned_name, taxonomic_resolution) %>%
Expand Down

0 comments on commit cfa098c

Please sign in to comment.