许多化学家面临的一个恼人的问题是将化学化合物的cas注册号(存储在一些不易访问的商业数据库中)转换为pubchem标识符(公开可用)。Pubchem类支持两者之间的转换,但仅通过它们的手动web接口,而不是它们的官方PUG REST编程接口。
这里给出了一个基于e-utilities接口的Ruby解决方案:http://depth-first.com/articles/2007/09/13/hacking-pubchem-convert-cas-numbers-into-pubchem-cids-with-ruby/
有人知道这是怎么变成R的吗?
编辑:根据下面的答案,最优雅的解决方案是:

library(XML)
library(RCurl)

CAStocids=function(query) {
  xmlresponse = xmlParse( getURL(paste("http://www.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pccompound&retmax=100&term=",query,sep="") ) )
  cids = sapply(xpathSApply(xmlresponse, "//Id"), function(n){xmlValue(n)})
  return(cids)
}

> CAStocids("64318-79-2")
[1] "6434870" "5282237"

干杯,
汤姆

最佳答案

这就是Ruby代码的工作原理,转换成R,使用RCurlXML

> xmlresponse = xmlParse( getURL("http://www.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pccompound&retmax=100&term=64318-79-2") )

下面是如何提取Id节点:
> sapply(xpathSApply(xmlresponse, "//Id"), function(n){xmlValue(n)})
 [1] "6434870" "5282237"

在函数中包装所有这些…
 convertU = function(query){
    xmlresponse = xmlParse(getURL(
       paste0("http://www.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pccompound&retmax=100&term=",query)))
    sapply(xpathSApply(xmlresponse, "//Id"), function(n){xmlValue(n)})
 }

> convertU("64318-79-2")
[1] "6434870" "5282237"
> convertU("64318-79-1")
list()
> convertU("64318-78-2")
list()
> convertU("64313-78-2")
[1] "313"

如果找不到,可能需要做个测试。

关于ruby - R中的CAS注册表到Pubchem cid标识符的转换,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21551937/

10-12 20:02