identical.ml 3.45 KB
Newer Older
Carine Rey's avatar
Carine Rey committed
1
open Core
Philippe Veber's avatar
Philippe Veber committed
2 3
open Bistro
open Bistro.Shell_dsl
Carine Rey's avatar
Carine Rey committed
4 5 6 7 8 9 10
open File_formats

let assign k v =
  seq ~sep:"=" [ string k ; v ]

let conf_file_bppml ~tree ~faa ~out ~config =
  seq ~sep:"\n" (
11
    [
Carine Rey's avatar
Carine Rey committed
12 13 14
      assign "OUT" (out) ;
      assign "input.sequence.file" (dep faa) ;
      assign "alphabet" (string "Protein") ;
15 16
      assign "input.sequence.remove_stop_codons" (string "no") ;
      assign "input.sequence.sites_to_use" (string "all") ;
Carine Rey's avatar
Carine Rey committed
17
      assign "input.sequence.remove_saturated_sites" (string "yes") ;
Carine Rey's avatar
Carine Rey committed
18 19 20 21

      assign "input.tree.file"  (dep tree) ;
      assign "init.tree" (string "user") ;
      assign "input.tree.format" (string "Nhx") ;
22

Carine Rey's avatar
Carine Rey committed
23 24 25 26 27 28 29 30 31 32 33 34 35
      assign "optimization.topology" (string "false") ;

      assign "output.tree.file" (string "$(OUT)/tree.nhx") ;
      assign "output.tree.format" (string "Nhx") ;


      assign "output.infos" (string "$(OUT)/infos.tsv") ;
      assign "output.estimates" (string "$(OUT)/estimates.tsv") ;
    ]
    @ config
  )

let bppml ?(descr="") ~faa ~tree ~config : _ workflow =
36
  let env = Env.env_bppsuite in
Carine Rey's avatar
Carine Rey committed
37 38
  let config_f = dest // "config_bppml.bpp" in
  let out = ident dest in
Philippe Veber's avatar
Philippe Veber committed
39 40 41 42 43 44
  Workflow.shell ~descr:("bppsuite.bppml" ^ descr) ~img:env [
    and_list [
      mkdir_p dest;
      cmd "cat" ~stdout:config_f [(file_dump (conf_file_bppml ~tree ~faa ~out ~config ))];
      cmd "bppml" [
        assign "param"  config_f;
Carine Rey's avatar
Carine Rey committed
45
      ]
Philippe Veber's avatar
Philippe Veber committed
46
    ]
Carine Rey's avatar
Carine Rey committed
47
  ]
48

Carine Rey's avatar
Carine Rey committed
49 50
let conf_file_bppancestor ~tree ~faa ~out ~config =
  seq ~sep:"\n" (
51
    [
Carine Rey's avatar
Carine Rey committed
52 53 54
      assign "OUT" (out) ;
      assign "input.sequence.file" (dep faa) ;
      assign "alphabet" (string "Protein") ;
Carine Rey's avatar
Carine Rey committed
55 56 57
      assign "input.sequence.remove_stop_codons" (string "no") ;
      assign "input.sequence.sites_to_use" (string "all") ;
      assign "input.sequence.remove_saturated_sites" (string "yes") ;
Carine Rey's avatar
Carine Rey committed
58 59 60 61

      assign "input.tree.file"  (dep tree) ;
      assign "init.tree" (string "user") ;
      assign "input.tree.format" (string "Nhx") ;
62

Carine Rey's avatar
Carine Rey committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76
      assign "optimization.topology" (string "false") ;

      assign "output.sequence.file" (string "$(OUT)/output_anc.fa") ;
      assign "asr.add_extant" (string "true") ;
      assign "asr.probabilities" (string "true") ;


      assign "output.sites.file" (string "$(OUT)/sites.tsv") ;
      assign "output.nodes.file" (string "$(OUT)/nodes.tsv") ;
    ]
    @ config
  )

let bppancestor ?(descr="") ~faa ~tree ~config : _ workflow =
77
  let env = Env.env_bppsuite in
Carine Rey's avatar
Carine Rey committed
78 79
  let config_f = dest // "config_bppancestor.bpp" in
  let out = ident dest in
Philippe Veber's avatar
Philippe Veber committed
80 81 82 83 84 85
  Workflow.shell ~descr:("bppsuite.bppancestor" ^ descr) ~img:env [
    and_list [
      mkdir_p dest;
      cmd "cat" ~stdout:config_f [(file_dump (conf_file_bppancestor ~tree ~faa ~out ~config))];
      cmd "bppancestor" [
        assign "param"  config_f;
Carine Rey's avatar
Carine Rey committed
86
      ]
Philippe Veber's avatar
Philippe Veber committed
87
    ]
Carine Rey's avatar
Carine Rey committed
88 89
  ]

Philippe Veber's avatar
Philippe Veber committed
90
let identical ?(descr="") ~(tree_id:_ file) ~(tree_sc:_ file) ~(faa:aminoacid_fasta file) ~prot_model () : [`identical] directory =
Carine Rey's avatar
Carine Rey committed
91 92 93 94
  let config = [assign "model" (string prot_model)] in
  let out1 = dest // "out1.tsv" in
  let out2 = dest // "out2.tsv" in
  let run_bppancestor = bppancestor ~descr:"" ~tree:tree_id ~faa ~config in
Philippe Veber's avatar
Philippe Veber committed
95
  let proba = Workflow.select run_bppancestor ["sites.tsv"] in
Philippe Veber's avatar
Philippe Veber committed
96
  Workflow.shell ~descr:("identical."^prot_model^"."^descr) ~img:Env.env_pcoc [
Carine Rey's avatar
Carine Rey committed
97
    mkdir dest ;
Philippe Veber's avatar
Philippe Veber committed
98
    cmd "python" [
99 100 101 102 103 104
      file_dump (string Scripts.calc_identical) ;
      opt "-t" dep tree_sc;
      opt "-a" dep faa;
      opt "-p" dep proba;
      opt "-o"  ident out1 ;
      opt "-o2"  ident out2 ;
Carine Rey's avatar
Carine Rey committed
105 106 107
    ]
  ]

Philippe Veber's avatar
Philippe Veber committed
108
let results run_identical : text file =
Philippe Veber's avatar
Philippe Veber committed
109
  Workflow.select run_identical ["out1.tsv"]