I'm updating a database and trying to move from CAS Registry names to InChIKeys. I have about ~800 compounds to track. Is there a way to do this mappings programatically? I'm looking for a web service or API that already has this implemented, does something like it exist?
2 Answers
$\begingroup$
$\endgroup$
4
Chemical Identifier Resolver can convert several identifiers and has an API so you can convert with a script.
A Python example for CAS to InChIKey:
from urllib.request import urlopen
def CIRconvert(cas):
try:
url = 'http://cactus.nci.nih.gov/chemical/structure/' + cas + '/stdinchikey'
ans = urlopen(url).read().decode('utf8')
return ans
except:
return cas
casno = ['50-78-2', '69-72-7', '95-1E-6', '108-24-7', '31710-30-2']
for casid in casno:
print(CIRconvert(casid))
Output:
InChIKey=BSYNRYMUTXBXSQ-UHFFFAOYSA-N
InChIKey=YGSDEFSMJLZEOE-UHFFFAOYSA-N
95-1E-6
InChIKey=WFDIJRYMOXRFFG-UHFFFAOYSA-N
InChIKey=CIPFDHFTBYJKQB-UHFFFAOYSA-N
-
$\begingroup$ note that your code is syntactically wrong $\endgroup$– mykhalCommented Jun 8, 2020 at 13:23
-
$\begingroup$ @mykhal Just tested - code and service works. $\endgroup$– rapelpyCommented Jun 8, 2020 at 15:55
-
$\begingroup$ It really works, sorry for the inconvenience. But I have edited the "buggy code". $\endgroup$– mykhalCommented Jun 8, 2020 at 16:01
-
$\begingroup$ @mykhal For future reference: code prettify $\endgroup$– Martin - マーチン ♦Commented Jun 8, 2020 at 16:37
$\begingroup$
$\endgroup$
Chemical Identifier Resolver has a python API also: https://cirpy.readthedocs.io/en/latest/index.html
import cirpy
print(cirpy.resolve('107-13-1', 'stdinchikey'))
Output
InChIKey=NLHHRLWOUZZQLW-UHFFFAOYSA-N