identical.ml 3.55 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
  Workflow.shell ~descr:("bppsuite.bppml" ^ descr) [
    within_container env (
Carine Rey's avatar
Carine Rey committed
41 42 43 44
      and_list [
        mkdir_p dest;
        cmd "cat" ~stdout:config_f [(file_dump (conf_file_bppml ~tree ~faa ~out ~config ))];
        cmd "bppml" [
45 46
          assign "param"  config_f;
        ]
Carine Rey's avatar
Carine Rey committed
47 48 49
      ]
    )
  ]
50

Carine Rey's avatar
Carine Rey committed
51 52
let conf_file_bppancestor ~tree ~faa ~out ~config =
  seq ~sep:"\n" (
53
    [
Carine Rey's avatar
Carine Rey committed
54 55 56
      assign "OUT" (out) ;
      assign "input.sequence.file" (dep faa) ;
      assign "alphabet" (string "Protein") ;
Carine Rey's avatar
Carine Rey committed
57 58 59
      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
60 61 62 63

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

Carine Rey's avatar
Carine Rey committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78
      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 =
79
  let env = Env.env_bppsuite in
Carine Rey's avatar
Carine Rey committed
80 81
  let config_f = dest // "config_bppancestor.bpp" in
  let out = ident dest in
Philippe Veber's avatar
Philippe Veber committed
82 83
  Workflow.shell ~descr:("bppsuite.bppancestor" ^ descr) [
    within_container env (
Carine Rey's avatar
Carine Rey committed
84 85 86 87
      and_list [
        mkdir_p dest;
        cmd "cat" ~stdout:config_f [(file_dump (conf_file_bppancestor ~tree ~faa ~out ~config))];
        cmd "bppancestor" [
88 89
          assign "param"  config_f;
        ]
Carine Rey's avatar
Carine Rey committed
90 91 92 93
      ]
    )
  ]

94
let identical ?(descr="") ~(tree_id:_ pworkflow) ~(tree_sc:_ pworkflow) ~(faa:aminoacid_fasta pworkflow) ~prot_model () : [`identical] dworkflow =
Carine Rey's avatar
Carine Rey committed
95 96 97 98
  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
99
  let proba = Workflow.select run_bppancestor ["sites.tsv"] in
Carine Rey's avatar
Carine Rey committed
100
  Workflow.shell ~descr:("identical."^prot_model^"."^descr) [
Carine Rey's avatar
Carine Rey committed
101
    mkdir dest ;
102
    cmd "python" ~img:Env.env_pcoc [
103 104 105 106 107 108
      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
109 110 111
    ]
  ]

Philippe Veber's avatar
Philippe Veber committed
112 113
let results run_identical : text_file pworkflow =
  Workflow.select run_identical ["out1.tsv"]