Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve taxonomic names from external APIs to PhyloPic #97

Merged
merged 18 commits into from
Dec 20, 2023

Conversation

willgearty
Copy link
Collaborator

This adds the resolve_phylopic() function, which allows users to supply a taxonomic name that they expect to be matched in an external API (EOL, GBIF, PBDB, WoRMs, and OTOL atm) and then use that API to resolve the taxonomic name to PhyloPic. The function can return images (uuids/urls) for just the specified name or for a part of the taxonomic hierarchy (as reported by the API, except for EOL which doesn't supply taxonomic information).

This basically accomplishes the asynchronous API searching that the PhyloPic website does, but with much lower overhead than calling all of those APIs within get_uuid (because it is user-driven).

Fixes #66.

@willgearty willgearty added this to the 1.3.0 milestone Dec 18, 2023
Copy link

@keesey keesey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty cool!

R/resolve_phylopic.R Outdated Show resolved Hide resolved
@willgearty
Copy link
Collaborator Author

(rebasing because of the updated snapshots on main)

Copy link
Collaborator

@LewisAJones LewisAJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @willgearty, this works really well, great job! I've made some comments and suggestions - nothing major, but a few things to think about. Let me know if you want to chat about anything.

R/resolve_phylopic.R Outdated Show resolved Hide resolved
R/resolve_phylopic.R Outdated Show resolved Hide resolved
R/resolve_phylopic.R Outdated Show resolved Hide resolved
R/resolve_phylopic.R Outdated Show resolved Hide resolved
R/resolve_phylopic.R Outdated Show resolved Hide resolved
R/resolve_phylopic.R Outdated Show resolved Hide resolved
R/resolve_phylopic.R Outdated Show resolved Hide resolved
R/resolve_phylopic.R Outdated Show resolved Hide resolved
name <- gsub("_", " ", name)
name <- URLencode(name)
# Query specified API for the name -------------------------------------
if (api == "eol.org") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works really well but there is quite a bit of repeated code (e.g. L89–97). Could you perhaps start by making a list, subset the list to whatever API is requested and then run the code? I think this will help with managing any updates in future, including adding additional APIs? I get that there is some API specific code which is unavoidable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried my best to reduce some of the repeated code, but the responses from these APIs are just sooooo different.

R/resolve_phylopic.R Outdated Show resolved Hide resolved
Copy link
Collaborator

@LewisAJones LewisAJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good to me! Thanks for entertaining my pickiness 😄. Great job on turning that around so quickly 🚀

#' @return A `list` where each value is `n` (or fewer) PhyloPic image uuids (or
#' urls if `url = TRUE`) and each name is the taxonomic name as matched and
#' reported by the specified `api`. If `hierarchy` is `FALSE`, the list has
#' length 1. If `hierarchy` is `TRUE`, the list has maximum length
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you mean if you have a vector of more than length 1... well I guess if this is the case, does it even need to be named? I guess as long as get_phylopic and other functions can handle lists, it doesn't matter so much.

#'
#' The following APIs are available for matching (`api`):
#' \itemize{
#' \item{"eol.org": the \href{https://eol.org/}{Encyclopedia of Life}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it!

@willgearty willgearty merged commit df53f80 into main Dec 20, 2023
10 checks passed
@willgearty willgearty deleted the resolve_phylopic branch December 20, 2023 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

get_uuid still doesn't replicate phylopic.org search
3 participants