ropensci / rentrez

talk with NCBI entrez using R
https://docs.ropensci.org/rentrez
Other
194 stars 38 forks source link

Error: Must specify either (not both) 'id' or 'web_history' arguments #146

Closed arteteco closed 3 years ago

arteteco commented 4 years ago

Hello everyone,

I had this error today, and it seems to only happen with some codes, and not in others.

I have R 3.6.2 Debian 10 rentrez 1.2.2

If I run it, say, with sequence EU583721 I have the desired result:

$ ./quick.R EU583721
Title: Uncultured Hypocreales isolate H3.4 internal transcribed spacer 1, partial sequence; 5.8S ribosomal RNA gene and internal transcribed spacer 2, complete sequence; and 28S ribosomal RNA gene, partial sequence 
 Organism:  uncultured Hypocreales 
 PubMed:  A case study of modified interactions with symbionts in a hybrid mediterranean orchid. 
 Authors:  Schatz B Geoffroy A Dainat B Bessière JM Buatois B Hossaert-McKey M Selosse MA 
 https://www.ncbi.nlm.nih.gov/pubmed/?term=21616880 
 GenBank:  https://www.ncbi.nlm.nih.gov/nuccore/EU583721 

If I use for example FJ688104, which exists and is a valid code, I have the following error:

$ ./quick.R FJ688104 
Error: Must specify either (not both) 'id' or 'web_history' arguments
Execution halted

This is the code, I'm not a programmer so don't judge me on the form please!

#!/usr/bin/env Rscript

library("rentrez")

# I take my input from the command line
args = commandArgs(trailingOnly=TRUE)

r<-entrez_summary(db="nuccore", id=args)

p<-entrez_link(dbfrom="nuccore", id=args, db="all")

pub<-p$links$nuccore_pubmed

if(is.null(pub)){
  pub= 'No article found'

} else {

  pub=paste('https://www.ncbi.nlm.nih.gov/pubmed/?term=',pub, sep="")
}

#A small hack to get the pubmed and genbank links

gbl<-paste('https://www.ncbi.nlm.nih.gov/nuccore/', args, sep="")

pubm<-entrez_summary(db="pubmed", id=p$links$nuccore_pubmed)

auth<-do.call(paste,pubm$authors[1])

#And print everything
cat('Title:', r$title, "\n", 'Organism: ', r$organism, "\n", 'PubMed: ', pubm$title, "\n", 'Authors: ', auth, "\n",pub, "\n", 'GenBank: ', gbl, "\n")

Thanks!

dwinter commented 4 years ago

Hey, a nicer problem to think about than some others in the world just now ....

I think this is an issue with 'FJ688104' not having any nuccore_pubmed links. In an interactive session

r<-entrez_summary(db="nuccore", id=args)
p<-entrez_link(dbfrom="nuccore", id=args, db="all")
names(p$links)
[1] "nuccore_taxonomy

Might want to try some if statements for these cases? (An I could test that id is not null)

arteteco commented 4 years ago

Hi, thanks for your answer! I hope I understood what you mean.

I thought about the case that there was no nuccore_pubmed entry. In this case it's NULL, that is why I used that if, so that if it's null it would make p="No article found"

A very weird thing is that I tried it now and it was working. I will have to run around 100 more genbanks codes by tomorrow so I'll surely find another not working one. I hope so, at this point, otherwise I'd feel really dumb!

dwinter commented 4 years ago

Hi @arteteco , looks like the line

pubm<-entrez_summary(db="pubmed", id=p$links$nuccore_pubmed)

is not part of the else block, though? So it will be called not matter what and lead to the error.

arteteco commented 4 years ago

Hi, thanks.

Seems like using a simple if solves the issue in RStudio. If I run the code from there, by hardcoding args<-"FJ688104" it works.

What I don't understand at this point is: why if I save the script and run it from the command line I still have the error output? This happens either with R < q02.R --no-save or ./q02.R I am not sure this is the right place to ask such questions anymore, so feel free to tell me to go do my homework if I missed something.

$ ./q02.R 
Error: Must specify either (not both) 'id' or 'web_history' arguments
Execution halted

This is the little if just to catch the exception

pubm<-entrez_summary(db="pubmed", id=p$links$nuccore_pubmed)

if(is.null(pubm)){
  pubm= 'No article found'

}