mgbam commited on
Commit
39e5a96
·
verified ·
1 Parent(s): 21f575e

Update genesis/api_clients/ncbi_api.py

Browse files
Files changed (1) hide show
  1. genesis/api_clients/ncbi_api.py +38 -2
genesis/api_clients/ncbi_api.py CHANGED
@@ -137,17 +137,53 @@ def search_proteins(term: str, retmax: int = 5) -> List[Dict]:
137
  proteins = [{"id": pid, "fasta": fasta_data} for pid in ids]
138
  return proteins
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  # -------------------------
141
  # Build Cross-Database Profile
142
  # -------------------------
143
  def ncbi_cross_profile(term: str) -> Dict:
144
  """
145
- Given a term, pull literature, genes, and proteins for unified output.
146
  """
147
  return {
148
  "term": term,
149
  "timestamp": datetime.utcnow().isoformat(),
150
  "literature": search_pubmed(term, retmax=5),
151
  "genes": search_genes(term, retmax=5),
152
- "proteins": search_proteins(term, retmax=2)
 
153
  }
 
137
  proteins = [{"id": pid, "fasta": fasta_data} for pid in ids]
138
  return proteins
139
 
140
+ # -------------------------
141
+ # Structure Search
142
+ # -------------------------
143
+ def fetch_ncbi_structure(term: str, retmax: int = 5) -> List[Dict]:
144
+ """
145
+ Search NCBI Structure database and return structure metadata.
146
+ """
147
+ ids = ncbi_search("structure", term, retmax)
148
+ if not ids:
149
+ return []
150
+
151
+ params = {
152
+ "db": "structure",
153
+ "id": ",".join(ids),
154
+ "retmode": "json"
155
+ }
156
+ if NCBI_API_KEY:
157
+ params["api_key"] = NCBI_API_KEY
158
+
159
+ r = session.get(f"{NCBI_BASE}/esummary.fcgi", params=params)
160
+ r.raise_for_status()
161
+
162
+ records = r.json().get("result", {})
163
+ structures = []
164
+ for sid in ids:
165
+ rec = records.get(sid, {})
166
+ structures.append({
167
+ "structure_id": sid,
168
+ "title": rec.get("title"),
169
+ "organism": rec.get("organism"),
170
+ "release_date": rec.get("releasedate"),
171
+ "link": f"https://www.ncbi.nlm.nih.gov/structure/{sid}"
172
+ })
173
+ return structures
174
+
175
  # -------------------------
176
  # Build Cross-Database Profile
177
  # -------------------------
178
  def ncbi_cross_profile(term: str) -> Dict:
179
  """
180
+ Given a term, pull literature, genes, proteins, and structures for unified output.
181
  """
182
  return {
183
  "term": term,
184
  "timestamp": datetime.utcnow().isoformat(),
185
  "literature": search_pubmed(term, retmax=5),
186
  "genes": search_genes(term, retmax=5),
187
+ "proteins": search_proteins(term, retmax=2),
188
+ "structures": fetch_ncbi_structure(term, retmax=3)
189
  }