From 10c6f0d73c14d2d7c10b3c1fe7210652396d53db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20=20MENAGER?= <herve.menager@pasteur.fr>
Date: Sat, 9 Sep 2017 21:57:11 +0200
Subject: [PATCH] add ws function to check if a PDB entry exists

Former-commit-id: 6d985f2167bda81cb08bad3b9cc5e4738a96e5a1
---
 ippisite/ippidb/ws.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/ippisite/ippidb/ws.py b/ippisite/ippidb/ws.py
index b29027bb..ad6fd40e 100644
--- a/ippisite/ippidb/ws.py
+++ b/ippisite/ippidb/ws.py
@@ -83,3 +83,12 @@ def get_pdb_uniprot_mapping(pdb_id):
     resp = requests.get('https://www.ebi.ac.uk/pdbe/api/mappings/uniprot/{}'.format(pdb_id.lower()))
     uniprot_ids = list(resp.json()[pdb_id]['UniProt'].keys())
     return uniprot_ids
+
+def pdb_entry_exists(pdb_id):
+    """ test if a PDB entry exists using EBI web services """
+    resp = requests.get('https://www.ebi.ac.uk/pdbe/api/pdb/entry/summary/{}'.format(pdb_id.lower()))
+    # EBI sends back either a 404 or an empty json if the PDB does not exist
+    if not(resp.ok):
+        return False
+    else:
+        return True
-- 
GitLab