post_analyses.ml 18.2 KB
Newer Older
Carine Rey's avatar
Carine Rey committed
1 2 3 4 5 6 7 8
open Core
open Bistro.Std
open Bistro.EDSL
open Bistro_bioinfo.Std
open Bistro_utils
open File_formats
open Convergence_detection

Carine Rey's avatar
Carine Rey committed
9
type plot_trees
Carine Rey's avatar
Carine Rey committed
10
type post_analyses_dir
Carine Rey's avatar
Carine Rey committed
11
type sens_spe_t_choices_plot
Carine Rey's avatar
Carine Rey committed
12

Carine Rey's avatar
Carine Rey committed
13
type t_choices = {
Carine Rey's avatar
Carine Rey committed
14 15
  t_choices_complete: text_file workflow ;
  t_choices_max: text_file workflow ;
Carine Rey's avatar
Carine Rey committed
16
  t_choices_recall09: text_file workflow ;
Carine Rey's avatar
Carine Rey committed
17
  t_choices_plot: text_file workflow ;
Carine Rey's avatar
Carine Rey committed
18
  t_choices_condensed_plot: text_file workflow ;
Carine Rey's avatar
Carine Rey committed
19
  tree_prefix: string;
20 21
}

22 23 24 25 26 27 28 29 30 31
type auto_t_plot = {
  tree_prefix:string ;
  model_prefix:string ;
  auto_t_plot: svg workflow;
}


type post_analyses_res = {
  t_choices : t_choices option;
  auto_t_plot_l : auto_t_plot list option;
Carine Rey's avatar
Carine Rey committed
32
  dataset_results_l : dataset_res list;
33 34
}

Carine Rey's avatar
Carine Rey committed
35 36 37
type simu_infos = {
  simu_infos: text_file workflow option ;
  model_prefix: string ;
38
  tree_prefix: string ;
39
}
Carine Rey's avatar
Carine Rey committed
40

Carine Rey's avatar
Carine Rey committed
41 42 43 44 45 46 47
type reinfered_tree = {
  reinfered_tree : nw workflow ;
  input_tree : nhx workflow ;
  tree_prefix : string ;
  model_prefix : string ;
}

Carine Rey's avatar
Carine Rey committed
48
type post_analyses_simu = {
Carine Rey's avatar
Carine Rey committed
49
  simu_infos_l : simu_infos list;
50
  simu_infos_plot : text_file workflow ;
Carine Rey's avatar
Carine Rey committed
51
  trees_plot : text_file workflow ;
52
}
Carine Rey's avatar
Carine Rey committed
53

Carine Rey's avatar
Carine Rey committed
54
let r_env = docker_image ~account:"carinerey" ~name:"r_basics" ~tag:"08012018" ()
55
let py_env = docker_image ~account:"carinerey" ~name:"python_basics" ~tag:"07252018" ()
Carine Rey's avatar
Carine Rey committed
56 57

let is_hyp ~hyp (dataset_results :dataset_res) =
Carine Rey's avatar
Carine Rey committed
58 59 60
  let model_prefix = dataset_results.model_prefix in
  model_prefix = hyp

61 62
let build_cmd_t_choices (opt_name : string) mr_option  =
  match mr_option with
Carine Rey's avatar
Carine Rey committed
63 64
  | Some x -> [opt opt_name dep x]
  | None -> []
65

Carine Rey's avatar
Carine Rey committed
66
let make_t_choices ~h0_mr ~h0_NeBig_mr ~h0_NeSmall_mr ~haPCOC_mr ~haPC_mr ~haPC_NeBig_mr ~haPC_NeSmall_mr ~h0_NeBigInSmall_mr
67 68 69 70
    ~h0_NeSmallInBig_mr ~haPC_NeBigInSmall_mr ~haPC_NeSmallInBig_mr
    ~h0_NeG1_mr ~h0_NeG2_mr ~h0_NeG3_mr ~h0_NeG4_mr ~h0_NeG5_mr
    ~haPC_NeG1_mr ~haPC_NeG2_mr ~haPC_NeG3_mr ~haPC_NeG4_mr ~haPC_NeG5_mr () : post_analyses_dir directory workflow =

71
  let env = r_env in
Carine Rey's avatar
Carine Rey committed
72
  let out = dest // "out" in
73
  let cmd_mr = List.map [
74 75 76 77 78 79 80 81 82 83
      ("--H0_NeG1"           , h0_NeG1_mr          );
      ("--H0_NeG2"           , h0_NeG2_mr          );
      ("--H0_NeG3"           , h0_NeG3_mr          );
      ("--H0_NeG4"           , h0_NeG4_mr          );
      ("--H0_NeG5"           , h0_NeG5_mr          );
      ("--HaPC_NeG1"         , haPC_NeG1_mr          );
      ("--HaPC_NeG2"         , haPC_NeG2_mr          );
      ("--HaPC_NeG3"         , haPC_NeG3_mr          );
      ("--HaPC_NeG4"         , haPC_NeG4_mr          );
      ("--HaPC_NeG5"         , haPC_NeG5_mr          );
Carine Rey's avatar
Carine Rey committed
84 85 86 87 88 89 90 91 92 93 94 95 96
      ("--H0"                , h0_mr          );
      ("--H0NeBig"           , h0_NeBig_mr    );
      ("--H0NeSmall"         , h0_NeSmall_mr  );
      ("--H0NeBigInSmall"    , h0_NeBigInSmall_mr  );
      ("--H0NeSmallInBig"    , h0_NeSmallInBig_mr  );
      ("--HaPCOC"            , haPCOC_mr      );
      ("--HaPC"              , haPC_mr        );
      ("--HaPCNeBig"         , haPC_NeBig_mr  );
      ("--HaPCNeSmall"       , haPC_NeSmall_mr);
      ("--HaPCNeBigInSmall"  , haPC_NeBigInSmall_mr  );
      ("--HaPCNeSmallInBig"  , haPC_NeSmallInBig_mr);
    ] ~f:(fun (opt_name, mr_option) -> build_cmd_t_choices opt_name mr_option)
               |> List.concat in
Carine Rey's avatar
Carine Rey committed
97
  workflow ~descr:"post_analyses.t_choices" [
98
    docker env (
Carine Rey's avatar
Carine Rey committed
99 100
      and_list [
        mkdir_p dest ;
101
        cmd "Rscript" ([
Carine Rey's avatar
Carine Rey committed
102 103 104 105 106
            [file_dump (string Scripts.calc_t_per_meth) ;
             opt "--out " ident out;
            ] ;
            cmd_mr ;
          ] |> List.concat) ;
107
      ])
Carine Rey's avatar
Carine Rey committed
108 109
  ]

Carine Rey's avatar
Carine Rey committed
110 111 112 113
let make_simu_infos ?(descr="") ?(fna_infos) ~faa ~tree_sc : text_file workflow =
  let env = docker_image ~account:"carinerey" ~name:"pcoc" ~tag:"07022018" () in
  workflow ~descr:("post_analyses.simu_infos." ^ descr) [
    cmd "python" ~env [
114 115 116 117 118
      file_dump (string Scripts.calc_simu_infos) ;
      opt "--faa" dep faa;
      opt "--tree" dep tree_sc;
      option ( opt "--fna_infos" dep) fna_infos;
      opt "--output " ident dest;
Carine Rey's avatar
Carine Rey committed
119 120 121
    ];
  ]

122
let group_simu_infos ~simu_infos_l : simu_infos directory workflow =
123
  let env = r_env in
124
  let cmd_cp_l = List.map simu_infos_l ~f:(fun s ->
125
      match s.simu_infos with
Carine Rey's avatar
Carine Rey committed
126
      | Some w -> [cmd "cp" [dep w ; tmp // (s.tree_prefix ^"@"^ s.model_prefix ^ ".tsv")]]
127 128 129 130 131
      | None -> []
    ) |> List.concat
  in
  let out = dest // "out" in
  workflow ~descr:"post_analyses.plot_simu_infos" [
132
    docker env (
133
      and_list ([
134 135 136 137 138 139 140 141 142 143 144
          [mkdir_p dest];
          [mkdir_p tmp ];
          cmd_cp_l;
          [cmd "Rscript" [
              file_dump (string Scripts.plot_hyp_simu_validation) ;
              opt "--input_dir" ident tmp;
              opt "--out " ident out;
            ];]
        ]
          |> List.concat)
    )
145 146
  ]

Carine Rey's avatar
Carine Rey committed
147
let plot_trees ~reinfered_tree_l : plot_trees directory workflow =
148 149
  let env_r = r_env in
  let env_py = py_env in
Carine Rey's avatar
Carine Rey committed
150
  let cmd_cp_l = List.map reinfered_tree_l ~f:(fun rt -> [
Carine Rey's avatar
Carine Rey committed
151 152
        cmd "cp" [dep rt.reinfered_tree ; tmp // (rt.tree_prefix ^"@"^ rt.model_prefix ^ ".nw")];
        cmd "cp" [dep rt.input_tree ; tmp // (rt.tree_prefix ^"@input_tree.nw")]
Carine Rey's avatar
Carine Rey committed
153 154 155
      ]) |> List.concat
  in
  let out = dest // "out" in
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
  workflow ~descr:"post_analyses.plot_trees" ([
    [mkdir_p dest];
    [mkdir_p tmp ];
    cmd_cp_l;
    [cmd "Rscript" ~env:env_r [
        file_dump (string Scripts.plot_trees) ;
        opt "--input_dir" ident tmp;
        opt "--out " ident out;
    ];
    ];
    [cmd "python" ~env:env_py [
        file_dump (string Scripts.get_bl_trees) ;
        opt "--input_dir" ident tmp;
        opt "--out " ident out;
    ];
    ];
    ]|> List.concat)
Carine Rey's avatar
Carine Rey committed
173

174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
let get_merged_results_opt hx = match hx with
  | Some w -> Some w.merged_results
  | None -> None

type res_all_hyp = {
  h0_res            : dataset_res option ;
  h0_NeBig_res      : dataset_res option ;
  h0_NeSmall_res    : dataset_res option ;
  ha_PC_res         : dataset_res option ;
  ha_PCOC_res       : dataset_res option ;
  ha_PC_NeBig_res   : dataset_res  option ;
  ha_PC_NeSmall_res : dataset_res option ;
  h0_NeBigInSmall_res : dataset_res option ;
  h0_NeSmallInBig_res : dataset_res option ;
  ha_PC_NeBigInSmall_res : dataset_res option ;
  ha_PC_NeSmallInBig_res : dataset_res option ;
190 191 192 193 194 195 196 197 198 199
  h0_NeG1_res   : dataset_res option ;
  h0_NeG2_res   : dataset_res option ;
  h0_NeG3_res   : dataset_res option ;
  h0_NeG4_res   : dataset_res option ;
  h0_NeG5_res   : dataset_res option ;
  haPC_NeG1_res : dataset_res option ;
  haPC_NeG2_res : dataset_res option ;
  haPC_NeG3_res : dataset_res option ;
  haPC_NeG4_res : dataset_res option ;
  haPC_NeG5_res : dataset_res option ;
Carine Rey's avatar
Carine Rey committed
200
}
201 202

let make_t_choices_per_couple {h0_res; h0_NeBig_res; h0_NeSmall_res; ha_PC_res; ha_PCOC_res; ha_PC_NeBig_res ; ha_PC_NeSmall_res;
203 204 205 206 207 208 209 210
                               h0_NeBigInSmall_res; h0_NeSmallInBig_res; ha_PC_NeBigInSmall_res; ha_PC_NeSmallInBig_res; 
                               h0_NeG1_res; h0_NeG2_res; h0_NeG3_res; h0_NeG4_res; h0_NeG5_res;
                               haPC_NeG1_res;
                               haPC_NeG2_res;
                               haPC_NeG3_res;
                               haPC_NeG4_res;
                               haPC_NeG5_res;
                                } =
211

Carine Rey's avatar
Carine Rey committed
212 213 214 215 216
  let h0_mr           = get_merged_results_opt h0_res in
  let h0_NeBig_mr     = get_merged_results_opt h0_NeBig_res in
  let h0_NeSmall_mr   = get_merged_results_opt h0_NeSmall_res in
  let h0_NeBigInSmall_mr   = get_merged_results_opt h0_NeBigInSmall_res in
  let h0_NeSmallInBig_mr   = get_merged_results_opt h0_NeSmallInBig_res in
217

Carine Rey's avatar
Carine Rey committed
218
  let haPCOC_mr       = get_merged_results_opt ha_PCOC_res in
219

Carine Rey's avatar
Carine Rey committed
220 221 222 223 224
  let haPC_mr         = get_merged_results_opt ha_PC_res in
  let haPC_NeBig_mr   = get_merged_results_opt ha_PC_NeBig_res in
  let haPC_NeSmall_mr = get_merged_results_opt ha_PC_NeSmall_res in
  let haPC_NeBigInSmall_mr   = get_merged_results_opt ha_PC_NeBigInSmall_res in
  let haPC_NeSmallInBig_mr = get_merged_results_opt ha_PC_NeSmallInBig_res in
225 226 227 228 229 230 231 232 233 234 235
  
  let h0_NeG1_mr   = get_merged_results_opt h0_NeG1_res   in
  let h0_NeG2_mr   = get_merged_results_opt h0_NeG2_res   in
  let h0_NeG3_mr   = get_merged_results_opt h0_NeG3_res   in
  let h0_NeG4_mr   = get_merged_results_opt h0_NeG4_res   in
  let h0_NeG5_mr   = get_merged_results_opt h0_NeG5_res   in
  let haPC_NeG1_mr = get_merged_results_opt haPC_NeG1_res in
  let haPC_NeG2_mr = get_merged_results_opt haPC_NeG2_res in
  let haPC_NeG3_mr = get_merged_results_opt haPC_NeG3_res in
  let haPC_NeG4_mr = get_merged_results_opt haPC_NeG4_res in
  let haPC_NeG5_mr = get_merged_results_opt haPC_NeG5_res in
236

Carine Rey's avatar
Carine Rey committed
237
  make_t_choices ~h0_mr ~h0_NeBig_mr ~h0_NeSmall_mr ~haPCOC_mr ~haPC_mr ~haPC_NeBig_mr ~haPC_NeSmall_mr ~h0_NeBigInSmall_mr
238 239 240 241 242 243 244 245 246 247 248
    ~h0_NeSmallInBig_mr ~haPC_NeBigInSmall_mr ~haPC_NeSmallInBig_mr ~h0_NeG1_mr  
    ~h0_NeG2_mr  
    ~h0_NeG3_mr  
    ~h0_NeG4_mr  
    ~h0_NeG5_mr  
    ~haPC_NeG1_mr
    ~haPC_NeG2_mr
    ~haPC_NeG3_mr
    ~haPC_NeG4_mr
    ~haPC_NeG5_mr
    ()
249 250


Carine Rey's avatar
Carine Rey committed
251
let get_t_choices ~(dataset_results_l: dataset_res list) : t_choices option =
252 253 254
  let h0_res                = List.find dataset_results_l (is_hyp ~hyp: "H0"               ) in
  let h0_NeBig_res          = List.find dataset_results_l (is_hyp ~hyp: "H0_NeBig"         ) in
  let h0_NeSmall_res        = List.find dataset_results_l (is_hyp ~hyp: "H0_NeSmall"       ) in
255 256
  let h0_NeBigInSmall_res   = List.find dataset_results_l (is_hyp ~hyp: "H0_BigNeInSmallNe") in
  let h0_NeSmallInBig_res   = List.find dataset_results_l (is_hyp ~hyp: "H0_SmallNeInBigNe") in
257

258
  let ha_PCOC_res           = List.find dataset_results_l (is_hyp ~hyp: "HaPCOC"              ) in
259

260 261 262
  let ha_PC_res              = List.find dataset_results_l (is_hyp ~hyp: "HaPC"               ) in
  let ha_PC_NeBig_res        = List.find dataset_results_l (is_hyp ~hyp: "HaPC_NeBig"         ) in
  let ha_PC_NeSmall_res      = List.find dataset_results_l (is_hyp ~hyp: "HaPC_NeSmall"       ) in
263 264 265
  let ha_PC_NeBigInSmall_res = List.find dataset_results_l (is_hyp ~hyp: "HaPC_BigNeInSmallNe") in
  let ha_PC_NeSmallInBig_res = List.find dataset_results_l (is_hyp ~hyp: "HaPC_SmallNeInBigNe") in

266 267 268 269 270 271 272 273 274 275 276 277 278 279
  let h0_NeG1_res   = List.find dataset_results_l (is_hyp ~hyp: "H0_NeG1"               ) in
  let h0_NeG2_res   = List.find dataset_results_l (is_hyp ~hyp: "H0_NeG2"               ) in
  let h0_NeG3_res   = List.find dataset_results_l (is_hyp ~hyp: "H0_NeG3"               ) in
  let h0_NeG4_res   = List.find dataset_results_l (is_hyp ~hyp: "H0_NeG4"               ) in
  let h0_NeG5_res   = List.find dataset_results_l (is_hyp ~hyp: "H0_NeG5"               ) in
  let haPC_NeG1_res = List.find dataset_results_l (is_hyp ~hyp: "HaPC_NeG1"             ) in
  let haPC_NeG2_res = List.find dataset_results_l (is_hyp ~hyp: "HaPC_NeG2"             ) in
  let haPC_NeG3_res = List.find dataset_results_l (is_hyp ~hyp: "HaPC_NeG3"             ) in
  let haPC_NeG4_res = List.find dataset_results_l (is_hyp ~hyp: "HaPC_NeG4"             ) in
  let haPC_NeG5_res = List.find dataset_results_l (is_hyp ~hyp: "HaPC_NeG5"             ) in
  

  match (ha_PCOC_res) with
  | ( Some ha_PCOC) ->
280
    let t_choices_dir = make_t_choices_per_couple {h0_res; h0_NeBig_res; h0_NeSmall_res; ha_PC_res; ha_PCOC_res; ha_PC_NeBig_res ; ha_PC_NeSmall_res;
281 282 283
                                                   h0_NeBigInSmall_res; h0_NeSmallInBig_res; ha_PC_NeBigInSmall_res; ha_PC_NeSmallInBig_res ;
                                                   h0_NeG1_res; h0_NeG2_res; h0_NeG3_res; h0_NeG4_res; h0_NeG5_res;
                                                   haPC_NeG1_res; haPC_NeG2_res;haPC_NeG3_res; haPC_NeG4_res; haPC_NeG5_res; }  in
Carine Rey's avatar
Carine Rey committed
284 285
    let t_choices_max = t_choices_dir / selector ["out.max_MCC_per_meth.tsv"] in
    let t_choices_recall09 = t_choices_dir / selector ["out.recall09_per_meth.tsv"] in
286 287
    let t_choices_complete = t_choices_dir / selector ["out.complete.tsv"] in
    let t_choices_plot = t_choices_dir / selector ["out.pdf"] in
Carine Rey's avatar
Carine Rey committed
288
    let t_choices_condensed_plot = t_choices_dir / selector ["out_condensed.pdf"] in
289
    let tree_prefix = ha_PCOC.tree_prefix in
Carine Rey's avatar
Carine Rey committed
290
    Some {t_choices_max; t_choices_recall09; t_choices_complete ; t_choices_plot; t_choices_condensed_plot; tree_prefix}
291
  | _ -> None
Carine Rey's avatar
Carine Rey committed
292

293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313


let plot_det_meth_res_auto_t ~t_choices ~dataset_results_l =
  match t_choices with
  | None -> None
  | Some w -> Some (
      List.map dataset_results_l ~f:(fun (dataset_results : dataset_res) ->
          let tree_prefix = dataset_results.tree_prefix in
          let model_prefix = dataset_results.model_prefix in
          let ready_dataset = dataset_results.dataset.dataset in
          let tree = Tree_dataset.tree ready_dataset.tree_dataset `Detection in
          let faa = ready_dataset.faa in
          let tsv = dataset_results.merged_results in
          let res_by_tools = dataset_results.res_by_tools in
          let plot_all_sites = true in
          let t_choices = w.t_choices_max in
          let auto_t_plot = plot_merge_results ~t_choices ~plot_all_sites ~res_by_tools ~tree ~faa ~tsv () in
          {tree_prefix; model_prefix ; auto_t_plot}
        )
    )

Carine Rey's avatar
Carine Rey committed
314 315 316
let get_simu_infos ~(dataset:Dataset.t) =
  let model_prefix = dataset.model_prefix in
  let ready_dataset = dataset.dataset in
Carine Rey's avatar
Carine Rey committed
317 318 319 320
  let faa = ready_dataset.faa in
  let tree_sc = Tree_dataset.tree ready_dataset.tree_dataset `Detection in
  let fna_infos = ready_dataset.fna_infos in
  match fna_infos with
321 322
  | Some w -> Some (make_simu_infos ~descr:model_prefix ~faa ~tree_sc ~fna_infos:w)
  | None -> None (*make_simu_infos ~faa ~tree_sc*)
Carine Rey's avatar
Carine Rey committed
323 324


Carine Rey's avatar
Carine Rey committed
325
let post_analyses_res_of_dataset_results_l ~dataset_results_l =
Carine Rey's avatar
Carine Rey committed
326
  let t_choices = get_t_choices ~dataset_results_l in
327
  let auto_t_plot_l = plot_det_meth_res_auto_t ~t_choices ~dataset_results_l in
Carine Rey's avatar
Carine Rey committed
328
  {t_choices; auto_t_plot_l;dataset_results_l}
Carine Rey's avatar
Carine Rey committed
329 330 331 332 333 334

let post_analyses_simu_of_simu_dataset_l ~simu_dataset_l =
  let simu_infos_l = List.map simu_dataset_l ~f:(fun dataset ->
      {simu_infos = (get_simu_infos ~dataset);
       tree_prefix = dataset.tree_prefix ;
       model_prefix = dataset.model_prefix
335 336
      }
    ) in
Carine Rey's avatar
Carine Rey committed
337 338 339 340 341 342 343 344 345 346
  let reinfered_tree_l = List.map simu_dataset_l ~f:(fun dataset ->
      let rd = dataset.dataset in
      let phy = Bppsuite.fa2phy rd.fna in
      let input_tree = rd.input_tree in
      let reinfered_tree = Phyml.phyml_tree ~tree:input_tree phy in
      {reinfered_tree; input_tree;
       tree_prefix = dataset.tree_prefix ;
       model_prefix = dataset.model_prefix
      }
    ) in
347
  let simu_infos_plot = group_simu_infos ~simu_infos_l / selector ["out.pdf"] in
Carine Rey's avatar
Carine Rey committed
348 349
  let trees_plot = plot_trees ~reinfered_tree_l / selector ["out.pdf"] in
  {simu_infos_l; simu_infos_plot; trees_plot}
Carine Rey's avatar
Carine Rey committed
350

Carine Rey's avatar
Carine Rey committed
351 352


353
let plot_sens_spe_t_choices ~t_choices_l ~dataset_results_l ~profile_prefix : sens_spe_t_choices_plot directory workflow =
354
  let env = r_env in
Carine Rey's avatar
Carine Rey committed
355 356 357 358
  let t_choices_dir = tmp // "t_choices_dir" in
  let merged_results_dir = tmp // "merged_results_dir" in
  let out = dest // "out" in
  let cmd_cp_t_choices_l = List.map t_choices_l ~f:(fun t_choices ->
Carine Rey's avatar
Carine Rey committed
359
      cmd "cp" [dep t_choices.t_choices_recall09 ; t_choices_dir // (t_choices.tree_prefix ^ ".tsv")]
Carine Rey's avatar
Carine Rey committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
    )
  in
  let cmd_cp_merged_results_l = List.map dataset_results_l ~f:(fun dataset_results ->
      cmd "cp" [dep dataset_results.merged_results ; merged_results_dir // (dataset_results.tree_prefix ^"@"^ dataset_results.model_prefix ^ ".tsv")]
    )
  in
  workflow ~descr:"post_analyses.plot_sens_spe_all_trees" [
    docker env (
      and_list ([
          [mkdir_p dest];
          [mkdir_p t_choices_dir ];
          [mkdir_p merged_results_dir ];
          cmd_cp_t_choices_l;
          cmd_cp_merged_results_l;
          [cmd "Rscript" [
              file_dump (string Scripts.plot_sens_spe_all_trees) ;
              opt "--input_dir" ident t_choices_dir;
              opt "--input_dir2" ident merged_results_dir;
378
              opt "--profil" string profile_prefix;
Carine Rey's avatar
Carine Rey committed
379 380 381 382 383 384 385
              opt "--out " ident out;
            ];]
        ]
          |> List.concat)
    )
  ]

386
let repo_post_analyses_all_trees_of_all_post_analyses_per_tree ~profile_prefix ~all_post_analyses_per_tree =
Carine Rey's avatar
Carine Rey committed
387 388 389 390 391 392 393 394 395
  let t_choices_l = List.map all_post_analyses_per_tree ~f:(fun post_analyses_res ->
      match post_analyses_res.t_choices with
      | Some w -> [w]
      | None -> []
    ) |> List.concat
  in
  let dataset_results_l =  List.map all_post_analyses_per_tree ~f:(fun post_analyses_res ->
      post_analyses_res.dataset_results_l) |> List.concat
  in
396
  let sens_spe_t_choices_plot = plot_sens_spe_t_choices  ~t_choices_l ~dataset_results_l ~profile_prefix in
Carine Rey's avatar
Carine Rey committed
397 398 399 400 401 402 403 404 405
  [Repo.[
      item ["sens_spe.tsv"] (sens_spe_t_choices_plot / selector ["out.sens_spe_auto_t.tsv"]);
      item ["all_t_choices.tsv"] (sens_spe_t_choices_plot / selector ["out.t_per_tree.tsv"]);
    ] |> Repo.shift "pdf_tsv" ;
   Repo.[
     item ["sens_spe.pdf"] (sens_spe_t_choices_plot / selector ["out.sens_spe_auto_t.pdf"]);
     item ["all_t_choices.pdf"] (sens_spe_t_choices_plot / selector ["out.t_per_tree.pdf"]);
   ]
  ] |> List.concat
Carine Rey's avatar
Carine Rey committed
406

Carine Rey's avatar
Carine Rey committed
407
let repo_of_post_analyses_simu ~post_analyses_simu =
Carine Rey's avatar
Carine Rey committed
408
  [
409
    Repo.[
Carine Rey's avatar
Carine Rey committed
410 411
      item ["hypothesis_validation.pdf"] post_analyses_simu.simu_infos_plot ;
      item ["trees_validation.pdf"] post_analyses_simu.trees_plot;
Carine Rey's avatar
Carine Rey committed
412
    ]
413
    ;
Carine Rey's avatar
Carine Rey committed
414
    (List.map post_analyses_simu.simu_infos_l ~f:(fun simu_infos ->
415 416 417 418
         match simu_infos.simu_infos with
         | None -> []
         | Some w ->
           Repo.[
Carine Rey's avatar
Carine Rey committed
419
             item [simu_infos.tree_prefix ^ "@" ^ simu_infos.model_prefix ^ ".tsv"] w
Carine Rey's avatar
Carine Rey committed
420 421
           ] |> Repo.shift simu_infos.tree_prefix
           |> Repo.shift "tsv"
422 423
       ) |> List.concat
    );
Carine Rey's avatar
Carine Rey committed
424
  ] |> List.concat
Carine Rey's avatar
Carine Rey committed
425
  |> Repo.shift "Simulation_details"
Carine Rey's avatar
Carine Rey committed
426 427

let repo_of_post_analyses_res ~prefix ~post_analyses_res =
428 429 430 431
  [
    (match post_analyses_res.t_choices with
     | None -> []
     | Some w ->
Carine Rey's avatar
Carine Rey committed
432 433 434 435 436 437 438 439 440 441 442
       [
         Repo.[
           item [prefix ^ ".t_choices.max_mcc_per_meth.tsv"] w.t_choices_max ;
           item [prefix ^ ".t_choices.recall09_per_meth.tsv"] w.t_choices_recall09 ;
           item [prefix ^ ".t_choices.complete.tsv"] w.t_choices_complete ;
         ] |> Repo.shift "pdf_tsv" ;
         Repo.[
           item [prefix ^ ".t_choices.pdf"] w.t_choices_plot ;
           item [prefix ^ ".t_choices.condensed.pdf"] w.t_choices_condensed_plot ;
         ]
       ] |> List.concat
443
    );
Carine Rey's avatar
Carine Rey committed
444
    (*(
445 446 447 448 449 450 451 452 453 454
      match post_analyses_res.auto_t_plot_l with
      | None -> []
      | Some w_l ->
        List.map w_l ~f:(fun w ->
            Repo.[
              let prefix_f = w.tree_prefix ^ "@" ^ w.model_prefix in
              item [ prefix_f ^ ".auto_t.svg"] w.auto_t_plot ;
            ]
          )|> List.concat
        |> Repo.shift "auto_t_pdf"
Carine Rey's avatar
Carine Rey committed
455
      );*)
456
  ] |> List.concat
Carine Rey's avatar
Carine Rey committed
457