mgbam commited on
Commit
c88dd17
Β·
verified Β·
1 Parent(s): ba49169

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -122
app.py CHANGED
@@ -8,13 +8,9 @@ from rdkit.Chem import Draw
8
  import pandas as pd
9
  import matplotlib.pyplot as plt
10
  import seaborn as sns
11
- from fpdf import FPDF
12
- import tempfile
13
  import logging
14
- import os
15
- import plotly.graph_objects as go
16
- import networkx as nx
17
- from typing import Optional, Dict, List, Any, Tuple
18
  from openai import OpenAI
19
 
20
  # Configure advanced logging for full traceability and diagnostics
@@ -29,27 +25,10 @@ logger = logging.getLogger("PRIS")
29
  # GLOBAL CONSTANTS
30
  # -----------------------------
31
  API_ENDPOINTS = {
32
- # Clinical Data Services
33
  "clinical_trials": "https://clinicaltrials.gov/api/v2/studies",
34
  "fda_drug_approval": "https://api.fda.gov/drug/label.json",
35
- "faers_adverse_events": "https://api.fda.gov/drug/event.json",
36
-
37
- # Chemical & Biological Data
38
  "pubchem": "https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/{}/JSON",
39
- "pubmed": "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi",
40
-
41
- # Pharmacogenomics Resources
42
- "pharmgkb_variant_clinical_annotations": "https://api.pharmgkb.org/v1/data/variant/{}/clinicalAnnotations",
43
- "pharmgkb_gene": "https://api.pharmgkb.org/v1/data/gene/{}",
44
- "pharmgkb_gene_variants": "https://api.pharmgkb.org/v1/data/gene/{}/variants",
45
-
46
- # Semantic Medical Resources
47
- "bioportal_search": "https://data.bioontology.org/search",
48
-
49
- # Drug Classification Systems
50
- "rxnorm_rxcui": "https://rxnav.nlm.nih.gov/REST/rxcui.json",
51
- "rxnorm_properties": "https://rxnav.nlm.nih.gov/REST/rxcui/{}/properties.json",
52
- "rxclass_by_drug": "https://rxnav.nlm.nih.gov/REST/class/byDrugName.json"
53
  }
54
 
55
  DEFAULT_HEADERS = {
@@ -61,7 +40,7 @@ DEFAULT_HEADERS = {
61
  # SECRETS MANAGEMENT
62
  # -----------------------------
63
  class APIConfigurationError(Exception):
64
- """Custom exception for missing API configurations in pharma research workflows."""
65
  pass
66
 
67
  try:
@@ -70,10 +49,8 @@ try:
70
  PUB_EMAIL = st.secrets["PUB_EMAIL"]
71
  OPENFDA_KEY = st.secrets["OPENFDA_KEY"]
72
 
73
- # Validate that all essential API credentials are configured
74
  if not all([OPENAI_API_KEY, BIOPORTAL_API_KEY, PUB_EMAIL, OPENFDA_KEY]):
75
  raise APIConfigurationError("One or more required API credentials are missing.")
76
-
77
  except (KeyError, APIConfigurationError) as e:
78
  st.error(f"Critical configuration error: {str(e)}")
79
  st.stop()
@@ -82,7 +59,7 @@ except (KeyError, APIConfigurationError) as e:
82
  # CORE INFRASTRUCTURE
83
  # -----------------------------
84
  class PharmaResearchEngine:
85
- """Core engine for integrating diverse pharmaceutical datasets and performing advanced analysis."""
86
 
87
  def __init__(self):
88
  self.openai_client = OpenAI(api_key=OPENAI_API_KEY)
@@ -91,10 +68,7 @@ class PharmaResearchEngine:
91
  def api_request(endpoint: str,
92
  params: Optional[Dict] = None,
93
  headers: Optional[Dict] = None) -> Optional[Dict]:
94
- """
95
- Enterprise-grade API request handler designed for robust and reproducible data acquisition.
96
- Implements detailed error logging and user-friendly messaging.
97
- """
98
  try:
99
  response = requests.get(
100
  endpoint,
@@ -102,7 +76,7 @@ class PharmaResearchEngine:
102
  headers={**DEFAULT_HEADERS, **(headers or {})},
103
  timeout=(3.05, 15)
104
  )
105
- response.raise_for_status() # Raises HTTPError for bad responses (4xx, 5xx)
106
  return response.json()
107
  except requests.exceptions.HTTPError as e:
108
  logger.error(f"HTTP Error {e.response.status_code} for {endpoint} with params {params}")
@@ -113,15 +87,20 @@ class PharmaResearchEngine:
113
  return None
114
 
115
  def get_compound_profile(self, identifier: str) -> Optional[Dict]:
116
- """
117
- Retrieve a comprehensive chemical profile from PubChem for a given compound identifier.
118
- Returns key molecular descriptors and structural data.
119
- """
120
- pubchem_data = self.api_request(API_ENDPOINTS["pubchem"].format(identifier))
 
 
 
121
 
 
 
122
  if not pubchem_data or not pubchem_data.get("PC_Compounds"):
123
  logger.warning(f"No compound data returned for identifier: {identifier}")
124
- st.error("No compound data found. Please verify the input (e.g., drug name or SMILES).")
125
  return None
126
 
127
  compound = pubchem_data["PC_Compounds"][0]
@@ -134,45 +113,50 @@ class PharmaResearchEngine:
134
  }
135
 
136
  def _extract_property(self, compound: Dict, prop_name: str) -> str:
137
- """Helper function to extract a specified property from the PubChem compound data."""
138
  for prop in compound.get("props", []):
139
  if prop.get("urn", {}).get("label") == prop_name:
140
  return prop["value"].get("sval", "N/A")
141
  return "N/A"
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  # -----------------------------
144
  # INTELLIGENCE MODULES
145
  # -----------------------------
146
  class ClinicalIntelligence:
147
- """
148
- Module for the analysis of clinical trial data and regulatory intelligence.
149
- Provides real-time insights into trial landscapes and FDA approval statuses.
150
- """
151
 
152
  def __init__(self):
153
  self.engine = PharmaResearchEngine()
154
 
155
  def get_trial_landscape(self, query: str) -> List[Dict]:
156
- """
157
- Analyze the clinical trial landscape based on a user-defined query.
158
- Returns a curated list of high-impact trials or an empty list if an error occurs.
159
- """
160
  params = {"query.term": query, "retmax": 10} if not query.startswith("NCT") else {"id": query}
161
  trials = self.engine.api_request(API_ENDPOINTS["clinical_trials"], params=params)
162
-
163
  if trials is None:
164
  logger.error(f"Clinical trial API returned no data for query: {query}")
165
  st.error("Failed to retrieve clinical trials. Please try a different query or check your network connection.")
166
  return []
167
-
168
- # Safely extract studies, defaulting to an empty list if key is missing
169
  return trials.get("studies", [])[:5]
170
 
171
  def get_fda_approval(self, drug_name: str) -> Optional[Dict]:
172
- """
173
- Retrieve FDA approval information for a specified drug.
174
- Integrates openFDA data to provide comprehensive regulatory insights.
175
- """
176
  if not OPENFDA_KEY:
177
  st.error("OpenFDA API key not configured.")
178
  return None
@@ -182,29 +166,20 @@ class ClinicalIntelligence:
182
  "search": f'openfda.brand_name:"{drug_name}"',
183
  "limit": 1
184
  }
185
-
186
  data = self.engine.api_request(API_ENDPOINTS["fda_drug_approval"], params=params)
187
  if data and data.get("results"):
188
  return data["results"][0]
189
-
190
- logger.warning(f"No FDA approval data found for drug: {drug_name}")
191
  st.error("No FDA regulatory data found for the specified drug.")
192
  return None
193
 
194
  class AIDrugInnovator:
195
- """
196
- GPT-4 powered strategic module for drug development.
197
- Leverages advanced natural language processing to formulate comprehensive R&D blueprints.
198
- """
199
 
200
  def __init__(self):
201
  self.engine = PharmaResearchEngine()
202
 
203
  def generate_strategy(self, target: str, strategy: str) -> str:
204
- """
205
- Generate an AI-driven drug development strategy.
206
- The output includes target validation, lead optimization, clinical trial design, regulatory analysis, and market assessment.
207
- """
208
  prompt = f"""As the Chief Scientific Officer at a leading pharmaceutical company, please develop a {strategy} strategy for the target: {target}.
209
  Include the following sections:
210
  - **Target Validation Approach**
@@ -214,7 +189,6 @@ Include the following sections:
214
  - **Commercial Potential Assessment**
215
 
216
  Format your response in Markdown with clear and concise sections."""
217
-
218
  try:
219
  response = self.engine.openai_client.chat.completions.create(
220
  model="gpt-4",
@@ -232,10 +206,7 @@ Format your response in Markdown with clear and concise sections."""
232
  # STREAMLIT INTERFACE
233
  # -----------------------------
234
  class PharmaResearchInterface:
235
- """
236
- User interface for PRIS built with Streamlit.
237
- Provides researchers with an intuitive dashboard for accessing multi-modal pharmaceutical data and AI-driven insights.
238
- """
239
 
240
  def __init__(self):
241
  self.clinical_intel = ClinicalIntelligence()
@@ -243,27 +214,24 @@ class PharmaResearchInterface:
243
  self._configure_page()
244
 
245
  def _configure_page(self):
246
- """Setup the Streamlit page configuration with a focus on clarity and ease-of-use."""
247
  st.set_page_config(
248
- page_title="PRIS - Pharmaceutical Research Intelligence Suite",
249
  layout="wide",
250
  initial_sidebar_state="expanded"
251
  )
252
  st.markdown("""
253
  <style>
254
- .main {background-color: #f9f9f9;}
255
  .stAlert {padding: 20px;}
256
- .reportview-container .markdown-text-container {font-family: 'Arial'}
257
  </style>
258
  """, unsafe_allow_html=True)
259
 
260
  def render(self):
261
- """Render the main application interface."""
262
- st.title("Pharmaceutical Research Intelligence Suite")
263
  self._render_navigation()
264
 
265
  def _render_navigation(self):
266
- """Dynamic tab-based navigation to access different research modules."""
267
  tabs = st.tabs([
268
  "πŸš€ Drug Innovation",
269
  "πŸ“ˆ Trial Analytics",
@@ -271,7 +239,6 @@ class PharmaResearchInterface:
271
  "πŸ“œ Regulatory Hub",
272
  "πŸ€– AI Strategist"
273
  ])
274
-
275
  with tabs[0]:
276
  self._drug_innovation()
277
  with tabs[1]:
@@ -284,33 +251,27 @@ class PharmaResearchInterface:
284
  self._ai_strategist()
285
 
286
  def _drug_innovation(self):
287
- """Interface for AI-driven drug development strategies."""
288
  st.header("AI-Powered Drug Innovation Engine")
289
  col1, col2 = st.columns([1, 3])
290
-
291
  with col1:
292
  target = st.text_input("Target Pathobiology:", placeholder="e.g., EGFR mutant NSCLC")
293
  strategy = st.selectbox("Development Paradigm:",
294
- ["First-in-class", "Fast-follower", "Biologic", "ADC", "Gene Therapy"])
295
  if st.button("Generate Development Blueprint"):
296
  with st.spinner("Formulating strategic plan..."):
297
  blueprint = self.ai_innovator.generate_strategy(target, strategy)
298
  st.markdown(blueprint, unsafe_allow_html=True)
299
 
300
  def _trial_analytics(self):
301
- """Interface for clinical trial landscape analytics."""
302
  st.header("Clinical Trial Landscape Analysis")
303
  trial_query = st.text_input("Search Clinical Trials:", placeholder="Enter condition, intervention, or NCT number")
304
-
305
  if st.button("Analyze Trial Landscape"):
306
  with st.spinner("Fetching trial data..."):
307
  trials = self.clinical_intel.get_trial_landscape(trial_query)
308
-
309
  if trials:
310
  st.subheader("Top 5 Clinical Trials")
311
  trial_data = []
312
  for study in trials:
313
- # Use .get() safely and log missing keys if necessary
314
  title = study.get("protocolSection", {}).get("identificationModule", {}).get("briefTitle", "N/A")
315
  status = study.get("protocolSection", {}).get("statusModule", {}).get("overallStatus", "N/A")
316
  phase = study.get("protocolSection", {}).get("designModule", {}).get("phases", ["N/A"])[0]
@@ -321,12 +282,8 @@ class PharmaResearchInterface:
321
  "Phase": phase,
322
  "Enrollment": enrollment
323
  })
324
-
325
- # Display as a DataFrame
326
  df = pd.DataFrame(trial_data)
327
  st.dataframe(df)
328
-
329
- # Visualization: Trial Phase Distribution
330
  st.subheader("Trial Phase Distribution")
331
  phase_counts = df["Phase"].value_counts()
332
  fig, ax = plt.subplots()
@@ -338,40 +295,34 @@ class PharmaResearchInterface:
338
  st.warning("No clinical trials found for the provided query.")
339
 
340
  def _compound_profiler(self):
341
- """Interface for advanced multi-omics compound profiling."""
342
- st.header("Multi-Omics Compound Profiler")
343
- compound = st.text_input("Analyze Compound:", placeholder="Enter drug name or SMILES")
344
-
345
- if compound:
346
  with st.spinner("Decoding molecular profile..."):
347
  profile = PharmaResearchEngine().get_compound_profile(compound)
348
-
349
- if profile:
350
- col1, col2 = st.columns(2)
351
- with col1:
352
- st.subheader("Structural Insights")
353
- mol = Chem.MolFromSmiles(profile['canonical_smiles'])
354
- if mol:
355
- img = Draw.MolToImage(mol, size=(400, 300))
356
- st.image(img, caption="2D Molecular Structure")
357
- else:
358
- st.error("Failed to generate molecular structure image. Check the SMILES string.")
359
-
360
- with col2:
361
- st.subheader("Physicochemical Profile")
362
- st.metric("Molecular Weight", profile['molecular_weight'])
363
- st.metric("LogP", profile['logp'])
364
- st.metric("IUPAC Name", profile['iupac_name'])
365
- st.code(f"SMILES: {profile['canonical_smiles']}")
366
- else:
367
- st.warning("Compound profile could not be generated. Please try again with a valid input.")
368
 
369
  def _regulatory_hub(self):
370
- """Interface for accessing regulatory intelligence and FDA approval data."""
371
  st.header("Regulatory Intelligence Hub")
372
- st.write("This section provides insights into FDA approvals and regulatory pathways.")
373
- drug_name = st.text_input("Enter Drug Name for Regulatory Analysis:", placeholder="e.g., aspirin")
374
-
375
  if st.button("Fetch Regulatory Data"):
376
  with st.spinner("Retrieving regulatory information..."):
377
  fda_data = self.clinical_intel.get_fda_approval(drug_name)
@@ -382,11 +333,9 @@ class PharmaResearchInterface:
382
  st.warning("No FDA regulatory data found for the specified drug.")
383
 
384
  def _ai_strategist(self):
385
- """Interface for AI-driven strategic drug development."""
386
  st.header("AI Drug Development Strategist")
387
- st.write("Leverage GPT-4 to generate innovative drug development strategies.")
388
  target = st.text_input("Enter Target Disease or Pathway:", placeholder="e.g., KRAS G12C mutation")
389
-
390
  if st.button("Generate AI Strategy"):
391
  with st.spinner("Generating AI-driven strategy..."):
392
  strategy = self.ai_innovator.generate_strategy(target, "First-in-class")
 
8
  import pandas as pd
9
  import matplotlib.pyplot as plt
10
  import seaborn as sns
 
 
11
  import logging
12
+ import re
13
+ from typing import Optional, Dict, List, Any
 
 
14
  from openai import OpenAI
15
 
16
  # Configure advanced logging for full traceability and diagnostics
 
25
  # GLOBAL CONSTANTS
26
  # -----------------------------
27
  API_ENDPOINTS = {
 
28
  "clinical_trials": "https://clinicaltrials.gov/api/v2/studies",
29
  "fda_drug_approval": "https://api.fda.gov/drug/label.json",
 
 
 
30
  "pubchem": "https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/{}/JSON",
31
+ # ... other endpoints omitted for brevity ...
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  }
33
 
34
  DEFAULT_HEADERS = {
 
40
  # SECRETS MANAGEMENT
41
  # -----------------------------
42
  class APIConfigurationError(Exception):
43
+ """Custom exception for missing API configurations."""
44
  pass
45
 
46
  try:
 
49
  PUB_EMAIL = st.secrets["PUB_EMAIL"]
50
  OPENFDA_KEY = st.secrets["OPENFDA_KEY"]
51
 
 
52
  if not all([OPENAI_API_KEY, BIOPORTAL_API_KEY, PUB_EMAIL, OPENFDA_KEY]):
53
  raise APIConfigurationError("One or more required API credentials are missing.")
 
54
  except (KeyError, APIConfigurationError) as e:
55
  st.error(f"Critical configuration error: {str(e)}")
56
  st.stop()
 
59
  # CORE INFRASTRUCTURE
60
  # -----------------------------
61
  class PharmaResearchEngine:
62
+ """Core engine for data integration and advanced analysis."""
63
 
64
  def __init__(self):
65
  self.openai_client = OpenAI(api_key=OPENAI_API_KEY)
 
68
  def api_request(endpoint: str,
69
  params: Optional[Dict] = None,
70
  headers: Optional[Dict] = None) -> Optional[Dict]:
71
+ """Robust API request handler with detailed error logging."""
 
 
 
72
  try:
73
  response = requests.get(
74
  endpoint,
 
76
  headers={**DEFAULT_HEADERS, **(headers or {})},
77
  timeout=(3.05, 15)
78
  )
79
+ response.raise_for_status()
80
  return response.json()
81
  except requests.exceptions.HTTPError as e:
82
  logger.error(f"HTTP Error {e.response.status_code} for {endpoint} with params {params}")
 
87
  return None
88
 
89
  def get_compound_profile(self, identifier: str) -> Optional[Dict]:
90
+ """Retrieve comprehensive chemical profile data from PubChem."""
91
+ # Validate input using heuristic: check if input appears to be a compound or a disease
92
+ if not self._is_valid_compound_input(identifier):
93
+ msg = (f"The input '{identifier}' does not appear to be a valid chemical compound name or SMILES string. "
94
+ "If you are searching for disease-related data, please use the Clinical Trial Analytics module.")
95
+ logger.warning(msg)
96
+ st.error(msg)
97
+ return None
98
 
99
+ pubchem_url = API_ENDPOINTS["pubchem"].format(identifier)
100
+ pubchem_data = self.api_request(pubchem_url)
101
  if not pubchem_data or not pubchem_data.get("PC_Compounds"):
102
  logger.warning(f"No compound data returned for identifier: {identifier}")
103
+ st.error("No compound data found. Please verify your input (e.g., check if it's a valid drug name or SMILES).")
104
  return None
105
 
106
  compound = pubchem_data["PC_Compounds"][0]
 
113
  }
114
 
115
  def _extract_property(self, compound: Dict, prop_name: str) -> str:
116
+ """Helper function to extract a specified property from PubChem data."""
117
  for prop in compound.get("props", []):
118
  if prop.get("urn", {}).get("label") == prop_name:
119
  return prop["value"].get("sval", "N/A")
120
  return "N/A"
121
 
122
+ @staticmethod
123
+ def _is_valid_compound_input(user_input: str) -> bool:
124
+ """
125
+ Basic heuristic to check if the user input is likely to be a compound.
126
+ Checks for presence of alphabetic chemical names or a valid SMILES pattern.
127
+ """
128
+ # A simplistic SMILES check: valid SMILES usually contain characters like "C", "O", "N", "=", "#", etc.
129
+ smiles_pattern = re.compile(r'^[BCNOFPSIbcnofpsi0-9@+\-\[\]\(\)=#$]+$')
130
+ if smiles_pattern.match(user_input.strip()):
131
+ return True
132
+
133
+ # Alternatively, check if the input contains common compound words and is not a disease name.
134
+ disease_terms = ['diabetes', 'cancer', 'hypertension', 'asthma']
135
+ if any(term in user_input.lower() for term in disease_terms):
136
+ return False
137
+
138
+ # Otherwise, assume a valid chemical name (could be improved with a dictionary lookup)
139
+ return True
140
+
141
  # -----------------------------
142
  # INTELLIGENCE MODULES
143
  # -----------------------------
144
  class ClinicalIntelligence:
145
+ """Module for clinical trial and regulatory intelligence."""
 
 
 
146
 
147
  def __init__(self):
148
  self.engine = PharmaResearchEngine()
149
 
150
  def get_trial_landscape(self, query: str) -> List[Dict]:
 
 
 
 
151
  params = {"query.term": query, "retmax": 10} if not query.startswith("NCT") else {"id": query}
152
  trials = self.engine.api_request(API_ENDPOINTS["clinical_trials"], params=params)
 
153
  if trials is None:
154
  logger.error(f"Clinical trial API returned no data for query: {query}")
155
  st.error("Failed to retrieve clinical trials. Please try a different query or check your network connection.")
156
  return []
 
 
157
  return trials.get("studies", [])[:5]
158
 
159
  def get_fda_approval(self, drug_name: str) -> Optional[Dict]:
 
 
 
 
160
  if not OPENFDA_KEY:
161
  st.error("OpenFDA API key not configured.")
162
  return None
 
166
  "search": f'openfda.brand_name:"{drug_name}"',
167
  "limit": 1
168
  }
 
169
  data = self.engine.api_request(API_ENDPOINTS["fda_drug_approval"], params=params)
170
  if data and data.get("results"):
171
  return data["results"][0]
172
+ logger.warning(f"No FDA data found for drug: {drug_name}")
 
173
  st.error("No FDA regulatory data found for the specified drug.")
174
  return None
175
 
176
  class AIDrugInnovator:
177
+ """GPT-4 powered module for AI-driven drug development strategy."""
 
 
 
178
 
179
  def __init__(self):
180
  self.engine = PharmaResearchEngine()
181
 
182
  def generate_strategy(self, target: str, strategy: str) -> str:
 
 
 
 
183
  prompt = f"""As the Chief Scientific Officer at a leading pharmaceutical company, please develop a {strategy} strategy for the target: {target}.
184
  Include the following sections:
185
  - **Target Validation Approach**
 
189
  - **Commercial Potential Assessment**
190
 
191
  Format your response in Markdown with clear and concise sections."""
 
192
  try:
193
  response = self.engine.openai_client.chat.completions.create(
194
  model="gpt-4",
 
206
  # STREAMLIT INTERFACE
207
  # -----------------------------
208
  class PharmaResearchInterface:
209
+ """Next-generation Streamlit interface for PRIS."""
 
 
 
210
 
211
  def __init__(self):
212
  self.clinical_intel = ClinicalIntelligence()
 
214
  self._configure_page()
215
 
216
  def _configure_page(self):
 
217
  st.set_page_config(
218
+ page_title="PRIS - Next-Generation Pharmaceutical Research Suite",
219
  layout="wide",
220
  initial_sidebar_state="expanded"
221
  )
222
  st.markdown("""
223
  <style>
224
+ .main {background-color: #f0f2f6;}
225
  .stAlert {padding: 20px;}
226
+ .reportview-container .markdown-text-container {font-family: 'Helvetica Neue', Arial, sans-serif}
227
  </style>
228
  """, unsafe_allow_html=True)
229
 
230
  def render(self):
231
+ st.title("Next-Generation Pharmaceutical Research Intelligence Suite")
 
232
  self._render_navigation()
233
 
234
  def _render_navigation(self):
 
235
  tabs = st.tabs([
236
  "πŸš€ Drug Innovation",
237
  "πŸ“ˆ Trial Analytics",
 
239
  "πŸ“œ Regulatory Hub",
240
  "πŸ€– AI Strategist"
241
  ])
 
242
  with tabs[0]:
243
  self._drug_innovation()
244
  with tabs[1]:
 
251
  self._ai_strategist()
252
 
253
  def _drug_innovation(self):
 
254
  st.header("AI-Powered Drug Innovation Engine")
255
  col1, col2 = st.columns([1, 3])
 
256
  with col1:
257
  target = st.text_input("Target Pathobiology:", placeholder="e.g., EGFR mutant NSCLC")
258
  strategy = st.selectbox("Development Paradigm:",
259
+ ["First-in-class", "Fast-follower", "Biologic", "ADC", "Gene Therapy"])
260
  if st.button("Generate Development Blueprint"):
261
  with st.spinner("Formulating strategic plan..."):
262
  blueprint = self.ai_innovator.generate_strategy(target, strategy)
263
  st.markdown(blueprint, unsafe_allow_html=True)
264
 
265
  def _trial_analytics(self):
 
266
  st.header("Clinical Trial Landscape Analysis")
267
  trial_query = st.text_input("Search Clinical Trials:", placeholder="Enter condition, intervention, or NCT number")
 
268
  if st.button("Analyze Trial Landscape"):
269
  with st.spinner("Fetching trial data..."):
270
  trials = self.clinical_intel.get_trial_landscape(trial_query)
 
271
  if trials:
272
  st.subheader("Top 5 Clinical Trials")
273
  trial_data = []
274
  for study in trials:
 
275
  title = study.get("protocolSection", {}).get("identificationModule", {}).get("briefTitle", "N/A")
276
  status = study.get("protocolSection", {}).get("statusModule", {}).get("overallStatus", "N/A")
277
  phase = study.get("protocolSection", {}).get("designModule", {}).get("phases", ["N/A"])[0]
 
282
  "Phase": phase,
283
  "Enrollment": enrollment
284
  })
 
 
285
  df = pd.DataFrame(trial_data)
286
  st.dataframe(df)
 
 
287
  st.subheader("Trial Phase Distribution")
288
  phase_counts = df["Phase"].value_counts()
289
  fig, ax = plt.subplots()
 
295
  st.warning("No clinical trials found for the provided query.")
296
 
297
  def _compound_profiler(self):
298
+ st.header("Advanced Multi-Omics Compound Profiler")
299
+ compound = st.text_input("Analyze Compound:", placeholder="Enter drug name or SMILES (e.g., Metformin, C(C(=O)O)N)")
300
+ if st.button("Profile Compound"):
 
 
301
  with st.spinner("Decoding molecular profile..."):
302
  profile = PharmaResearchEngine().get_compound_profile(compound)
303
+ if profile:
304
+ col1, col2 = st.columns(2)
305
+ with col1:
306
+ st.subheader("Structural Insights")
307
+ mol = Chem.MolFromSmiles(profile['canonical_smiles'])
308
+ if mol:
309
+ img = Draw.MolToImage(mol, size=(400, 300))
310
+ st.image(img, caption="2D Molecular Structure")
311
+ else:
312
+ st.error("Could not generate molecular structure image. Verify the SMILES string.")
313
+ with col2:
314
+ st.subheader("Physicochemical Profile")
315
+ st.metric("Molecular Weight", profile['molecular_weight'])
316
+ st.metric("LogP", profile['logp'])
317
+ st.metric("IUPAC Name", profile['iupac_name'])
318
+ st.code(f"SMILES: {profile['canonical_smiles']}")
319
+ else:
320
+ st.warning("Compound profiling failed. Ensure that you have entered a valid chemical compound.")
 
 
321
 
322
  def _regulatory_hub(self):
 
323
  st.header("Regulatory Intelligence Hub")
324
+ st.write("Gain insights into FDA approvals and regulatory pathways.")
325
+ drug_name = st.text_input("Enter Drug Name for Regulatory Analysis:", placeholder="e.g., Aspirin")
 
326
  if st.button("Fetch Regulatory Data"):
327
  with st.spinner("Retrieving regulatory information..."):
328
  fda_data = self.clinical_intel.get_fda_approval(drug_name)
 
333
  st.warning("No FDA regulatory data found for the specified drug.")
334
 
335
  def _ai_strategist(self):
 
336
  st.header("AI Drug Development Strategist")
337
+ st.write("Leverage GPT-4 to generate cutting-edge drug development strategies.")
338
  target = st.text_input("Enter Target Disease or Pathway:", placeholder="e.g., KRAS G12C mutation")
 
339
  if st.button("Generate AI Strategy"):
340
  with st.spinner("Generating AI-driven strategy..."):
341
  strategy = self.ai_innovator.generate_strategy(target, "First-in-class")