convergence_detection.ml 3.94 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
Philippe Veber's avatar
Philippe Veber committed
15
]
Carine Rey's avatar
Carine Rey committed
16

Philippe Veber's avatar
Philippe Veber committed
17 18 19 20
let meth_string_of_result = function
  | `Pcoc _ -> "pcoc"
  | `Pcoc_gamma _ -> "pcoc_gamma"
  | `Diffsel _ -> "diffsel"
Carine Rey's avatar
Carine Rey committed
21
  | `Diffsel_bis _ -> "diffsel_bis"
Carine Rey's avatar
Carine Rey committed
22 23
  | `Identical_LG _ -> "identical_LG"
  | `Identical_WAG _ -> "identical_WAG"
Carine Rey's avatar
Carine Rey committed
24 25 26 27

type dataset_res = {
  model_prefix : string ;
  tree_prefix : string ;
Philippe Veber's avatar
Philippe Veber committed
28
  res_by_tools: result list ;
Carine Rey's avatar
Carine Rey committed
29 30
  merged_results : text_file workflow ;
  plot_merged_results : svg workflow ;
Philippe Veber's avatar
Philippe Veber committed
31
}
Carine Rey's avatar
Carine Rey committed
32

Carine Rey's avatar
Carine Rey committed
33
let merge_results ~res_by_tools : text_file workflow =
Carine Rey's avatar
Carine Rey committed
34
  let env = docker_image ~account:"carinerey" ~name:"ete3" ~tag:"3.0.0b35" () in
Carine Rey's avatar
Carine Rey committed
35
  let command = List.map res_by_tools ~f:(fun res ->
Philippe Veber's avatar
Philippe Veber committed
36
      let w = match res with
Carine Rey's avatar
Carine Rey committed
37
        | `Pcoc d -> Pcoc.results d
Philippe Veber's avatar
Philippe Veber committed
38
        | `Pcoc_gamma d -> Pcoc.results d
Philippe Veber's avatar
Philippe Veber committed
39
        | `Diffsel d -> Diffsel.selector d
Carine Rey's avatar
Carine Rey committed
40
        | `Diffsel_bis d -> Diffsel.selector d
Carine Rey's avatar
Carine Rey committed
41 42
        | `Identical_LG d -> Identical.results d
        | `Identical_WAG d -> Identical.results d
Philippe Veber's avatar
Philippe Veber committed
43 44 45 46 47
      in
      let opt = match res with
        | `Pcoc _ -> string "--pcoc"
        | `Pcoc_gamma _ -> string "--pcoc_gamma"
        | `Diffsel _ -> string "--diffsel"
Carine Rey's avatar
Carine Rey committed
48
        | `Diffsel_bis _ -> string "--diffsel_bis"
Carine Rey's avatar
Carine Rey committed
49 50
        | `Identical_LG _ -> string "--identical_LG"
        | `Identical_WAG _ -> string "--identical_WAG"
Philippe Veber's avatar
Philippe Veber committed
51 52 53
      in
      seq ~sep:" " [opt; dep w]
    )
Carine Rey's avatar
Carine Rey committed
54 55
  in
  workflow ~descr:"convergence_detection.merge_results" [
Carine Rey's avatar
Carine Rey committed
56
    cmd "python" ~env [
Carine Rey's avatar
Carine Rey committed
57 58 59 60 61 62 63
            file_dump (string Scripts.merge_det_results) ;
            opt "-o" ident dest ;
            seq ~sep:" " command ;
          ] ;
  ]


Carine Rey's avatar
Carine Rey committed
64
let plot_merge_results ~(res_by_tools:result list) ~tree ~faa ~tsv : svg workflow =
Carine Rey's avatar
Carine Rey committed
65 66 67 68 69
  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
70 71 72 73
    let opt = match res with
      | `Pcoc _ -> "PCOC"
      | `Pcoc_gamma _ -> "PCOC_gamma"
      | `Diffsel _ -> "Diffsel"
Carine Rey's avatar
Carine Rey committed
74
      | `Diffsel_bis _ -> "Diffsel_bis"
Carine Rey's avatar
Carine Rey committed
75 76
      | `Identical_LG _ -> "Identical_LG08"
      | `Identical_WAG _ -> "Identical_WAG01"
Carine Rey's avatar
Carine Rey committed
77
    in
Philippe Veber's avatar
Philippe Veber committed
78
    string opt
Carine Rey's avatar
Carine Rey committed
79 80
  ) |> seq ~sep:","
  in
81 82 83 84 85
  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
86
      | `Diffsel_bis _ -> "Diffsel_bis:0.9"
Carine Rey's avatar
Carine Rey committed
87 88
      | `Identical_LG _ -> "Identical_LG08:0.9"
      | `Identical_WAG _ -> "Identical_WAG01:0.9"
89 90 91 92
    in
    string opt
  ) |> seq ~sep:","
  in
Carine Rey's avatar
Carine Rey committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
  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 ;
115
          opt "-t" ident meths_t ;
Carine Rey's avatar
Carine Rey committed
116 117 118 119 120
          flag string "--all_sites" plot_all_sites ;
        ]
      ]
    )
  ]