convergence_detection.ml 3.34 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
Philippe Veber's avatar
Philippe Veber committed
13
]
Carine Rey's avatar
Carine Rey committed
14

Philippe Veber's avatar
Philippe Veber committed
15 16 17 18
let meth_string_of_result = function
  | `Pcoc _ -> "pcoc"
  | `Pcoc_gamma _ -> "pcoc_gamma"
  | `Diffsel _ -> "diffsel"
Carine Rey's avatar
Carine Rey committed
19
  | `Diffsel_bis _ -> "diffsel_bis"
Carine Rey's avatar
Carine Rey committed
20 21 22 23

type dataset_res = {
  model_prefix : string ;
  tree_prefix : string ;
Philippe Veber's avatar
Philippe Veber committed
24
  res_by_tools: result list ;
Carine Rey's avatar
Carine Rey committed
25 26
  merged_results : text_file workflow ;
  plot_merged_results : svg workflow ;
Philippe Veber's avatar
Philippe Veber committed
27
}
Carine Rey's avatar
Carine Rey committed
28

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


Carine Rey's avatar
Carine Rey committed
56 57 58 59 60 61
let plot_merge_results ~res_by_tools ~tree ~faa ~tsv : svg workflow =
  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
62 63 64 65
    let opt = match res with
      | `Pcoc _ -> "PCOC"
      | `Pcoc_gamma _ -> "PCOC_gamma"
      | `Diffsel _ -> "Diffsel"
Carine Rey's avatar
Carine Rey committed
66
      | `Diffsel_bis _ -> "Diffsel_bis"
Carine Rey's avatar
Carine Rey committed
67
    in
Philippe Veber's avatar
Philippe Veber committed
68
    string opt
Carine Rey's avatar
Carine Rey committed
69 70
  ) |> seq ~sep:","
  in
71 72 73 74 75
  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
76
      | `Diffsel_bis _ -> "Diffsel_bis:0.9"
77 78 79 80
    in
    string opt
  ) |> seq ~sep:","
  in
Carine Rey's avatar
Carine Rey committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
  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 ;
103
          opt "-t" ident meths_t ;
Carine Rey's avatar
Carine Rey committed
104 105 106 107 108
          flag string "--all_sites" plot_all_sites ;
        ]
      ]
    )
  ]