Samad14 commited on
Commit
7756be4
·
1 Parent(s): 758bd07

fix: Foldseek alignments are dicts, parse with .get() correctly

Browse files
bioai-platform/backend/app/routers/structure_analysis.py CHANGED
@@ -224,22 +224,13 @@ async def _foldseek_search(pdb_id: str, chain: str, max_results: int) -> dict:
224
  else:
225
  raise HTTPException(504, "Foldseek job did not complete in time")
226
 
227
- # 5. Parse alignments (Foldseek returns list-of-lists tabular format)
228
  entries = data if isinstance(data, list) else data.get("results", [])
229
  seen: set[str] = set()
230
  results: list[StructureMatch] = []
231
  for db_entry in entries:
232
- alns = db_entry if isinstance(db_entry, list) else db_entry.get("alignments", [])
233
- # Debug: return raw first alignment to see format
234
- if alns and not results:
235
- raw_first = _json.dumps(alns[0] if isinstance(alns[0], (list, dict)) else str(alns[0]))
236
- results.append(StructureMatch(
237
- pdb_id="DEBUG", chain="", description=raw_first,
238
- tm_score=0, rmsd=0, seq_identity=0, aligned_length=0,
239
- ))
240
- break
241
- for aln in alns:
242
- target = aln[0] if isinstance(aln, list) else aln.get("target", "")
243
  raw_target = target.replace("pdb_", "").replace("PDB_", "")
244
  match_pdb = raw_target[:4].upper()
245
  match_chain = raw_target[4:] if len(raw_target) > 4 else ""
@@ -250,19 +241,14 @@ async def _foldseek_search(pdb_id: str, chain: str, max_results: int) -> dict:
250
  continue
251
  seen.add(match_pdb)
252
 
253
- score = aln[1] if isinstance(aln, list) else aln.get("score", 0)
254
- seq_id = aln[2] if isinstance(aln, list) else aln.get("seqId", 0)
255
- aln_len = aln[3] if isinstance(aln, list) else aln.get("alnLength", 0)
256
-
257
- tm = score / 100.0
258
  results.append(StructureMatch(
259
  pdb_id=match_pdb,
260
  chain=match_chain,
261
  description=target,
262
- tm_score=round(tm, 4),
263
  rmsd=0,
264
- seq_identity=seq_id,
265
- aligned_length=aln_len,
266
  ))
267
  if len(results) >= max_results:
268
  break
 
224
  else:
225
  raise HTTPException(504, "Foldseek job did not complete in time")
226
 
227
+ # 5. Parse alignments
228
  entries = data if isinstance(data, list) else data.get("results", [])
229
  seen: set[str] = set()
230
  results: list[StructureMatch] = []
231
  for db_entry in entries:
232
+ for aln in db_entry.get("alignments", []):
233
+ target = aln.get("target", "")
 
 
 
 
 
 
 
 
 
234
  raw_target = target.replace("pdb_", "").replace("PDB_", "")
235
  match_pdb = raw_target[:4].upper()
236
  match_chain = raw_target[4:] if len(raw_target) > 4 else ""
 
241
  continue
242
  seen.add(match_pdb)
243
 
 
 
 
 
 
244
  results.append(StructureMatch(
245
  pdb_id=match_pdb,
246
  chain=match_chain,
247
  description=target,
248
+ tm_score=round(aln.get("score", 0) / 100.0, 4),
249
  rmsd=0,
250
+ seq_identity=aln.get("seqId", 0),
251
+ aligned_length=aln.get("alnLength", 0),
252
  ))
253
  if len(results) >= max_results:
254
  break