convergence_detection.ml 5.09 KB
Newer Older
Carine Rey's avatar
Carine Rey committed
1
open Core
Philippe Veber's avatar
Philippe Veber committed
2 3
open Bistro.Shell_dsl
open Bistro
Carine Rey's avatar
Carine Rey committed
4

Philippe Veber's avatar
Philippe Veber committed
5
type result = [
Philippe Veber's avatar
Philippe Veber committed
6 7 8 9 10 11 12 13 14 15 16
  | `Pcoc of [`pcoc] dworkflow
  | `Pcoc_gamma of [`pcoc] dworkflow
  | `Pcoc_C60 of [`pcoc] dworkflow
  | `Diffsel of [`diffsel] dworkflow
  | `Identical_LG of [`identical] dworkflow
  | `Identical_WAG of [`identical] dworkflow
  | `Topological_LG of [`topological] dworkflow
  | `Topological_WAG of [`topological] dworkflow
  | `Tdg09 of [`tdg09] dworkflow
  | `Multinomial of [`multinomial] dworkflow
  | `Msd of [`msd] dworkflow * float
Philippe Veber's avatar
Philippe Veber committed
17
]
Carine Rey's avatar
Carine Rey committed
18

Philippe Veber's avatar
Philippe Veber committed
19 20 21
let meth_string_of_result = function
  | `Pcoc _ -> "pcoc"
  | `Pcoc_gamma _ -> "pcoc_gamma"
Carine Rey's avatar
Carine Rey committed
22
  | `Pcoc_C60 _ -> "pcoc_gamma"
Philippe Veber's avatar
Philippe Veber committed
23
  | `Diffsel _ -> "diffsel"
Carine Rey's avatar
Carine Rey committed
24 25
  | `Identical_LG _ -> "identical_LG"
  | `Identical_WAG _ -> "identical_WAG"
26 27
  | `Topological_LG _ -> "topological_LG"
  | `Topological_WAG _ -> "topological_WAG"
Carine Rey's avatar
typo  
Carine Rey committed
28
  | `Tdg09 _ -> "tdg09"
29
  | `Multinomial _ -> "multinomial"
30
  | `Msd (_, e) -> sprintf "msd_%f" e
Carine Rey's avatar
Carine Rey committed
31 32 33 34

type dataset_res = {
  model_prefix : string ;
  tree_prefix : string ;
Carine Rey's avatar
Carine Rey committed
35
  dataset : Dataset.t ;
Philippe Veber's avatar
Philippe Veber committed
36
  res_by_tools: result list ;
Philippe Veber's avatar
Philippe Veber committed
37 38
  merged_results : text_file pworkflow ;
  plot_merged_results : svg pworkflow ;
Philippe Veber's avatar
Philippe Veber committed
39
}
Carine Rey's avatar
Carine Rey committed
40

Philippe Veber's avatar
Philippe Veber committed
41
let merge_results ?fna_infos ~res_by_tools () : text_file pworkflow =
Carine Rey's avatar
Carine Rey committed
42 43 44 45
  let fna_infos = match fna_infos with
    | Some (sw) -> sw
    | _ -> None
  in
Carine Rey's avatar
Carine Rey committed
46
  let command = List.map res_by_tools ~f:(fun res ->
Philippe Veber's avatar
Philippe Veber committed
47
      let w = match res with
Carine Rey's avatar
Carine Rey committed
48
        | `Pcoc d -> Pcoc.results d
Philippe Veber's avatar
Philippe Veber committed
49
        | `Pcoc_gamma d -> Pcoc.results d
Carine Rey's avatar
Carine Rey committed
50
        | `Pcoc_C60 d -> Pcoc.results d
Philippe Veber's avatar
Philippe Veber committed
51
        | `Diffsel d -> Diffsel.selector d
Carine Rey's avatar
Carine Rey committed
52 53
        | `Identical_LG d -> Identical.results d
        | `Identical_WAG d -> Identical.results d
54 55 56
        | `Topological_LG d -> Topological.results d
        | `Topological_WAG d -> Topological.results d
        | `Tdg09 d -> Tamuri.results d
57
        | `Multinomial d -> Multinomial.results d
Philippe Veber's avatar
Philippe Veber committed
58
        | `Msd (d, _) -> Msd.results d
Philippe Veber's avatar
Philippe Veber committed
59 60 61 62
      in
      let opt = match res with
        | `Pcoc _ -> string "--pcoc"
        | `Pcoc_gamma _ -> string "--pcoc_gamma"
Carine Rey's avatar
Carine Rey committed
63
        | `Pcoc_C60 _ -> string "--pcoc_C60"
Philippe Veber's avatar
Philippe Veber committed
64
        | `Diffsel _ -> string "--diffsel"
Carine Rey's avatar
Carine Rey committed
65 66
        | `Identical_LG _ -> string "--identical_LG"
        | `Identical_WAG _ -> string "--identical_WAG"
67 68 69
        | `Topological_LG _ -> string "--topological_LG"
        | `Topological_WAG _ -> string "--topological_WAG"
        | `Tdg09 _ -> string "--tdg09"
70
        | `Multinomial _ -> string "--multinomial"
Philippe Veber's avatar
Philippe Veber committed
71
        | `Msd (_, e) -> string (sprintf "--msd %f" e)
Philippe Veber's avatar
Philippe Veber committed
72 73 74
      in
      seq ~sep:" " [opt; dep w]
    )
Carine Rey's avatar
Carine Rey committed
75
  in
Philippe Veber's avatar
Philippe Veber committed
76 77
  Workflow.shell ~descr:"convergence_detection.merge_results" [
    cmd "python" ~img:Env.env_py [
78 79 80
      file_dump (string Scripts.merge_det_results) ;
      opt "-o" ident dest ;
      seq ~sep:" " command ;
Carine Rey's avatar
Carine Rey committed
81
      option( opt "--fna_infos" dep ) fna_infos;
82
    ] ;
Carine Rey's avatar
Carine Rey committed
83 84
  ]

Philippe Veber's avatar
Philippe Veber committed
85 86
let plot_merge_results ?t_choices ~plot_all_sites ~(res_by_tools:result list) ~tree ~faa ~tsv (): svg pworkflow =
  let img = Pcoc.img in
Carine Rey's avatar
Carine Rey committed
87 88
  (* use of pcoc env due to its working X server for dra plot with ete3 *)
  let meths = List.map res_by_tools ~f:(fun res ->
89 90 91 92 93 94 95 96 97
      let opt = match res with
        | `Pcoc _ -> "PCOC,PC,OC"
        | `Pcoc_gamma _ -> "PCOC_gamma,PC_gamma,OC_gamma,"
        | `Pcoc_C60 _ -> "PCOC_C60,PC_C60,OC_C60,"
        | `Diffsel _ -> "Diffsel_mean,Diffsel_max"
        | `Identical_LG _ -> "Identical_LG08"
        | `Identical_WAG _ -> "Identical_WAG01"
        | `Topological_LG _ -> "Topological_LG08"
        | `Topological_WAG _ -> "Topological_WAG01"
Carine Rey's avatar
Carine Rey committed
98
        | `Tdg09 _ -> "Tdg09_1MinusFDR,Tdg09_1MinusLRT,Tdg09_prob_post"
Carine Rey's avatar
Carine Rey committed
99
        | `Multinomial _ -> "Mutinomial_1MinusLRT"
Carine Rey's avatar
Carine Rey committed
100
        | `Msd _ -> "Msd_0.05_1MinusP"
101 102 103
      in
      string opt
    ) |> seq ~sep:","
Carine Rey's avatar
Carine Rey committed
104
  in
105
  let default_t = List.map res_by_tools ~f:(fun res ->
106
      let opt = match res with
LANORE Vincent's avatar
LANORE Vincent committed
107 108 109 110 111 112 113 114 115 116 117
        | `Pcoc _ -> "PCOC:0,PC:0,OC:0"
        | `Pcoc_gamma _ -> "PCOC_gamma:0,PC_gamma:0,OC_gamma:0"
        | `Pcoc_C60 _ -> "PCOC_C60:0,PC_C60:0,OC_C60:0"
        | `Diffsel _ -> "Diffsel_mean:0,Diffsel_max:0"
        | `Identical_LG _ -> "Identical_LG08:0"
        | `Identical_WAG _ -> "Identical_WAG01:0"
        | `Topological_LG _ -> "Topological_LG08:0"
        | `Topological_WAG _ -> "Topological_WAG01:0"
        | `Tdg09 _ -> "Tdg09_1MinusFDR:0,Tdg09_prob_post:0,Tdg09_1MinusLRT:0"
        | `Multinomial _ -> "Mutinomial_1MinusLRT:0"
        | `Msd _ -> "Msd_0.05_1MinusP:0"
Carine Rey's avatar
Carine Rey committed
118

119 120 121
      in
      string opt
    ) |> seq ~sep:","
122
  in
123 124 125 126
  let meths_t = match t_choices with
    | Some _ -> None
    | None -> Some default_t
  in
Carine Rey's avatar
Carine Rey committed
127
  let out = dest // "results.svg" in
Philippe Veber's avatar
Philippe Veber committed
128 129 130 131
  let inner =
    Workflow.shell ~descr:"convergence_detection.plot_results" [
      within_container img (
        and_list [
132
          mkdir_p dest ;
Carine Rey's avatar
Carine Rey committed
133

Philippe Veber's avatar
Philippe Veber committed
134
          cmd "python" [
135
            Utils.script_dump Scripts.[ diffsel_script_utils ; plot_data ; plot_convergent_sites ] ;
Philippe Veber's avatar
Philippe Veber committed
136 137 138 139 140 141 142 143 144
            opt "-msa" dep faa ;
            opt "-tsv" dep tsv ;
            opt "-tree" dep tree ;
            opt "-out" ident out ;
            opt "-meth" ident meths ;
            option (opt "-t" ident) meths_t ;
            option (opt "--t_tsv" dep) t_choices ;
            flag string "--all_sites" plot_all_sites ;
          ]
Carine Rey's avatar
Carine Rey committed
145
        ]
Philippe Veber's avatar
Philippe Veber committed
146 147 148 149
      )
    ]
  in
  Workflow.select inner ["results.svg"]