许多化学家面临的一个恼人的问题是将化学物质的化学文摘社登记号(存储在一些不易访问的商业数据库中)转换为Pubchem标识符(公开可用)。Pubchem类支持两者之间的转换,但只能通过他们的手工web界面,而不是他们官方的PUG REST编程接口。
本文给出了一种基于e-实用程序接口:http://depth-first.com/articles/2007/09/13/hacking-pubchem-convert-cas-numbers-into-pubchem-cids-with-ruby/的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"干杯,汤姆
发布于 2014-02-04 12:32:24
这是Ruby代码如何使用RCurl和XML实现的,并转换为R
> 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"如果找不到的话也许需要做个测试。
发布于 2015-03-25 09:49:25
我认为您仍然应该能够使用PubChem将CAS编号转换为PubChem ID,而不是输入CAS编号的化合物的名称。当然,如果CAS编号重叠,这可能就不那么具体了。我还没试过呢。
阿司匹林https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/50-78-2/cids/JSON一例
https://stackoverflow.com/questions/21551937
复制相似问题