pipeline.ml 2.14 KB
Newer Older
Philippe Veber's avatar
Philippe Veber committed
1
open Core
Philippe Veber's avatar
Philippe Veber committed
2
open Bistro_utils
LANORE Vincent's avatar
LANORE Vincent committed
3
open Bistro.EDSL
Carine Rey's avatar
typing  
Carine Rey committed
4
open Bistro.Std
5 6 7
open File_formats


Carine Rey's avatar
typing  
Carine Rey committed
8 9
let parse_input_tree ~tree : parsed_input_tree directory workflow =
    workflow ~descr:"utils.parse_input_tree" [
10 11 12 13 14 15 16 17 18 19 20 21 22 23
    (*let env = docker_image ~account:"carinerey" ~name:"ete3:3.0.0b35" () in*)
    cmd "python" (*~env*) [
      string "etc/utils/bin/parse_input_tree.py";
      opt "-t" dep tree;
      opt "-o" ident dest;
    ]
  ]

let select_out parsed_tree t = match t with
    | Nodes_H0     -> parsed_tree / selector [ "tree.H0.node_ids" ]
    | Nodes_Ha     -> parsed_tree / selector [ "tree.Ha.node_ids" ]
    | Tree4detect  -> parsed_tree / selector [ "tree.only_convergent_tags.nhx" ]
    | Tree4simu    -> parsed_tree / selector [ "tree.only_node_ids.nhx" ]
    | Tree_diffsel -> parsed_tree / selector [ "tree.diffsel" ]
Philippe Veber's avatar
Philippe Veber committed
24

LANORE Vincent's avatar
LANORE Vincent committed
25 26 27
let derive_from_tree ~tree_dir ~tree ~preview =
  let tree = input (Filename.concat tree_dir tree) in
  let nb_sites = if preview then 10 else 100 in
28 29
  let parsed_tree = parse_input_tree ~tree in
  let fna = Bppsuite.bppseqgen ~nb_sites ~tree:(select_out parsed_tree Tree4simu) in
LANORE Vincent's avatar
LANORE Vincent committed
30 31
  Repo.[
    item ["simulated_sequences.fna"] fna ;
Philippe Veber's avatar
Philippe Veber committed
32
  ]
Philippe Veber's avatar
Philippe Veber committed
33

LANORE Vincent's avatar
LANORE Vincent committed
34 35 36 37 38 39 40 41 42 43
let derive ~tree_dir ~trees ~preview =
  List.map trees ~f:(fun tree ->
      let id = Filename.chop_extension tree in
      Repo.shift id (derive_from_tree ~tree_dir ~tree ~preview))
  |> List.concat

let main ~outdir ?(np = 2) ?(mem = 2) ~tree_dir ~preview () =
  let trees = Array.to_list @@ Sys.readdir tree_dir in
  let repo = derive ~tree_dir ~trees ~preview in
  Repo.build ~outdir ~np ~mem:(`GB mem) repo
Philippe Veber's avatar
Philippe Veber committed
44 45 46 47 48 49 50

let command =
  let open Command.Let_syntax in
  Command.basic
    ~summary:"Run simulation pipeline"
    [%map_open
      let outdir =
LANORE Vincent's avatar
LANORE Vincent committed
51 52 53
        flag "--outdir" (required string) ~doc:"PATH Output directory"
      and preview =
        flag "--preview-mode" no_arg ~doc:" Preview mode"
Philippe Veber's avatar
Philippe Veber committed
54 55 56 57
      and np =
        flag "--np" (optional int) ~doc:"INT Number of available processors"
      and mem =
        flag "--mem" (optional int) ~doc:"INT Available memory (in GB)"
LANORE Vincent's avatar
LANORE Vincent committed
58 59
      and tree_dir =
        flag "--tree-dir" (required string) ~doc:"PATH Path to tree directory"
Philippe Veber's avatar
Philippe Veber committed
60
      in
LANORE Vincent's avatar
LANORE Vincent committed
61
      main ~outdir ?np ?mem ~tree_dir ~preview
Philippe Veber's avatar
Philippe Veber committed
62
    ]