Fix: handle empty index.json, fallback to zip scan
Browse files- app/utils/data_loader.py +15 -10
app/utils/data_loader.py
CHANGED
|
@@ -76,20 +76,25 @@ def load_prediction_index(pred_dir: str) -> pd.DataFrame:
|
|
| 76 |
with zipfile.ZipFile(zip_path, 'r') as zf:
|
| 77 |
# Look for index.json inside the zip
|
| 78 |
idx_file = next((f for f in zf.namelist() if f.endswith("index.json")), None)
|
|
|
|
| 79 |
if idx_file:
|
| 80 |
with zf.open(idx_file) as f:
|
| 81 |
index_dict = json.load(f)
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
| 91 |
else:
|
| 92 |
-
# No index.json — scan zip for _mode_0.txt files
|
|
|
|
| 93 |
mode0_files = [f for f in zf.namelist() if f.endswith("_mode_0.txt")]
|
| 94 |
for mf in mode0_files:
|
| 95 |
base = os.path.basename(mf).replace("_mode_0.txt", "")
|
|
|
|
| 76 |
with zipfile.ZipFile(zip_path, 'r') as zf:
|
| 77 |
# Look for index.json inside the zip
|
| 78 |
idx_file = next((f for f in zf.namelist() if f.endswith("index.json")), None)
|
| 79 |
+
index_dict = {}
|
| 80 |
if idx_file:
|
| 81 |
with zf.open(idx_file) as f:
|
| 82 |
index_dict = json.load(f)
|
| 83 |
+
|
| 84 |
+
if index_dict:
|
| 85 |
+
# Use pre-built index
|
| 86 |
+
for k, v in index_dict.items():
|
| 87 |
+
rows.append({
|
| 88 |
+
"name": k,
|
| 89 |
+
"seq_len": v.get("seq_len", 0),
|
| 90 |
+
"n_modes": v.get("n_modes", 0),
|
| 91 |
+
"mean_disp_m0": v.get("mean_disp", 0.0),
|
| 92 |
+
"max_disp_m0": v.get("max_disp", 0.0),
|
| 93 |
+
"top_residue": -1,
|
| 94 |
+
})
|
| 95 |
else:
|
| 96 |
+
# No index.json or empty — scan zip for _mode_0.txt files
|
| 97 |
+
logger.info("index.json missing or empty — scanning zip for mode files...")
|
| 98 |
mode0_files = [f for f in zf.namelist() if f.endswith("_mode_0.txt")]
|
| 99 |
for mf in mode0_files:
|
| 100 |
base = os.path.basename(mf).replace("_mode_0.txt", "")
|