convergence_detection.ml 5.15 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
  | `Diffsel_bis of [`diffsel] directory workflow
Carine Rey's avatar
Carine Rey committed
14 15
  | `Identical_LG of [`identical] directory workflow
  | `Identical_WAG of [`identical] directory workflow
16 17 18
  | `Topological_LG of [`topological] directory workflow
  | `Topological_WAG of [`topological] directory workflow
  | `Tdg09 of [`tdg09] 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
  | `Diffsel_bis _ -> "diffsel_bis"
Carine Rey's avatar
Carine Rey committed
27 28
  | `Identical_LG _ -> "identical_LG"
  | `Identical_WAG _ -> "identical_WAG"
29 30
  | `Topological_LG _ -> "topological_LG"
  | `Topological_WAG _ -> "topological_WAG"
Carine Rey's avatar
typo  
Carine Rey committed
31
  | `Tdg09 _ -> "tdg09"
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 =
Carine Rey's avatar
Carine Rey committed
43
  let env = docker_image ~account:"carinerey" ~name:"python_basics" ~tag:"07172018" () 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
        | `Diffsel_bis d -> Diffsel.selector d
Carine Rey's avatar
Carine Rey committed
51 52
        | `Identical_LG d -> Identical.results d
        | `Identical_WAG d -> Identical.results d
53 54 55
        | `Topological_LG d -> Topological.results d
        | `Topological_WAG d -> Topological.results d
        | `Tdg09 d -> Tamuri.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
        | `Diffsel_bis _ -> string "--diffsel_bis"
Carine Rey's avatar
Carine Rey committed
63 64
        | `Identical_LG _ -> string "--identical_LG"
        | `Identical_WAG _ -> string "--identical_WAG"
65 66 67
        | `Topological_LG _ -> string "--topological_LG"
        | `Topological_WAG _ -> string "--topological_WAG"
        | `Tdg09 _ -> string "--tdg09"
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 [
Carine Rey's avatar
Carine Rey committed
74 75 76 77 78 79 80
            file_dump (string Scripts.merge_det_results) ;
            opt "-o" ident dest ;
            seq ~sep:" " command ;
          ] ;
  ]


81
let plot_merge_results ~plot_all_sites ~(res_by_tools:result list) ~tree ~faa ~tsv : svg workflow =
Carine Rey's avatar
Carine Rey committed
82 83 84
  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 ->
Philippe Veber's avatar
Philippe Veber committed
85
    let opt = match res with
Carine Rey's avatar
Carine Rey committed
86 87
      | `Pcoc _ -> "PCOC,PC,OC"
      | `Pcoc_gamma _ -> "PCOC_gamma,PC_gamma,OC_gamma,"
Carine Rey's avatar
Carine Rey committed
88
      | `Pcoc_C60 _ -> "PCOC_C60,PC_C60,OC_C60,"
Carine Rey's avatar
Carine Rey committed
89 90
      | `Diffsel _ -> "Diffsel_mean,Diffsel_max"
      | `Diffsel_bis _ -> "Diffsel_bis_mean,Diffsel_bis_max"
Carine Rey's avatar
Carine Rey committed
91 92
      | `Identical_LG _ -> "Identical_LG08"
      | `Identical_WAG _ -> "Identical_WAG01"
93 94
      | `Topological_LG _ -> "Topological_LG08"
      | `Topological_WAG _ -> "Topological_WAG01"
Carine Rey's avatar
Carine Rey committed
95
      | `Tdg09 _ -> "Tdg09_1-FDR,Tdg09_prob_post"
Carine Rey's avatar
Carine Rey committed
96
    in
Philippe Veber's avatar
Philippe Veber committed
97
    string opt
Carine Rey's avatar
Carine Rey committed
98 99
  ) |> seq ~sep:","
  in
100 101
  let meths_t = List.map res_by_tools ~f:(fun res ->
    let opt = match res with
Carine Rey's avatar
Carine Rey committed
102 103 104
      | `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"
105 106
      | `Diffsel _ -> "Diffsel_mean:0.11,Diffsel_max:0.9"
      | `Diffsel_bis _ -> "Diffsel_bis_mean:0.11,Diffsel_bis_max:0.9"
Carine Rey's avatar
Carine Rey committed
107 108
      | `Identical_LG _ -> "Identical_LG08:0.9"
      | `Identical_WAG _ -> "Identical_WAG01:0.9"
109 110
      | `Topological_LG _ -> "Topological_LG08:0.9"
      | `Topological_WAG _ -> "Topological_WAG01:0.9"
Carine Rey's avatar
Carine Rey committed
111
      | `Tdg09 _ -> "Tdg09_1-FDR:0.9,Tdg09_prob_post:0.9"
112 113 114 115
    in
    string opt
  ) |> seq ~sep:","
  in
Carine Rey's avatar
Carine Rey committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
  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 ;
138
          opt "-t" ident meths_t ;
Carine Rey's avatar
Carine Rey committed
139 140 141 142 143
          flag string "--all_sites" plot_all_sites ;
        ]
      ]
    )
  ]