1- fn run_manifest_rows_for_report (
2- runtime_root : & Path ,
3- manifest_path : & Path ,
4- input_file : & Path ,
5- participant_id : & str ,
6- loader : & GenotypeLoadOptions ,
7- filters : & [ String ] ,
8- ) -> Result < Vec < BTreeMap < String , String > > , String > {
9- let input_text = input_file. display ( ) . to_string ( ) ;
10- let store = GenotypeStore :: from_file_with_options ( Path :: new ( & input_text) , loader)
11- . map_err ( |err| err. to_string ( ) ) ?;
12- let workspace = bioscript_reporting:: FilesystemManifestWorkspace :: new ( runtime_root) ;
13- let manifest_path_text = manifest_path. display ( ) . to_string ( ) ;
14- let tasks =
15- bioscript_reporting:: collect_variant_manifest_tasks ( & workspace, & manifest_path_text, filters) ?;
16- let observations = store
17- . lookup_variants (
18- & tasks
19- . iter ( )
20- . map ( |task| task. manifest . spec . clone ( ) )
21- . collect :: < Vec < _ > > ( ) ,
22- )
23- . map_err ( |err| err. to_string ( ) ) ?;
24- Ok ( tasks
25- . into_iter ( )
26- . zip ( observations)
27- . map ( |( task, observation) | {
28- let resolved = Path :: new ( & task. manifest_path ) ;
29- variant_row (
30- runtime_root,
31- resolved,
32- & task. manifest . name ,
33- & task. manifest . tags ,
34- & observation,
35- Some ( participant_id) ,
36- )
37- } )
38- . collect ( ) )
39- }
40-
411struct ReportAnalysisOptions < ' a > {
422 runtime_root : & ' a Path ,
433 input_file : & ' a Path ,
444 participant_id : & ' a str ,
455 loader : & ' a GenotypeLoadOptions ,
466 output_dir : & ' a Path ,
477 observation_rows : & ' a [ BTreeMap < String , String > ] ,
48- filters : & ' a [ String ] ,
498 max_duration_ms : u64 ,
509}
5110
52- fn run_manifest_analyses_for_report (
53- manifest_path : & Path ,
54- options : & ReportAnalysisOptions < ' _ > ,
55- ) -> Result < Vec < serde_json:: Value > , String > {
56- let workspace = bioscript_reporting:: FilesystemManifestWorkspace :: new ( options. runtime_root ) ;
57- let manifest_path_text = manifest_path. display ( ) . to_string ( ) ;
58- let mut analyses = Vec :: new ( ) ;
59- for task in
60- bioscript_reporting:: collect_analysis_manifest_tasks ( & workspace, & manifest_path_text, options. filters ) ?
61- {
62- analyses. extend ( run_interpretations_for_report (
11+ struct CliReportAnalysisRunner < ' a > {
12+ runtime_root : & ' a Path ,
13+ input_file : & ' a Path ,
14+ participant_id : & ' a str ,
15+ loader : & ' a GenotypeLoadOptions ,
16+ output_dir : & ' a Path ,
17+ max_duration_ms : u64 ,
18+ }
19+
20+ impl bioscript_reporting:: ReportAnalysisRunner for CliReportAnalysisRunner < ' _ > {
21+ fn run_analysis_task (
22+ & self ,
23+ task : & bioscript_reporting:: AnalysisManifestTask ,
24+ observation_rows : & [ BTreeMap < String , String > ] ,
25+ _variant_observations : & [ bioscript_core:: VariantObservation ] ,
26+ _observations : & [ serde_json:: Value ] ,
27+ ) -> Result < Vec < serde_json:: Value > , String > {
28+ let options = ReportAnalysisOptions {
29+ runtime_root : self . runtime_root ,
30+ input_file : self . input_file ,
31+ participant_id : self . participant_id ,
32+ loader : self . loader ,
33+ output_dir : self . output_dir ,
34+ observation_rows,
35+ max_duration_ms : self . max_duration_ms ,
36+ } ;
37+ run_interpretations_for_report (
6338 Path :: new ( & task. manifest_path ) ,
6439 & task. manifest_name ,
6540 & task. interpretations ,
66- options,
67- ) ? ) ;
41+ & options,
42+ )
6843 }
69- Ok ( analyses)
7044}
7145
7246fn run_interpretations_for_report (
@@ -317,7 +291,6 @@ mod app_report_execution_tests {
317291 loader : & loader,
318292 output_dir : & dir,
319293 observation_rows : & [ ] ,
320- filters : & [ ] ,
321294 max_duration_ms : 10 ,
322295 } ;
323296
@@ -329,59 +302,6 @@ mod app_report_execution_tests {
329302 fs:: remove_dir_all ( dir) . unwrap ( ) ;
330303 }
331304
332- #[ test]
333- fn run_manifest_rows_for_report_reads_text_input_and_variant_manifest ( ) {
334- let dir = temp_dir ( "manifest-rows" ) ;
335- let manifest = dir. join ( "variant.yaml" ) ;
336- fs:: write (
337- & manifest,
338- r#"
339- schema: bioscript:variant:1.0
340- version: "1.0"
341- name: rs1
342- gene: ABC
343- identifiers:
344- rsids: [rs1]
345- coordinates:
346- grch38:
347- chrom: "1"
348- pos: 100
349- alleles:
350- kind: snv
351- ref: A
352- alts: [G]
353- "# ,
354- )
355- . unwrap ( ) ;
356- let input = dir. join ( "sample.txt" ) ;
357- fs:: write ( & input, "rsid\t genotype\n rs1\t A/G\n " ) . unwrap ( ) ;
358- let loader = GenotypeLoadOptions {
359- format : Some ( GenotypeSourceFormat :: Text ) ,
360- ..GenotypeLoadOptions :: default ( )
361- } ;
362-
363- let rows =
364- run_manifest_rows_for_report ( & dir, & manifest, & input, "p1" , & loader, & [ ] ) . unwrap ( ) ;
365- assert_eq ! ( rows. len( ) , 1 ) ;
366- assert_eq ! ( rows[ 0 ] [ "participant_id" ] , "p1" ) ;
367- assert_eq ! ( rows[ 0 ] [ "matched_rsid" ] , "rs1" ) ;
368- assert_eq ! ( rows[ 0 ] [ "genotype" ] , "AG" ) ;
369-
370- let missing_input = dir. join ( "missing.txt" ) ;
371- assert ! ( run_manifest_rows_for_report(
372- & dir,
373- & manifest,
374- & missing_input,
375- "p1" ,
376- & loader,
377- & [ ] ,
378- )
379- . unwrap_err( )
380- . contains( "No such file" ) ) ;
381-
382- fs:: remove_dir_all ( dir) . unwrap ( ) ;
383- }
384-
385305 #[ test]
386306 fn run_interpretations_executes_bioscript_analysis_and_builds_json_output ( ) {
387307 let dir = temp_dir ( "analysis-success" ) ;
@@ -426,7 +346,6 @@ if __name__ == "__main__":
426346 loader : & loader,
427347 output_dir : & output,
428348 observation_rows : & rows,
429- filters : & [ ] ,
430349 max_duration_ms : 1000 ,
431350 } ;
432351
0 commit comments