samirelanduk / pygtop

A Python wrapper for the IUPHAR/BPS Guide to PHARMACOLOGY API
MIT License
9 stars 2 forks source link

Issue in extracting interactions from any ligand #4

Open nicola-palmieri opened 1 month ago

nicola-palmieri commented 1 month ago

I wanted to loop over families to extract ligands and interactions for each ligand, but when i run ligand.interactions() i get a KeyError. Even the example code presented on the GitHub page does not work. Any ideas?

Thanks Nicola

>>> import pygtop
>>> ligand = pygtop.get_ligand_by_id(5239)
>>> ligand
<Ligand 5239 (paracetamol)>
>>> ligand.interactions()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\LabUser\AppData\Local\Programs\Python\Python312\Lib\site-packages\pygtop\ligands.py", line 522, in interactions
    return [Interaction(interaction_json) for interaction_json in self._get_interactions_json()]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\LabUser\AppData\Local\Programs\Python\Python312\Lib\site-packages\pygtop\interactions.py", line 47, in __init__
    self._affinity_type = json_data["affinityType"]
                          ~~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: 'affinityType'
stevejryan commented 1 month ago

I'm also trying to get targets from ligands and running into the same error. I also get this starting from targets and trying to query interactions

>>> mtor = pygtop.get_target_by_name('mtor')
>>> print(mtor)
<Target 2109 (mechanistic target of rapamycin kinase)>
>>> mtor.interactions()

KeyError                                  Traceback (most recent call last)
Cell In[29], line 3
      1 mtor = pygtop.get_target_by_name('mtor')
      2 print(mtor)
----> 3 mtor.interactions()

File ~\miniconda3\envs\qs_mlenv_311\Lib\site-packages\pygtop\targets.py:260, in Target.interactions(self, species)
    257     return [Interaction(interaction_json) for interaction_json in self._get_interactions_json()
    258      if interaction_json["targetSpecies"] and interaction_json["targetSpecies"].lower() == species.lower()]
    259 else:
--> 260     return [Interaction(interaction_json) for interaction_json in self._get_interactions_json()]

File ~\miniconda3\envs\qs_mlenv_311\Lib\site-packages\pygtop\targets.py:260, in <listcomp>(.0)
    257     return [Interaction(interaction_json) for interaction_json in self._get_interactions_json()
    258      if interaction_json["targetSpecies"] and interaction_json["targetSpecies"].lower() == species.lower()]
    259 else:
--> 260     return [Interaction(interaction_json) for interaction_json in self._get_interactions_json()]

File ~\miniconda3\envs\qs_mlenv_311\Lib\site-packages\pygtop\interactions.py:47, in Interaction.__init__(self, json_data)
     45 self._affinity_low = affinity_values[0] if affinity_values else None
     46 self._affinity_high = affinity_values[-1] if affinity_values else None
---> 47 self._affinity_type = json_data["affinityType"]

KeyError: 'affinityType'
samirelanduk commented 1 month ago

Hi all, this library was created as a wrapper around the API when I was working on the Guidetopharmacology team, but I haven't updated it since leaving - it looks the API may have been changed recently. I would recommend interfacing with the web services directly if this is the case: https://www.guidetopharmacology.org/webServices.jsp

stevejryan commented 4 weeks ago

I appreciate the feedback, @samirelanduk ! I may fork this and try to get it up and running or just take a crack at using the API directly.

Thanks!

nicola-palmieri commented 3 weeks ago

I found a solution. I have simply downloaded the GitHub repository and installed it with:

python setup.py build
python setup.py install