#!/usr/bin/env python # coding: utf-8 # In[1]: from chembl_webresource_client.unichem import unichem_client as unichem # ## Get src_compound_ids from src_compound_id # Obtain a list of all `src_compound_ids` from all sources which are **CURRENTLY** assigned to the same structure as a currently assigned query `src_compound_id`. The output will include query `src_compound_id` if it is a valid `src_compound_id` with a current assignment. # In[2]: ret = unichem.get('CHEMBL12',1) # In[3]: len(ret) # In[4]: ret # Note also, that by adding an additional (optional) argument (a valid `src_id`), then results will be restricted to only the source specified with this optional argument. # In[5]: ret = unichem.get('CHEMBL12',1,2) # In[6]: len(ret) # In[7]: ret # ## Get all src_compound_ids from src_compound_id # Obtain a list of *all* `src_compound_ids` from all sources (including **BOTH** current **AND** obsolete assignments) to the same structure as a currently assigned query `src_compound_id`. The output will include query `src_compound_id` if it is a valid `src_compound_id` with a current assignment. # In[8]: ret = unichem.get('CHEMBL12', 1, all=True) # In[9]: len(ret) # In[10]: ret # Note also, that by adding an additional (optional) argument (a valid `src_id`), then results will be restricted to only the source specified with this optional argument. # In[11]: ret = unichem.get('CHEMBL12', 1, 2, all=True) # In[12]: len(ret) # In[13]: ret # ## Get mapping # Obtain a full mapping between two sources. Uses only currently assigned `src_compound_ids` from both sources. # In[14]: ret = unichem.map(4,1) # In[15]: len(ret) # In[16]: ret[0] # ## Get src_compound_ids from InChI Key # Obtain a list of all `src_compound_ids` (from all sources) which are **CURRENTLY** assigned to a query InChIKey # In[17]: ret = unichem.get('AAOVKJBEBIDNHE-UHFFFAOYSA-N') # In[18]: len(ret) # In[19]: ret # ## Get src_compound_ids all from InChIKey # Obtain a list of *all* `src_compound_ids` (from all sources) which have current **AND** obsolete assignments to a query InChIKey # In[20]: ret = unichem.get('AAOVKJBEBIDNHE-UHFFFAOYSA-N', all=True) # In[21]: len(ret) # In[22]: ret # ## Get all src_ids # Obtain all `src_ids` currently in UniChem # In[23]: ret = unichem.src() # In[24]: len(ret) # In[25]: ret # ## Get source infomation # Obtain *all* information on a source by querying with a source id (`src_id`). # In[26]: ret = unichem.src(1) # In[27]: len(ret) # In[28]: ret # ## Get structure # Obtain structure(s) **CURRENTLY** assigned to a query `src_compound_id`. # In[29]: ret = unichem.structure('CHEMBL12',1) # In[30]: len(ret) # In[31]: ret # ## Get all structures # Obtain structure(s) with current **AND** obsolete assignments to a query `src_compound_id`. # In[32]: ret = unichem.structure('CHEMBL12',1, all=True) # In[33]: len(ret) # In[34]: ret # ## Get URL for src_compound_ids from src_compound_id # Obtain a list of URLs for all `src_compound_ids`, from a specified source (the `to_src_id`), which are **CURRENTLY** assigned to the same structure as a currently assigned query `src_compound_id`. Method only applicable for sources which support direct URLs to `src_compound_id` pages. # # In[35]: ret = unichem.get('CHEMBL12',1, 2, url=True) # In[36]: len(ret) # In[37]: ret # Method also applicable for `to_src_id`'s where the hyperlink is constructed from auxiliary data [and not from the `src_compound_id`] as per example below. # In[38]: ret = unichem.get('CHEMBL490',1, 15, url=True) # In[39]: len(ret) # In[40]: ret # ## Get src_compound_ids all from obsolete src_compound_id # Obtain a list of all `src_compound_ids` from all sources with **BOTH** current **AND** obsolete to the same structure with an obsolete assignment to the query `src_compound_id`. The output will include query `src_compound_id` if it is a valid `src_compound_id` with an obsolete assignment. # # ret = unichem.get('DB07699',2) # In[41]: len(ret) # In[42]: ret # Note also, that by adding an additional (optional) argument (a valid `src_id`), then results will be restricted to only the source specified with this optional argument. # In[43]: ret = unichem.get('DB07699',2,1) # In[44]: len(ret) # In[45]: ret # ## Get verbose src_compound_ids from InChIKey # Obtain all `src_compound_ids` (from all sources) which are **CURRENTLY** assigned to a query InChIKey. However, these are returned as part of the following data structure: A list of sources containing these `src_compound_ids`, including source description, base_id_url, etc. One element in this list is a list of the `src_compound_ids` currently assigned to the query InChIKey. # In[46]: ret = unichem.get('AAOVKJBEBIDNHE-UHFFFAOYSA-N', verbose=True) # In[47]: len(ret) # In[48]: ret # ## Get auxiliary mappings # For a single source, obtain a mapping between all current `src_compound_ids` to their corresponding auxiliary data. See [FAQ](https://www.ebi.ac.uk/unichem/info/faq#faq13) for an explanation of *auxiliary data*. # In[49]: ret = unichem.map(20) # In[50]: len(ret) # In[51]: ret[0] # ## Get Connectivity data from InChIKey # For the explanation of `a`-`h` arguments, please refer to the [documentation](https://www.ebi.ac.uk/unichem/info/widesearchInfo). # In[52]: ret = unichem.connectivity('QJVHTELASVOWBE-YBABNSIOSA-N', c=4, h=1) # In[53]: len(ret['1']) # In[54]: ret['1'][1] # In[55]: ret = unichem.connectivity('QJVHTELASVOWBE-YBABNSIOSA-N',a=1,c=3) # In[56]: len(ret['1']) # In[57]: len(ret['1'][0]['src_matches']) # In[58]: ret['1'][0]['src_matches'][3] # In[59]: ret = unichem.connectivity('QJVHTELASVOWBE',a=1,c=3) # In[60]: len(ret['1']) # In[61]: len(ret['1'][0]['src_matches']) # In[62]: ret['1'][0]['src_matches'][5] # ## Get Connectivity data from src_compound_id # For the explanation of `a`-`h` arguments, please refer to the [documentation](https://www.ebi.ac.uk/unichem/info/widesearchInfo). # In[63]: ret = unichem.connectivity('CHEMBL121',1,c=4,h=1) # In[64]: len(ret['1']) # In[65]: ret['1'][1] # In[66]: ret = unichem.connectivity('CHEMBL121',1) # In[67]: len(ret['1']) # In[68]: len(ret['1'][0]['src_matches']) # In[69]: ret['1'][0]['src_matches'] # ## Get InChI from InChIKey # Obtain InChI for InChIKey # In[70]: ret = unichem.inchiFromKey('AAOVKJBEBIDNHE-UHFFFAOYSA-N') # In[71]: ret