Skip to content

Commit

Permalink
utils: new R script module
Browse files Browse the repository at this point in the history
  • Loading branch information
pveber committed Jan 4, 2019
1 parent 8cd306a commit 51a05a6
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
60 changes: 60 additions & 0 deletions lib/utils/r_script.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
open Base
open Bistro
open Bistro.Template_dsl

type t = template

type expr = t

type arg = t

let make xs = Template_dsl.(seq ~sep:"\n" xs)

let source s = Template_dsl.string s

let dest = Template_dsl.(quote ~using:'"' dest)

let tmp = Template_dsl.(quote ~using:'"' tmp)

let string s =
Template_dsl.(quote ~using:'"' (string s))

let int i = Template_dsl.int i

let float f = Template_dsl.float f

let dep w = Template_dsl.(quote ~using:'"' (dep w))

let call_gen fn arg xs =
let open Template_dsl in
seq ~sep:"" [
string fn ;
string "(" ;
list ~sep:"," arg xs ;
string ")" ;
]

let call fn args = call_gen fn Fn.id args

let vector f xs = call_gen "c" f xs

let ints xs = vector Template_dsl.int xs
let floats xs = vector Template_dsl.float xs
let strings xs = vector string xs
let deps xs = vector dep xs

let arg ?l e =
let open Template_dsl in
match l with
| None -> e
| Some label ->
seq ~sep:"" [ string label ; string "=" ; e ]

let assign var e =
let open Template_dsl in
seq ~sep:" " [ string var ; string "<-" ; e ]

let workflow ?descr ?np ?mem ?img exprs =
Workflow.shell ?descr ?np ?mem Shell_dsl.[
cmd "Rscript" ?img [ file_dump (make exprs) ] ;
]
32 changes: 32 additions & 0 deletions lib/utils/r_script.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
open Bistro
open Bistro.Template_dsl

type t
type expr
type arg


val make : expr list -> template

val dest : expr
val tmp : expr
val source : string -> expr
val call : string -> arg list -> expr
val string : string -> expr
val int : int -> expr
val float : float -> expr
val dep : _ pworkflow -> expr
val ints : int list -> expr
val floats : float list -> expr
val strings : string list -> expr
val deps : _ pworkflow list -> expr
val arg : ?l:string -> expr -> arg
val assign : string -> expr -> expr

val workflow :
?descr:string ->
?np:int ->
?mem:int workflow ->
?img:Shell_dsl.container_image list ->
expr list ->
'a pworkflow

0 comments on commit 51a05a6

Please sign in to comment.