LoocasGoose Claude Opus 4.5 commited on
Commit
424b88d
·
1 Parent(s): 00a0b23

Clean up search summary output

Browse files

- Remove verbose/unused fields (risk_formula, risk_explanation, match_rate, etc.)
- Reorganize into cleaner nested structure
- Show alpha_used vs alpha_requested clearly
- Add note when FDR only has α=0.1 calibrated
- Round threshold and empirical_risk for readability

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

protein_conformal/backend/gradio_interface.py CHANGED
@@ -742,20 +742,11 @@ def _process_input_impl(stage_timer: StageTimer,
742
  logger.warning(f"Requested alpha={risk_value} not available. Using closest alpha={closest_alpha}")
743
 
744
  conformal_results = {
745
- "message": f"Used precomputed threshold for {risk_description} control, alpha={closest_alpha}, match_type={match_type_label}" + (f" (requested α={risk_value})" if abs(closest_alpha - risk_value) > 0.001 else ""),
746
  "threshold": float(threshold),
747
  "risk_type": risk_type.lower(),
748
  "match_type": match_type_label,
749
- "risk_description": risk_description,
750
- "risk_formula": risk_formula,
751
- "risk_explanation": risk_explanation,
752
  "empirical_risk": float(empirical_risk) if empirical_risk is not None else None,
753
- "n_matches": 0, # Will be updated after search
754
- "match_rate": 0.0, # Will be updated after search
755
- "n_calib": len(threshold_df),
756
- "match_info": [], # Will be populated after search
757
- "has_probability_calibration": True, # Enable Venn-Abers probability calibration
758
- "probability_calibration_method": "Venn-Abers prediction with isotonic regression"
759
  }
760
 
761
  if "error" in conformal_results:
@@ -823,37 +814,41 @@ def _process_input_impl(stage_timer: StageTimer,
823
  results_df = pd.DataFrame(all_matches)
824
 
825
  with stage_timer.track("results_packaging"):
826
- # 1. Create summary information for the JSON display
 
827
  summary = {
828
- "message": conformal_results["message"],
829
- "database_used": database_type,
830
- "num_matches": total_matches,
831
- "threshold": conformal_results["threshold"],
832
- "max_results_requested": max_results,
833
- "risk_type": conformal_results["risk_type"],
834
- "risk_description": conformal_results["risk_description"],
835
- "risk_formula": conformal_results["risk_formula"],
836
- "risk_explanation": conformal_results["risk_explanation"],
837
- "empirical_risk": conformal_results["empirical_risk"],
838
- "n_calib": conformal_results["n_calib"],
839
- "match_rate": conformal_results["match_rate"],
 
 
 
840
  }
841
-
842
- # 2. Complete results for the raw JSON output
 
 
 
 
843
  complete_results = {
844
- "conformal_prediction": conformal_results,
845
- "database_used": database_type,
846
- "num_matches": total_matches,
847
- "max_results_requested": max_results,
848
- "matches": all_matches, # Include all matches
849
  "threshold": conformal_results["threshold"],
850
  "risk_type": conformal_results["risk_type"],
851
- "risk_description": conformal_results["risk_description"],
852
- "risk_explanation": conformal_results["risk_explanation"],
853
  "empirical_risk": conformal_results["empirical_risk"]
854
  }
855
-
856
- # Store in session for potential later use - include ALL matches for export
857
  global CURRENT_SESSION
858
  CURRENT_SESSION = {
859
  "results": complete_results,
@@ -862,8 +857,6 @@ def _process_input_impl(stage_timer: StageTimer,
862
  "risk_value": risk_value,
863
  "max_results": max_results,
864
  "database_type": database_type,
865
- "input_type": "fasta_format", # Always FASTA now
866
- "n_calib": conformal_results["n_calib"]
867
  }
868
  }
869
 
 
742
  logger.warning(f"Requested alpha={risk_value} not available. Using closest alpha={closest_alpha}")
743
 
744
  conformal_results = {
 
745
  "threshold": float(threshold),
746
  "risk_type": risk_type.lower(),
747
  "match_type": match_type_label,
 
 
 
748
  "empirical_risk": float(empirical_risk) if empirical_risk is not None else None,
749
+ "has_probability_calibration": True,
 
 
 
 
 
750
  }
751
 
752
  if "error" in conformal_results:
 
814
  results_df = pd.DataFrame(all_matches)
815
 
816
  with stage_timer.track("results_packaging"):
817
+ # 1. Create concise summary for display
818
+ alpha_note = f" (only α=0.1 calibrated)" if risk_type.lower() == "fdr" and abs(float(closest_alpha) - risk_value) > 0.001 else ""
819
  summary = {
820
+ "status": "success",
821
+ "matches_found": total_matches,
822
+ "risk_control": {
823
+ "type": conformal_results["risk_type"].upper(),
824
+ "alpha_used": float(closest_alpha),
825
+ "alpha_requested": risk_value,
826
+ "threshold": round(conformal_results["threshold"], 10),
827
+ "empirical_risk": round(conformal_results["empirical_risk"], 4) if conformal_results["empirical_risk"] else None,
828
+ },
829
+ "search_config": {
830
+ "database": database_type,
831
+ "match_type": conformal_results["match_type"],
832
+ "max_k": max_results,
833
+ },
834
+ "note": alpha_note.strip() if alpha_note.strip() else None,
835
  }
836
+ # Remove None values for cleaner output
837
+ summary = {k: v for k, v in summary.items() if v is not None}
838
+ if summary.get("note") is None:
839
+ summary.pop("note", None)
840
+
841
+ # 2. Complete results for export
842
  complete_results = {
843
+ "summary": summary,
844
+ "matches": all_matches,
 
 
 
845
  "threshold": conformal_results["threshold"],
846
  "risk_type": conformal_results["risk_type"],
847
+ "match_type": conformal_results["match_type"],
 
848
  "empirical_risk": conformal_results["empirical_risk"]
849
  }
850
+
851
+ # Store in session for export
852
  global CURRENT_SESSION
853
  CURRENT_SESSION = {
854
  "results": complete_results,
 
857
  "risk_value": risk_value,
858
  "max_results": max_results,
859
  "database_type": database_type,
 
 
860
  }
861
  }
862