open Core open Bistro.Std open Bistro.EDSL open Bistro_bioinfo.Std open Bistro_utils open File_formats open Convergence_detection type post_analyses_dir type post_analyses = { t_choices_complete: text_file workflow ; t_choices_max: text_file workflow ; t_choices_plot: text_file workflow ; } let is_hyp ~hyp dataset_results = let model_prefix = dataset_results.model_prefix in let merged_results = dataset_results.merged_results in model_prefix = hyp let make_t_choices ~h0_merged_results ~ha_merged_results : post_analyses_dir directory workflow = let env = docker_image ~account:"carinerey" ~name:"r" ~tag:"07162018" () in let out = dest // "out" in workflow ~descr:"post_analyses.t_choices" [ docker env ( and_list [ mkdir_p dest ; cmd "Rscript" [ file_dump (string Scripts.calc_t_per_meth) ; opt "--H0" dep h0_merged_results; opt "--Ha" dep ha_merged_results; opt "--out " ident out; ]; ]) ] let post_analyses_of_dataset_results_l ~dataset_results_l = let h0_res = List.find dataset_results_l (is_hyp ~hyp: "H0") in let ha_res = List.find dataset_results_l (is_hyp ~hyp: "HaPCOC") in match (h0_res, ha_res) with | (Some h0, Some ha) -> let h0_merged_results = h0.merged_results in let ha_merged_results = ha.merged_results in let t_choices_dir = make_t_choices ~h0_merged_results ~ha_merged_results in let t_choices_max = t_choices_dir / selector ["out.max_per_meth.tsv"] in let t_choices_complete = t_choices_dir / selector ["out.complete.tsv"] in let t_choices_plot = t_choices_dir / selector ["out.pdf"] in Some {t_choices_max; t_choices_complete ; t_choices_plot} | _ -> failwith {| tata |} let repo_of_post_analyses ~prefix ~post_analyses = match post_analyses with | None -> [] | Some w -> Repo.[ item [prefix ^ ".t_choices.max_mcc_per_meth.tsv"] w.t_choices_max ; item [prefix ^ ".t_choices.complete.tsv"] w.t_choices_complete ; item [prefix ^ ".t_choices.pdf"] w.t_choices_plot ; ] |> Repo.shift "t_choices"