Skip to content
Snippets Groups Projects
Commit c5e51560 authored by Bryan BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

Merge branch 'master' into release

parents d1a6a376 7975fad4
No related branches found
No related tags found
1 merge request!53Clean code
Pipeline #110401 passed
......@@ -822,3 +822,20 @@ class TestWS(TestCaseWithRequestsCache):
ws.get_go_info('GO_0140999'),
{'label': 'histone H3K4 trimethyltransferase activity'}
)
def test_get_pubchem_id(self):
self.assertEqual(
ws.get_pubchem_id('ZRIKDHLPCRURPX-CSKARUKUSA-N'),
'24875307'
)
def test_get_ligand_id(self):
self.assertRaises(
EntryNotFoundError,
ws.get_ligand_id,
'CC(C)C(=O)c1cc(C(=O)c2ccc(Oc3ccccc3)cc2)c(O)c(O)c1O',
)
self.assertEqual(
ws.get_ligand_id('FC(F)(F)c1c(Sc2ccccc2OCc2cccnc2)ccc(C=CC(=O)N2CCOCC2)c1C(F)(F)F'),
'BQN',
)
"""
iPPI-DB web-service client utility functions
"""
import json
from typing import List
import xml.etree.ElementTree as ET
from urllib import parse as urllib_parse
import requests
from bioservices import xmltools
......@@ -580,19 +580,33 @@ def get_pubchem_id(inchikey: str) -> str:
def get_ligand_id(smiles: str) -> str:
endpoint = "http://www.rcsb.org/pdb/rest/smilesQuery?"
text = requests.get(
endpoint, params={"smiles": smiles, "search_type": "exact"}
).text
doc = ET.fromstring(text)
ligandInfoEls = doc.findall("ligandInfo")
if len(ligandInfoEls) > 0:
for ligandEl in ligandInfoEls[0].findall("ligand"):
if "chemicalID" in ligandEl.attrib:
return ligandEl.attrib["chemicalID"]
raise EntryNotFoundError(
smiles, msg=str(f"ligand for smiles {smiles} not found in PDB Ligand")
endpoint = "https://search.rcsb.org/rcsbsearch/v2/query"
query = {
"query": {
"type": "terminal",
"service": "chemical",
"parameters": {
"value": smiles,
"type": "descriptor",
"descriptor_type": "SMILES",
"match_type": "graph-strict"
}
},
"return_type": "mol_definition"
}
resp = requests.get(
endpoint, params={"json": json.dumps(query)}
)
if resp.text == '':
response = dict(total_count=0)
else:
response = resp.json()
if response['total_count'] == 0:
raise EntryNotFoundError(
smiles, msg=str(f"ligand for smiles {smiles} not found in PDB Ligand")
)
results = sorted(response['result_set'], key=lambda x: -x['score'])
return results[0]['identifier']
def get_orcid_user_details(orcid: str) -> str:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment