This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Retrieve title name by accession R vs Python

I was working with R trying to get organism name (description):

> handel <- entrez_fetch(db = "nucleotide", id = "NC_001479.1", rettype = "xml") 
# used also entre_search

With fetch I get empty list with search I get an ID

When I use Python.

handle = Entrez.efetch(db="nucleotide", id="NC_001479.1", rettype="gb", retmode="text")
x = SeqIO.read(handle, 'genbank')  
print(x.Description)

#result:  'Encephalomyocarditis virus, complete genome'

What I am doing wrong with R?!

Thanks


Ok , I think I need to use also rettype = "gb" with R then process the results.

At the end I wrote this function:

retrive_title <- function(gi){
  handel <- entrez_fetch(db = "nucleotide", id = gi, rettype = "gb", retmode = "xml")  
  xml_handel <- read_xml(handel)
  xml_text(xml_find_all(xml_handel, "//GBSeq_organism"))
}

example:
retrive_title("NC_023021.1")
[1] "Formica exsecta virus 1"

r python entrez

Is this question resolved?

Not yet, I still need to find out how to extract the name from the result, or maybe there is a better solution than the one I wrote.

Using NCBI unix utils:

$ efetch -db nuccore -id "NC_001479.1" -format docsum | xtract -pattern DocumentSummary -element Organism
Encephalomyocarditis virus

$  efetch -db nuccore -id "NC_001479.1" -format docsum | xtract -pattern DocumentSummary -element Title
Encephalomyocarditis virus, complete genome

What you are asking for is under heading Title not Organism. Difference demonstrated above.

Thanks I will try to apply that on Python or R

unfortunately, it did not fix the main issue: using

> handel <- entrez_fetch(db = "nucleotide", id = "NC_001479.1", rettype = "xml")

gives empty list using

> handel <- entrez_fetch(db = "nucleotide", id = "NC_001479.1", rettype = "gb")

give a bulk string that is not easy to handle (away from if it is title or organism)

If you are going to use xml then:

$ efetch -db nuccore -id "NC_001479.1" -format xml | xtract -pattern OrgName -element OrgName_name_virus
Encephalomyocarditis virus

$ efetch -db nuccore -id "NC_001479.1" -format xml | xtract -pattern Bioseq_descr -element Seqdesc_title
Encephalomyocarditis virus, complete genome
hypothetical protein EMCVgp1 [Encephalomyocarditis virus]
protein 1A [Encephalomyocarditis virus]
protein 1B [Encephalomyocarditis virus]
protein 1C [Encephalomyocarditis virus]
protein 1D [Encephalomyocarditis virus]
protein 2A [Encephalomyocarditis virus]
protein 2B [Encephalomyocarditis virus]
protein 2C [Encephalomyocarditis virus]
protein 3AB [Encephalomyocarditis virus]
protein 3C [Encephalomyocarditis virus]
protein 3D [Encephalomyocarditis virus]
truncated polyprotein [Encephalomyocarditis virus]
2B* protein [Encephalomyocarditis virus]

With gb

$ efetch -db nuccore -id "NC_001479.1" -format gb | grep DEFINITION
DEFINITION  Encephalomyocarditis virus, complete genome

because I am In R I used the following (feel free to advice me with something better):

handel <- entrez_fetch(db = "nucleotide", id = "NC_001479.1", rettype = "gb")
x -> read.xml(handle)
xml_text(xml_find_all(x, "//GBSeq_organism"))

The output will be: [1] "Encephalomyocarditis virus"

I think there should be something easier than this

0 answers

No answers yet.

Log in to answer this question.