Closed ocstringham closed 4 years ago
thanks for your question @ocstringham - having a look
We use the /species/5716/children/
API route, e.g, https://api.gbif.org/v1/species/5716/children to get data for this function. It does not allow query parameters for extinction status, AND does not return data for that status.
Another route /species/search/
, e.g,. https://api.gbif.org/v1/species/search?q=Camelidae&limit=20&isExtinct=false does allow filtering by extinct status and returns the data, but only allows querying by a name string rather than a taxonomic ID, so you can't do a precise query with a known taxonomic ID
opened an issue in their forum https://discourse.gbif.org/t/extinction-status-and-the-species-api-routes/2312
OK, thank you for the update! Looking forward to hearing back.
https://discourse.gbif.org/t/extinction-status-and-the-species-api-routes/2312/2 reply, may be at a later point though - see also https://github.com/CatalogueOfLife/backend/issues/837
I found out that No, there' no way to filter extinct/extant status with the routes we're using for gbif_downstream. An alternative could be to add that data after, something like:
library(taxize)
library(rgbif)
x <- gbif_downstream(5716, downto = 'species')
dskey <- "d7dddbf4-2cf0-4f39-9b2a-bb099caae36c"
is_extinct <- function(name, key) {
res <- data.frame(name_lookup(name, datasetKey=dskey)$data)
if (NROW(res) == 0) return(NA)
if (NROW(res) > 1) {
res <- res[res$key == key, ]
}
res$extinct %||% NA
}
ext_vec <- Map(is_extinct, x$name, x$key)
x$extinct <- unlist(unname(ext_vec))
na.omit(x)[!na.omit(x)$extinct,]
Thanks for the update @sckott. I appreciate the alternative way of adding in the data after!
hopefully that works for you
@ocstringham does that solution work for you, adding in the extinct status after?
@sckott No, not yet. I'm running into issues where taxize::gbif_downstream
is returning synonyms so then rgbif::name_lookup
is not returning extinction status. I'll keep trying and get back to you. Thanks.
@sckott It's actually that rgbif::name_lookup
sometimes doesn't return an extinction status. For example: test = name_lookup("Camelops navadanus")$data
doesn't have an extinction column. Any idea why this may be?
No i don't know why exinct
would be missing.
Asked a question in their forum https://discourse.gbif.org/t/why-would-extinct-be-missing-from-species-search/2366
@ocstringham see the answer in the forum link above. When there is no extinct field they just don't know if it's extinct or not. I guess that sounds a bit silly but there it is. If you want to ask in that forum follow up questions go for it
Got it, makes sense. In that case, yes I can now code to get extinction status using rgbif::name_lookup
, given if no extinction is returned its status is unknown. Thanks!
great, sounds good
possibly related to #https://github.com/gbif/portal-feedback/issues/3432
I was wondering if there is a way to remove extinct species and only keep extant species when using
gbif_downstream
?For example, Camelidae (gbif ID 5716) has only seven extant species but
gbif_downstream
returns 165 species.Example code:
camels = gbif_downstream(5716, downto = 'species')