chembl / chembl_webresource_client

Official Python client for accessing ChEMBL API
https://www.ebi.ac.uk/chembl/api/data/docs
Other
377 stars 95 forks source link

Searching by synonym ? #19

Closed i-shah closed 7 years ago

i-shah commented 7 years ago

Is searching molecules / targets by synonyms supported ? If so, can you provide sample usage ?

Thanks

mnowotka commented 7 years ago

Hi, Yes, of course this is supported. For molecules:

from chembl_webresource_client.new_client import new_client
molecule = new_client.molecule
molecule.set_format('json')
res = molecule.search('viagra')

For targets:

from chembl_webresource_client.new_client import new_client
target = new_client.target
target.set_format('json')
res = target.search('lipoxygenase')

For more advanced examples, please take a look at tests file: https://github.com/chembl/chembl_webresource_client/blob/master/chembl_webresource_client/tests.py

i-shah commented 7 years ago

Thank you ! I've been looking at the REST API and trying to figure out how to filter based on the molecule_synonyms/molecule_synonym

mnowotka commented 7 years ago

You can do that as well:

target = new_client.target
gene_name = 'GABRB2'
targets_for_gene = target.filter(target_components__target_component_synonyms__component_synonym__icontains=gene_name)

or shorter:

shortcut = target.filter(target_synonym__icontains=gene_name)

The difference is that the 'search' method uses solr index so it's faster. When you are using 'filter' you have to know exactly where you want to search and it can be slower.

i-shah commented 7 years ago

Much rather use the solr index. Out of curiosity though, how would you search for molecule synonyms using a filter ?

mnowotka commented 7 years ago

Since a single molecule may have multiple synonyms (one to many relation) and there is no separate endpoint for synonyms this is not possible to do directly apply such a filter on the molecule entity. This is (one of the reasons) why we exposed another endpoint called 'drug': https://www.ebi.ac.uk/chembl/api/data/drug.json. But please note it only contains approved drugs (max_phase=4).

Example of searching for synonym using URL: https://www.ebi.ac.uk/chembl/api/data/drug.json?synonyms__icontains=prazosin

and the client:

drug = new_client.drug
res =  drug.filter(synonyms__icontains="prazosin")

For a general synonym search across all ChEMBL molecules, the solr based 'search' method is the only option though.

mnowotka commented 7 years ago

Hi,

I'm closing this issue now but feel free to reopen if you have some more questions about this topic. For other questions, please create a new issue.

i-shah commented 7 years ago

Thanks - appreciate the help

On Thu, Apr 20, 2017, 6:51 AM Michał Nowotka notifications@github.com wrote:

Hi,

I'm closing this issue now but feel free to reopen if you have some more questions about this topic. For other questions, please create a new issue.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/chembl/chembl_webresource_client/issues/19#issuecomment-295680243, or mute the thread https://github.com/notifications/unsubscribe-auth/AJ3KG3eAnhfbopdo0diI4d5PzUr-UGY8ks5rxzingaJpZM4M_mdO .

BJWiley233 commented 3 years ago

I just downloaded the conda package from here. When I run: target.filter(target_components__target_component_synonyms__component_synonym__icontains=gene_name) or target.filter(target_synonym__icontains=gene_name) I get

TypeError: 'NoneType' object cannot be interpreted as an integer

I can run in once and then it breaks there after.