convergence_detection.ml 5.17 KB
Newer Older
Carine Rey's avatar
Carine Rey committed
1
open Core
Carine Rey's avatar
Carine Rey committed
2 3 4 5
open Bistro.EDSL
open Bistro.Std
open File_formats
open Bistro_bioinfo.Std
Carine Rey's avatar
Carine Rey committed
6
open Defs
Carine Rey's avatar
Carine Rey committed
7

Philippe Veber's avatar
Philippe Veber committed
8 9 10
type result = [
  | `Pcoc of [`pcoc] directory workflow
  | `Pcoc_gamma of [`pcoc] directory workflow
Carine Rey's avatar
Carine Rey committed
11
  | `Pcoc_C60 of [`pcoc] directory workflow
Philippe Veber's avatar
Philippe Veber committed
12
  | `Diffsel of [`diffsel] directory workflow
Carine Rey's avatar
Carine Rey committed
13 14
  | `Identical_LG of [`identical] directory workflow
  | `Identical_WAG of [`identical] directory workflow
15 16 17
  | `Topological_LG of [`topological] directory workflow
  | `Topological_WAG of [`topological] directory workflow
  | `Tdg09 of [`tdg09] directory workflow
18
  | `Multinomial of [`multinomial] directory workflow
Philippe Veber's avatar
Philippe Veber committed
19
]
Carine Rey's avatar
Carine Rey committed
20

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

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

Carine Rey's avatar
Carine Rey committed
42
let merge_results ~res_by_tools : text_file workflow =
43
  let env = docker_image ~account:"carinerey" ~name:"python_basics" ~tag:"07182018" () in
Carine Rey's avatar
Carine Rey committed
44
  let command = List.map res_by_tools ~f:(fun res ->
Philippe Veber's avatar
Philippe Veber committed
45
      let w = match res with
Carine Rey's avatar
Carine Rey committed
46
        | `Pcoc d -> Pcoc.results d
Philippe Veber's avatar
Philippe Veber committed
47
        | `Pcoc_gamma d -> Pcoc.results d
Carine Rey's avatar
Carine Rey committed
48
        | `Pcoc_C60 d -> Pcoc.results d
Philippe Veber's avatar
Philippe Veber committed
49
        | `Diffsel d -> Diffsel.selector d
Carine Rey's avatar
Carine Rey committed
50 51
        | `Identical_LG d -> Identical.results d
        | `Identical_WAG d -> Identical.results d
52 53 54
        | `Topological_LG d -> Topological.results d
        | `Topological_WAG d -> Topological.results d
        | `Tdg09 d -> Tamuri.results d
55
        | `Multinomial d -> Multinomial.results d
Philippe Veber's avatar
Philippe Veber committed
56 57 58 59
      in
      let opt = match res with
        | `Pcoc _ -> string "--pcoc"
        | `Pcoc_gamma _ -> string "--pcoc_gamma"
Carine Rey's avatar
Carine Rey committed
60
        | `Pcoc_C60 _ -> string "--pcoc_C60"
Philippe Veber's avatar
Philippe Veber committed
61
        | `Diffsel _ -> string "--diffsel"
Carine Rey's avatar
Carine Rey committed
62 63
        | `Identical_LG _ -> string "--identical_LG"
        | `Identical_WAG _ -> string "--identical_WAG"
64 65 66
        | `Topological_LG _ -> string "--topological_LG"
        | `Topological_WAG _ -> string "--topological_WAG"
        | `Tdg09 _ -> string "--tdg09"
67
        | `Multinomial _ -> string "--multinomial"
Philippe Veber's avatar
Philippe Veber committed
68 69 70
      in
      seq ~sep:" " [opt; dep w]
    )
Carine Rey's avatar
Carine Rey committed
71 72
  in
  workflow ~descr:"convergence_detection.merge_results" [
Carine Rey's avatar
Carine Rey committed
73
    cmd "python" ~env [
74 75 76 77
      file_dump (string Scripts.merge_det_results) ;
      opt "-o" ident dest ;
      seq ~sep:" " command ;
    ] ;
Carine Rey's avatar
Carine Rey committed
78 79
  ]

80
let plot_merge_results ~plot_all_sites ~(res_by_tools:result list) ~tree ~faa ~tsv : svg workflow =
Carine Rey's avatar
Carine Rey committed
81 82 83
  let env = docker_image ~account:"carinerey" ~name:"pcoc" ~tag:"06212018" () in
  (* 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 ->
84 85 86 87 88 89 90 91 92
      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
93 94
        | `Tdg09 _ -> "Tdg09_1MinusFDR,Tdg09_prob_post"
        | `Multinomial _ -> "Mutinomial_1MinusLRT"
95 96 97
      in
      string opt
    ) |> seq ~sep:","
Carine Rey's avatar
Carine Rey committed
98
  in
99
  let meths_t = List.map res_by_tools ~f:(fun res ->
100 101 102 103 104 105 106 107 108
      let opt = match res with
        | `Pcoc _ -> "PCOC:0.99,PC:0.99,OC:0.99"
        | `Pcoc_gamma _ -> "PCOC_gamma:0.99,PC_gamma:0.99,OC_gamma:0.99"
        | `Pcoc_C60 _ -> "PCOC_C60:0.99,PC_C60:0.99,OC_C60:0.99"
        | `Diffsel _ -> "Diffsel_mean:0.11,Diffsel_max:0.9"
        | `Identical_LG _ -> "Identical_LG08:0.9"
        | `Identical_WAG _ -> "Identical_WAG01:0.9"
        | `Topological_LG _ -> "Topological_LG08:0.9"
        | `Topological_WAG _ -> "Topological_WAG01:0.9"
Carine Rey's avatar
Carine Rey committed
109 110
        | `Tdg09 _ -> "Tdg09_1MinusFDR:0.99,Tdg09_prob_post:0.99"
        | `Multinomial _ -> "Mutinomial_1MinusLRT:0.95"
111 112 113
      in
      string opt
    ) |> seq ~sep:","
114
  in
Carine Rey's avatar
Carine Rey committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
  let package_diffsel_script_utils = tmp // "diffsel_script_utils.py" in
  let package_plot_data = tmp // "plot_data.py" in
  let script_plot_convergent_sites = tmp // "plot_convergent_sites.py" in
  let out = dest // "results.svg" in
  workflow ~descr:"convergence_detection.plot_results" [
    docker env (
      and_list [
        mkdir_p tmp ;
        mkdir_p dest ;
        cd tmp ;

        cmd "cp" [ file_dump (string Scripts.diffsel_script_utils) ; package_diffsel_script_utils ] ;
        cmd "cp" [ file_dump (string Scripts.plot_data) ; package_plot_data] ;
        cmd "cp" [ file_dump (string Scripts.plot_convergent_sites); script_plot_convergent_sites ] ;

        cmd "python" [
          string "plot_convergent_sites.py" ;
          opt "-msa" dep faa ;
          opt "-tsv" dep tsv ;
          opt "-tree" dep tree ;
          opt "-out" ident out ;
          opt "-meth" ident meths ;
137
          opt "-t" ident meths_t ;
Carine Rey's avatar
Carine Rey committed
138 139 140 141 142
          flag string "--all_sites" plot_all_sites ;
        ]
      ]
    )
  ]