Spaces:
Sleeping
Sleeping
Sync main.py from blood-brain-omics repo
Browse files
main.py
CHANGED
|
@@ -431,19 +431,20 @@ def h2h_blood(
|
|
| 431 |
phase = "h2h_blood_withcov" if covariates == "included" else "h2h_blood"
|
| 432 |
|
| 433 |
rows = q(f"""
|
| 434 |
-
SELECT target, blood_platform, {metric}
|
| 435 |
FROM results
|
| 436 |
WHERE phase = ? AND h2h_pair = ? AND brain_target = ? AND model = ?
|
| 437 |
ORDER BY target
|
| 438 |
""", [phase, pair, brain, model]).fetchall()
|
| 439 |
|
| 440 |
-
# Pivot: target -> {platform_a: val, platform_b: val}
|
| 441 |
platforms = sorted(set(r[1] for r in rows))
|
| 442 |
-
targets = {}
|
| 443 |
-
for target, platform, val in rows:
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
|
|
|
| 447 |
|
| 448 |
return {
|
| 449 |
"pair": pair,
|
|
@@ -451,7 +452,7 @@ def h2h_blood(
|
|
| 451 |
"platforms": platforms,
|
| 452 |
"metric": metric,
|
| 453 |
"targets": [
|
| 454 |
-
{"target": t, **vals}
|
| 455 |
for t, vals in sorted(targets.items())
|
| 456 |
],
|
| 457 |
}
|
|
|
|
| 431 |
phase = "h2h_blood_withcov" if covariates == "included" else "h2h_blood"
|
| 432 |
|
| 433 |
rows = q(f"""
|
| 434 |
+
SELECT target, blood_platform, {metric}, n_samples
|
| 435 |
FROM results
|
| 436 |
WHERE phase = ? AND h2h_pair = ? AND brain_target = ? AND model = ?
|
| 437 |
ORDER BY target
|
| 438 |
""", [phase, pair, brain, model]).fetchall()
|
| 439 |
|
| 440 |
+
# Pivot: target -> {platform_a: val, platform_b: val, n_samples: max(n)}
|
| 441 |
platforms = sorted(set(r[1] for r in rows))
|
| 442 |
+
targets: dict[str, dict] = {}
|
| 443 |
+
for target, platform, val, n_samples in rows:
|
| 444 |
+
bucket = targets.setdefault(target, {"_n": 0})
|
| 445 |
+
bucket[platform] = round(val, 4) if val is not None else None
|
| 446 |
+
if n_samples and n_samples > bucket["_n"]:
|
| 447 |
+
bucket["_n"] = n_samples
|
| 448 |
|
| 449 |
return {
|
| 450 |
"pair": pair,
|
|
|
|
| 452 |
"platforms": platforms,
|
| 453 |
"metric": metric,
|
| 454 |
"targets": [
|
| 455 |
+
{"target": t, "n_samples": vals.pop("_n"), **vals}
|
| 456 |
for t, vals in sorted(targets.items())
|
| 457 |
],
|
| 458 |
}
|