stasaking commited on
Commit
5256459
·
verified ·
1 Parent(s): b740423

Sync main.py from blood-brain-omics repo

Browse files
Files changed (1) hide show
  1. main.py +19 -6
main.py CHANGED
@@ -485,25 +485,37 @@ def h2h_blood_summary(
485
  metric: str = Query("r2"),
486
  covariates: str = Query("none", enum=["none", "included"]),
487
  model: str = Query("TabPFN"),
 
488
  ):
489
- """Win counts across all blood H2H pairs."""
 
 
 
 
 
490
  validate_metric(metric)
491
  phase = "h2h_blood_withcov" if covariates == "included" else "h2h_blood"
492
 
493
- rows = q(f"""
494
  SELECT h2h_pair, brain_target, target, blood_platform, {metric}
495
  FROM results
496
  WHERE phase = ? AND model = ? AND h2h_pair IS NOT NULL
497
- ORDER BY h2h_pair, brain_target, target
498
- """, [phase, model]).fetchall()
 
 
 
 
 
 
499
 
500
  # Count wins per pair
501
  pair_wins = {}
502
  current = None
503
  buffer = {}
504
 
505
- for pair, brain, target, platform, val in rows:
506
- key = (pair, brain, target)
507
  if key != current:
508
  if current and len(buffer) == 2:
509
  pair_key = current[0]
@@ -534,6 +546,7 @@ def h2h_blood_summary(
534
  return {
535
  "metric": metric,
536
  "covariates": covariates,
 
537
  "pairs": pair_wins,
538
  }
539
 
 
485
  metric: str = Query("r2"),
486
  covariates: str = Query("none", enum=["none", "included"]),
487
  model: str = Query("TabPFN"),
488
+ brain: Optional[str] = Query(None, description="Restrict win counts to a single brain target"),
489
  ):
490
+ """Win counts across blood H2H pairs.
491
+
492
+ If ``brain`` is provided, wins are counted only against that brain
493
+ target (e.g. ``neuropathology``). Otherwise wins are counted across
494
+ every brain target in the H2H phase.
495
+ """
496
  validate_metric(metric)
497
  phase = "h2h_blood_withcov" if covariates == "included" else "h2h_blood"
498
 
499
+ sql = f"""
500
  SELECT h2h_pair, brain_target, target, blood_platform, {metric}
501
  FROM results
502
  WHERE phase = ? AND model = ? AND h2h_pair IS NOT NULL
503
+ """
504
+ params = [phase, model]
505
+ if brain is not None:
506
+ sql += " AND brain_target = ?"
507
+ params.append(brain)
508
+ sql += " ORDER BY h2h_pair, brain_target, target"
509
+
510
+ rows = q(sql, params).fetchall()
511
 
512
  # Count wins per pair
513
  pair_wins = {}
514
  current = None
515
  buffer = {}
516
 
517
+ for pair, row_brain, target, platform, val in rows:
518
+ key = (pair, row_brain, target)
519
  if key != current:
520
  if current and len(buffer) == 2:
521
  pair_key = current[0]
 
546
  return {
547
  "metric": metric,
548
  "covariates": covariates,
549
+ "brain": brain,
550
  "pairs": pair_wins,
551
  }
552