Samad14 commited on
Commit
93a4e13
·
1 Parent(s): 3683b86

fix: AlphaFold lookup for NCBI RefSeq accessions

Browse files

- _lookup(): map NCBI RefSeq IDs to UniProt before querying AlphaFold API
- run(): skip cache for NCBI accessions (they need mapping, not caching)
- Fixes: AlphaFold 404 when BLAST returns NP_/XP_/YP_ accessions

bioai-platform/backend/app/tools/alphafold.py CHANGED
@@ -14,10 +14,28 @@ class AlphaFoldTool(BaseTool):
14
  if not uniprot_accession:
15
  return {"error": "No UniProt accession provided", "structure_available": False}
16
 
 
 
 
 
 
 
 
 
17
  result = await self._lookup(uniprot_accession)
18
  return result
19
 
20
  async def _lookup(self, accession: str) -> dict:
 
 
 
 
 
 
 
 
 
 
21
  url = f"{settings.ALPHAFOLD_DB_URL}/{accession}"
22
  async with httpx.AsyncClient(timeout=15) as client:
23
  resp = await client.get(url)
 
14
  if not uniprot_accession:
15
  return {"error": "No UniProt accession provided", "structure_available": False}
16
 
17
+ # NCBI RefSeq accessions can't be cached as-is because we need
18
+ # to map them to UniProt first (AlphaFold only indexes by UniProt).
19
+ # Skip cache for NCBI IDs — the mapped UniProt result will be cached.
20
+ import re
21
+ is_ncbi = uniprot_accession[:3] in ("NP_", "XP_", "YP_", "WP_")
22
+ if is_ncbi:
23
+ return await self._lookup(uniprot_accession)
24
+
25
  result = await self._lookup(uniprot_accession)
26
  return result
27
 
28
  async def _lookup(self, accession: str) -> dict:
29
+ # AlphaFold only indexes by UniProt accessions. If this looks like
30
+ # an NCBI RefSeq ID, try mapping to UniProt first.
31
+ import re
32
+ is_ncbi = accession[:3] in ("NP_", "XP_", "YP_", "WP_")
33
+ if is_ncbi:
34
+ from app.services.sequence_utils import map_refseq_to_uniprot
35
+ mapped = await map_refseq_to_uniprot(accession)
36
+ if mapped:
37
+ accession = mapped
38
+
39
  url = f"{settings.ALPHAFOLD_DB_URL}/{accession}"
40
  async with httpx.AsyncClient(timeout=15) as client:
41
  resp = await client.get(url)