ropensci / webchem Goto Github PK
View Code? Open in Web Editor NEWChemical Information from the Web
Home Page: https://docs.ropensci.org/webchem
License: Other
Chemical Information from the Web
Home Page: https://docs.ropensci.org/webchem
License: Other
Use match = c('all', 'first', 'best', 'ask') to handle multiple matches!
get_etoxid()
ci_query()
get_csid()
Currently:
> alanwood("S-Metolachlor", type = "commonname")$inchikey
# More then one link found! Returning first.
#
# Querying s-metolachlor.html
# [1] "major component (S)-isomer:WVQBLGZPHOPPFO-LBPRGKRZSA-Nminor component (R)-isomer:WVQBLGZPHOPPFO-GFCCVEGCSA-N"
Should be
> alanwood("S-Metolachlor", type = "commonname")$inchikey
# More then one link found! Returning first.
#
# Querying s-metolachlor.html
# [1] "major component (S)-isomer" - WVQBLGZPHOPPFO-LBPRGKRZSA-N
[2] "minor component (R)-isomer" - WVQBLGZPHOPPFO-GFCCVEGCSA-N
> ci_query('Tetracyclin', type = 'name')
http://chem.sis.nlm.nih.gov/chemidplus/name/Tetracyclin
Error in html_table(xml_find_all(ttt, "//h2[contains(., 'Toxicity')]/following-sibling::div//table"))[[1]] :
subscript out of bounds
For example in the case of S-Metolachlor
http://www.alanwood.net/pesticides/s-metolachlor.html
the HTML snippet for the InChiKey is
<tr valign="baseline">
<th id="r11">InChIKey:</th>
<td headers="r11">major component (<i>S</i>)-isomer:<br>WVQBLGZPHOPPFO-LBPRGKRZSA-N<br>minor component (<i>R</i>)-isomer:<br>WVQBLGZPHOPPFO-GFCCVEGCSA-N</td>
</tr>
and we get
test <- webchem::alanwood("S-Metolachlor", type = "commonname")
## Querying s-metolachlor.htmls-metolachlor.html
test$inchikey
## [1] "major component (S)-isomer:WVQBLGZPHOPPFO-LBPRGKRZSA-Nminor component (R)-isomer:WVQBLGZPHOPPFO-GFCCVEGCSA-N"
## [2] "major component (S)-isomer:WVQBLGZPHOPPFO-LBPRGKRZSA-Nminor component (R)-isomer:WVQBLGZPHOPPFO-GFCCVEGCSA-N"
which is duplicated (already the query as it seems).
Currently no builds are send to coveralls!
http://toxbank.net/data-warehouse
needs registration...
e.g. 120-93-4 (because of dups in ppdb_idx)
1327-53-3 (because of encoding error)
From Tom Wenseleers:
Hi Rajarshi or Eduard,
I just figured out how to download Kovats retention indices from Pubchem - in case you would be interested to include something like this in rpubchem or webchem :
library("xml2")
library("data.table")
compound.retention.index <- function(file=NULL) {
pubchemid <- sub(".*/([0-9]+)/?.*", "\\1", file)
compound <- read_xml(file)
ns <- xml_ns(compound)
information <- xml_find_all(compound, paste0(
"//d1:TOCHeading[text()='Kovats Retention Index']",
"/following-sibling::d1:Information"
), ns)
indexes <- lapply(information, function(x) {
name <- xml_text(xml_find_one(x, "./d1:Name", ns))
values <- as.numeric(sapply(
xml_find_all(x, "./*[contains(name(), 'NumValue')]", ns),
xml_text))
data.frame(pubchemid=pubchemid,
column_class=name,
kovats_ri=values)
})
return( do.call("rbind", indexes) )
}
cids <- c("5282108", "5282148", "91754124") # example pubchem cids
compounds <- paste0("https://pubchem.ncbi.nlm.nih.gov/rest/pug_view/data/compound/",cids,"/XML/?response_type=display")
# Kovats retention indices
rti <- do.call("rbind",
lapply(compounds, compound.retention.index))
names(rti)
rti
Some time ago I also wrote some code to retrieve detailed retention index information, compound properties and EI mass spectra from the NIST Chemistry Webbook.
@Eduard - would you be interested by any chance to have some functions to interact with the NIST Chemistry Webbook in your webchem package?
best regards,
Tom
PS using the xml2 package in R tends to work better than the XML package, as the latter is known to have memory leaks, which can be really annoying for large annotation jobs
PS2 @Rajarshi - could be nice perhaps in your package if you could query also by inchikey, and that it would automatically recognize the input, and convert from inchikey to cid if desired:
library(webchem)
get_cid('GLZPCOQZEFWAFX-JXMROGBWSA-N')
"637566"
and
Hi Eduard,
Ha that's great! And yes I know how to use github - only thing is that I got quite a lot of teaching to do shortly, so it may be a little while then before I get to it then... I'll dig into my NIST functions too then.
Ha and to access all the info available in Pherobase (e.g. http://www.pherobase.com/database/nmr/nmr-detail-geraniol.php, http://www.pherobase.com/database/kovats/kovats-detail-geraniol.php, http://www.pherobase.com/database/compound/compounds-detail-geraniol.php, http://www.pherobase.com/database/floral-compounds/floral-taxa-compounds-detail-geraniol.php) I also have some functions - only thing is that for that one to enable generic queries (e.g. based on structure/InChiKey or name) I created a file with the relevant pointers and conversion from a given name or structure to a particular Pherobase page with retention index info, natural occurrece and behavioural function.
(As pherobase itself does not implement a generic search function, it just uses Google for that)
best regards,
Tom
cir_query()
to cir()
Currently:
> alanwood("S-Metolachlor", type = "commonname")$activity
[1] "herbicides (chloroacetanilide herbicides)"
desired behaviour:
$activity [1] "herbicides"
$activity_subgroup [1] "chloroacetanilide herbicides"
Notes for implementation:
How is using it?
Why?
What is useful?
what is missing?
what can be enhanced?
aw_query('12071-83-9', type = 'cas')
Querying propineb.html
Error in if (grepl("isomer", inchikey)) { : argument is of length zero
add function to write mol file
Need's to be done before next CRAN release.
Extract prediction from html.
Eg. solubility should have the same name and unit through the results returned.
http://www.chemspider.com/InChI.asmx
is.inchikey_cs()
cs_csid_mol()
cs_inchikey_csid()
cs_inchikey_inchi()
cs_inchikey_mol()
cs_inchi_csid()
cs_inchi_inchikey()
cs_inchi_mol()
cs_inchi_smiles()
cs_smiles_inchi()
And maybe a top-level function:
cs_convert
split multiple inchikeys:
BFPGVJIMBRLFIR-GUCBCRIZSA-Nidentifier for no stereochemistry:ZXQYGBMAQZUVMI-UHFFFAOYSA-N
e.g.
require(webchem)
compounds <- c('Triclosan', 'Formaldehyde')
# query all compounds, return first hit (-> named vector)
sapply(compounds,
function(x) cir_query(identifier = x , representation = 'cas', first = TRUE))
# query all compounds, return all hits (-> named list)
sapply(compounds,
function(x) cir_query(identifier = x , representation = 'cas'))
# format as data.frame
ll <- sapply(compounds,
function(x) cir_query(identifier = x , representation = 'cas'))
data.frame(compound = rep(names(ll), sapply(ll, length)),
cas = unlist(ll))
Perhaps on a separate branch to avoid conflicts with CRAN?!
add wikidata support:
get_wdid()
# get itemidwd_ident()
# identifierswd_prop()
# propertieswdd_safety()
# safety datavia
h <- try(GET(qurl, timeout(2)))
if (inherits(h, "try-error")) {
warning('Problem with web service encountered... Returning NA.')
return(NA)
} else {
tt <- read_xml(content(h, as = 'raw'))
}
allanwood()
etox()
Some functions return huge (messy) lists.
Add extractor functions to extract and clean desired parts (e.g. solubility, inchikey, etc...).
cas()
smiles()
inchikey()
See readme.md
This is related to issue #36.
Output would be a list of lists. Therefore we need the extractor functions.
And could skip the example with multiple inputs.
cts
physprop
cir
pubchem
etox
opsin
pan
wikidata
alanwood
chemspider
chemid
See appveyor results:
1. Failure (at test-physprop.R#8): physprop returns correct results ------------
fl$cas not equal to "50-00-0"
1 string mismatches:
x[1]: "50-00-0"
y[1]: "�000050-00-0"
This happens because sub()
doesn't work. Possible workarounds:
Switch to xml2 package?
e.g.
isinchikey=function(s) {
(s==toupper(s))&(nchar(s) == 27)&(substr(s,15,15)=="-")&(substr(s,26,26)=="-")
}
to check input for cts
.
http://sitem.herts.ac.uk/aeru/ppdb/en/Reports/415.htm
E.g. for pan()
[or generally all first = TRUE? ]
Add checks / filters to retrieve only the best match! [agrep?].
http://www.chemicalbook.com/ProductChemicalPropertiesCB6771432_EN.htm
get_cbid()
cb_compinfo()
(needs parse_mol)source_functionality
.
That is change alanwood
to aw_query()
and others.
e.g. queries should be of lenght 1.
See also issue #31
Check which function can handle input vectors and which not.
Add checks (e.g. in utils.R
)
So according to our packaging guide we're moving from RJSONIO to jsonlite https://github.com/ropensci/packaging_guide#apis
Since the only part of webchem that uses JSON is the Chemical Translation Service would it be ok if I change it over?
cs_inchikey_csid(inchi = 'KYOUEHWYDNYHAL-IOORBXIBSA-N')
http://www.chemspider.com/InChI.asmx/InChIKeyToCSID?inchi_key=KYOUEHWYDNYHAL-IOORBXIBSA-N
[1] ""
if input is NA, NA should be returned (not sodium).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.