Update app.py
Browse files
app.py
CHANGED
@@ -82,8 +82,26 @@ def _query_pubmed(query: str, email: Optional[str] = PUBMED_EMAIL) -> Optional[D
|
|
82 |
"retmode": "json",
|
83 |
"email": email
|
84 |
}
|
85 |
-
|
|
|
|
|
|
|
|
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
def _get_pubchem_smiles(drug_name: str) -> Optional[str]:
|
89 |
"""Retrieves SMILES from PubChem, returns None on failure."""
|
@@ -159,12 +177,12 @@ def _analyze_adverse_events(drug_name: str, api_key:Optional[str] = OPENFDA_KEY,
|
|
159 |
|
160 |
def _get_pharmgkb_data(gene:str) -> Optional[Dict]:
|
161 |
"""Fetches pharmacogenomic data from PharmGKB."""
|
162 |
-
url =
|
163 |
data = _query_api(url)
|
164 |
if data and 'clinicalAnnotations' in data:
|
165 |
return data
|
166 |
else:
|
167 |
-
|
168 |
|
169 |
def _get_bioportal_data(ontology: str, term: str) -> Optional[Dict]:
|
170 |
"""Fetches data from BioPortal."""
|
|
|
82 |
"retmode": "json",
|
83 |
"email": email
|
84 |
}
|
85 |
+
data = _query_api(API_ENDPOINTS["pubmed"], params)
|
86 |
+
if data and 'esearchresult' in data:
|
87 |
+
return data
|
88 |
+
else:
|
89 |
+
return None
|
90 |
|
91 |
+
def _safe_get(endpoint: str, params: Optional[Dict] = None):
|
92 |
+
"""Safely fetches data from an API."""
|
93 |
+
try:
|
94 |
+
response = requests.get(endpoint, params=params)
|
95 |
+
response.raise_for_status() # Raises HTTPError for bad responses
|
96 |
+
return response.json()
|
97 |
+
except requests.exceptions.HTTPError as http_err:
|
98 |
+
st.error(f"HTTP error occurred: {http_err}")
|
99 |
+
logging.error(f"HTTP error occurred: {http_err}")
|
100 |
+
return None
|
101 |
+
except Exception as err:
|
102 |
+
st.error(f"Other error occurred: {err}")
|
103 |
+
logging.error(f"Other error occurred: {err}")
|
104 |
+
return None
|
105 |
|
106 |
def _get_pubchem_smiles(drug_name: str) -> Optional[str]:
|
107 |
"""Retrieves SMILES from PubChem, returns None on failure."""
|
|
|
177 |
|
178 |
def _get_pharmgkb_data(gene:str) -> Optional[Dict]:
|
179 |
"""Fetches pharmacogenomic data from PharmGKB."""
|
180 |
+
url = f"https://api.pharmgkb.org/v1/data/variant/{gene}/clinicalAnnotations"
|
181 |
data = _query_api(url)
|
182 |
if data and 'clinicalAnnotations' in data:
|
183 |
return data
|
184 |
else:
|
185 |
+
return None
|
186 |
|
187 |
def _get_bioportal_data(ontology: str, term: str) -> Optional[Dict]:
|
188 |
"""Fetches data from BioPortal."""
|