sig
(** Simplified creation of Run_environment.Machine.t values *)


open Biokepi_run_environment
open Common


(** Build a Run_environment.Machine.t with convenient default values.

The string argument is a URI like the one expected by Ketrew.EDSL.Host.parse except that the “path” is the meta-playground for Biokepi (the ketrew playground will be (meta_playground // "ketrew_playground").

The default run_program is daemonizing with `Python_daemon.

The default toolkit is default_toolkit from Tool_providers. This machine will get tools installations and data-fetching from Biokepi's defaults. The ?b37 argument allows to override the locations of the “B37” genome; to override other default please use Run_environment.Machine.create directly. *)


val create :
  ?max_processors : int ->
  ?gatk_jar_location:(unit -> Tool_providers.broad_jar_location) ->
  ?mutect_jar_location:(unit -> Tool_providers.broad_jar_location) ->
  ?run_program:Machine.Make_fun.t ->
  ?toolkit:Machine.Tool.Kit.t ->
  ?b37:Reference_genome.t ->
  string ->
  Machine.t
end 
struct
open Biokepi_run_environment
open Common


let default_run_program : host:KEDSL.Host.t -> Machine.Make_fun.t =
  fun ~host ?(name="biokepi-ssh-box") ?(requirements = []) program ->
    let open KEDSL in
    daemonize ~using:`Python_daemon ~host program

let create
    ?(max_processors = 1)
    ?gatk_jar_location
    ?mutect_jar_location
    ?run_program ?toolkit ?b37 uri =
  let open KEDSL in
  let host = Host.parse (uri // "ketrew_playground"in
  let meta_playground = Uri.of_string uri |> Uri.path in
  let run_program =
    match run_program with
    | None -> default_run_program ~host
    | Some r -> r
  in
  let toolkit =
    Option.value toolkit
      ~default:(Tool_providers.default_toolkit ()
                  ~run_program
                  ~host ~install_tools_path:(meta_playground // "install-tools")
                  ?gatk_jar_location ?mutect_jar_location)
  in
  Machine.create (sprintf "ssh-box-%s" uri)
    ~max_processors
    ~get_reference_genome:(fun name ->
        match name, b37 with
        | name, Some some37 when name = Reference_genome.name some37 -> some37
        | name, _ ->        
          Download_reference_genomes.get_reference_genome name
            ~toolkit ~host ~run_program
            ~destination_path:(meta_playground // "reference-genome"))
    ~host
    ~toolkit
    ~run_program
    ~work_dir:(meta_playground // "work")
end