convergence_detection.ml 4.75 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 11
type result = [
  | `Pcoc of [`pcoc] directory workflow
  | `Pcoc_gamma of [`pcoc] directory workflow
  | `Diffsel of [`diffsel] directory workflow
Carine Rey's avatar
Carine Rey committed
12
  | `Diffsel_bis 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
Philippe Veber's avatar
Philippe Veber committed
18
]
Carine Rey's avatar
Carine Rey committed
19

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

type dataset_res = {
  model_prefix : string ;
  tree_prefix : string ;
Philippe Veber's avatar
Philippe Veber committed
34
  res_by_tools: result list ;
Carine Rey's avatar
Carine Rey committed
35 36
  merged_results : text_file workflow ;
  plot_merged_results : svg workflow ;
Philippe Veber's avatar
Philippe Veber committed
37
}
Carine Rey's avatar
Carine Rey committed
38

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


Carine Rey's avatar
Carine Rey committed
76
let plot_merge_results ~(res_by_tools:result list) ~tree ~faa ~tsv : svg workflow =
Carine Rey's avatar
Carine Rey committed
77 78 79 80 81
  let plot_all_sites = true in
  (*let env = docker_image ~account:"carinerey" ~name:"ete3" ~tag:"3.0.0b35" () in*)
  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
82 83 84 85
    let opt = match res with
      | `Pcoc _ -> "PCOC"
      | `Pcoc_gamma _ -> "PCOC_gamma"
      | `Diffsel _ -> "Diffsel"
Carine Rey's avatar
Carine Rey committed
86
      | `Diffsel_bis _ -> "Diffsel_bis"
Carine Rey's avatar
Carine Rey committed
87 88
      | `Identical_LG _ -> "Identical_LG08"
      | `Identical_WAG _ -> "Identical_WAG01"
89 90 91
      | `Topological_LG _ -> "Topological_LG08"
      | `Topological_WAG _ -> "Topological_WAG01"
      | `Tdg09 _ -> "Tdg09"
Carine Rey's avatar
Carine Rey committed
92
    in
Philippe Veber's avatar
Philippe Veber committed
93
    string opt
Carine Rey's avatar
Carine Rey committed
94 95
  ) |> seq ~sep:","
  in
96 97 98 99 100
  let meths_t = List.map res_by_tools ~f:(fun res ->
    let opt = match res with
      | `Pcoc _ -> "PCOC:0.99"
      | `Pcoc_gamma _ -> "PCOC_gamma:0.99"
      | `Diffsel _ -> "Diffsel:0.9"
Carine Rey's avatar
Carine Rey committed
101
      | `Diffsel_bis _ -> "Diffsel_bis:0.9"
Carine Rey's avatar
Carine Rey committed
102 103
      | `Identical_LG _ -> "Identical_LG08:0.9"
      | `Identical_WAG _ -> "Identical_WAG01:0.9"
104 105 106
      | `Topological_LG _ -> "Topological_LG08:0.9"
      | `Topological_WAG _ -> "Topological_WAG01:0.9"
      | `Tdg09 _ -> "Tdg09:0.9"
107 108 109 110
    in
    string opt
  ) |> seq ~sep:","
  in
Carine Rey's avatar
Carine Rey committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
  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 ;
133
          opt "-t" ident meths_t ;
Carine Rey's avatar
Carine Rey committed
134 135 136 137 138
          flag string "--all_sites" plot_all_sites ;
        ]
      ]
    )
  ]