ropensci / traits

R package for accessing species trait data from multiple databases
Other
39 stars 14 forks source link

Fixes ncbi_searcher error on some queries #107

Closed zachary-foster closed 6 years ago

zachary-foster commented 6 years ago

Description

I was getting the following error with the current github and CRAN versions:

> x <- traits::ncbi_searcher(id = "155619", fuzzy = TRUE)
Working on 155619...
...retrieving sequence IDs...
...retrieving available genes and their lengths...
Error in taxids[grepl(names(out)[i], taxids)] <- out[[i]] : 
  replacement has length zero

It was caused by an error being returned from the NCBI API instead of taxonomic information at this line:

https://github.com/ropensci/traits/blob/089094a07ba5722fbca964c99c618b13f7d68204/R/ncbi_searcher.R#L226

I am not sure why the error was occurring, but I changed the code so it returns NA in that case instead of failing.

Example

x <- traits::ncbi_searcher(id = "155619", fuzzy = TRUE)
> dplyr::as_tibble(x)
# A tibble: 500 x 5
   taxon                    length gene_desc                                                                   acc_no   gi_no
 * <chr>                     <dbl> <chr>                                                                       <chr>    <dbl>
 1 Lanmaoa pseudosensibilis   941. Lanmaoa pseudosensibilis voucher Mushroom Observer #275044 large subunit r… MH244…  1.38e9
 2 Boletaceae sp.             991. Boletaceae sp. voucher Mushroom Observer #250391 large subunit ribosomal R… MH244…  1.38e9
 3 Boletaceae sp.             988. Boletaceae sp. voucher Mushroom Observer #248795 large subunit ribosomal R… MH244…  1.38e9
 4 Boletus separans           993. Boletus separans voucher Mushroom Observer #282660 large subunit ribosomal… MH244…  1.38e9
 5 Boletus subvelutipes       750. Boletus subvelutipes voucher Mushroom Observer #285181 internal transcribe… MH244…  1.38e9
 6 Boletus subvelutipes       979. Boletus subvelutipes voucher Mushroom Observer #285181 large subunit ribos… MH244…  1.38e9
 7 Boletaceae sp.             567. Boletaceae sp. voucher Mushroom Observer #215899 small subunit ribosomal R… MH244…  1.38e9
 8 Leccinum snellii           967. Leccinum snellii voucher Mushroom Observer #288473 large subunit ribosomal… MH238…  1.38e9
 9 Boletus vermiculosoides    607. Boletus vermiculosoides voucher Mushroom Observer #279688 internal transcr… MH238…  1.38e9
10 NA                         756. Gliophorus cf. psittacinus internal transcribed spacer 2 and large subunit… MH237…  1.38e9
# ... with 490 more rows
codecov-io commented 6 years ago

Codecov Report

Merging #107 into master will decrease coverage by 0.14%. The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #107      +/-   ##
=========================================
- Coverage   24.04%   23.9%   -0.15%     
=========================================
  Files          17      17              
  Lines         682     686       +4     
=========================================
  Hits          164     164              
- Misses        518     522       +4
Impacted Files Coverage Δ
R/ncbi_searcher.R 0% <0%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 089094a...1b0a7ba. Read the comment docs.

sckott commented 6 years ago

looks good to me