@@ -28,12 +28,19 @@ def __init__(self, config: AnnotationConfig):
2828 self .client = AnnotationClient ()
2929 self .annotation_results : List [AnnotationDecision ] = []
3030
31- def process_studies (self , studies : List [Study ], output_dir : str ) -> List [AnnotationDecision ]:
31+ def process_studies (
32+ self ,
33+ included_studies : List [Study ],
34+ all_studies : List [Study ] = None ,
35+ output_dir : str = None
36+ ) -> List [AnnotationDecision ]:
3237 """
33- Process all studies and annotate their analyses.
38+ Process studies and annotate their analyses.
3439
3540 Args:
36- studies: List of studies with parsed analyses
41+ included_studies: List of INCLUDED studies with parsed analyses
42+ all_studies: Optional list of ALL studies (INCLUDED + EXCLUDED)
43+ with parsed analyses for the all_studies annotation
3744 output_dir: Output directory for caching results
3845
3946 Returns:
@@ -44,33 +51,53 @@ def process_studies(self, studies: List[Study], output_dir: str) -> List[Annotat
4451 if cached_results :
4552 # Check if cached results are still valid
4653 if self ._are_cached_results_valid (cached_results ):
47- logger .info (f"Loaded { len (cached_results )} cached annotation results" )
54+ logger .info (
55+ f"Loaded { len (cached_results )} cached annotation "
56+ "results"
57+ )
4858 self .annotation_results = cached_results
4959 return cached_results
5060 else :
51- logger .info ("Cached results are outdated, processing fresh annotations" )
52-
53- # Filter studies to only those that are included and have analyses
54- included_studies = [
55- study for study in studies
56- if study .status == StudyStatus .INCLUDED and study .analyses
57- ]
61+ logger .info (
62+ "Cached results are outdated, processing fresh "
63+ "annotations"
64+ )
5865
5966 if not included_studies :
60- logger .info ("No studies with analyses found for annotation" )
67+ logger .info (
68+ "No INCLUDED studies with analyses found for annotation"
69+ )
6170 return []
6271
63- logger .info (f"Processing { len (included_studies )} studies with analyses for annotation" )
72+ logger .info (
73+ f"Processing { len (included_studies )} INCLUDED studies with "
74+ "analyses for annotation"
75+ )
6476
6577 # Process all analysis-annotation combinations
6678 all_decisions = []
6779
68- # Process the "all_analyses" annotation if enabled
69- if self .config .include_all_analyses :
70- all_analyses_decisions = self ._create_all_analyses_annotations (included_studies )
80+ # Process the "all_analyses" annotation for INCLUDED studies
81+ if self .config .create_all_included_annotation :
82+ all_analyses_decisions = self ._create_all_analyses_annotations (
83+ included_studies ,
84+ annotation_name = "all_analyses"
85+ )
7186 all_decisions .extend (all_analyses_decisions )
7287
73- # Process custom annotations if any are defined
88+ # Process the "all_studies" annotation for ALL studies if enabled
89+ if self .config .create_all_from_search_annotation and all_studies :
90+ logger .info (
91+ f"Creating 'all_studies' annotation for "
92+ f"{ len (all_studies )} studies (INCLUDED + EXCLUDED)"
93+ )
94+ all_studies_decisions = self ._create_all_analyses_annotations (
95+ all_studies ,
96+ annotation_name = "all_studies"
97+ )
98+ all_decisions .extend (all_studies_decisions )
99+
100+ # Process custom annotations on INCLUDED studies only
74101 if self .config .annotations :
75102 custom_decisions = self ._process_custom_annotations (
76103 included_studies ,
@@ -84,12 +111,17 @@ def process_studies(self, studies: List[Study], output_dir: str) -> List[Annotat
84111
85112 return all_decisions
86113
87- def _create_all_analyses_annotations (self , studies : List [Study ]) -> List [AnnotationDecision ]:
114+ def _create_all_analyses_annotations (
115+ self ,
116+ studies : List [Study ],
117+ annotation_name : str = "all_analyses"
118+ ) -> List [AnnotationDecision ]:
88119 """
89- Create annotation decisions for the "all_analyses" annotation.
120+ Create annotation decisions for a default annotation.
90121
91122 Args:
92- studies: List of included studies with analyses
123+ studies: List of studies with analyses
124+ annotation_name: Name of the annotation to create
93125
94126 Returns:
95127 List of annotation decisions (all marked as included)
@@ -101,18 +133,21 @@ def _create_all_analyses_annotations(self, studies: List[Study]) -> List[Annotat
101133 # Create a unique analysis ID
102134 analysis_id = f"{ study .pmid } _analysis_{ i } "
103135
104- # Create decision for all_analyses annotation
136+ # Create decision for the annotation
105137 decision = AnnotationDecision (
106- annotation_name = "all_analyses" ,
138+ annotation_name = annotation_name ,
107139 analysis_id = analysis_id ,
108140 study_id = study .pmid ,
109141 include = True ,
110- reasoning = "All analyses included by default " ,
142+ reasoning = f "All analyses included in ' { annotation_name } ' " ,
111143 model_used = "none"
112144 )
113145 decisions .append (decision )
114146
115- logger .info (f"Created { len (decisions )} decisions for 'all_analyses' annotation" )
147+ logger .info (
148+ f"Created { len (decisions )} decisions for '{ annotation_name } ' "
149+ "annotation"
150+ )
116151 return decisions
117152
118153 def _process_custom_annotations (self , studies : List [Study ], model : str ) -> List [AnnotationDecision ]:
@@ -307,15 +342,24 @@ def _are_cached_results_valid(self, cached_results: List[AnnotationDecision]) ->
307342 # Check if we have the right number of annotations
308343 # (all_analyses + custom annotations)
309344 expected_annotation_count = 0
310- if self .config .include_all_analyses :
345+ if self .config .create_all_included_annotation :
346+ expected_annotation_count += 1
347+ if self .config .create_all_from_search_annotation :
311348 expected_annotation_count += 1
312349 expected_annotation_count += len (self .config .annotations )
313350
314351 # Get unique annotation names from cached results
315- cached_annotation_names = set (result .annotation_name for result in cached_results )
352+ cached_annotation_names = set (
353+ result .annotation_name for result in cached_results
354+ )
316355
317356 # Check if we have the expected annotations
318- if self .config .include_all_analyses and "all_analyses" not in cached_annotation_names :
357+ if (self .config .create_all_included_annotation and
358+ "all_analyses" not in cached_annotation_names ):
359+ return False
360+
361+ if (self .config .create_all_from_search_annotation and
362+ "all_studies" not in cached_annotation_names ):
319363 return False
320364
321365 # Check if we have all custom annotations
0 commit comments