Commit 138f2ee4 authored by Philippe Veber's avatar Philippe Veber
Browse files

refactoring: started toolbox library

toolbox will be used to separate simple ocaml functions from bistro
workflows.
parent 5d16d54d
......@@ -190,7 +190,8 @@ let recall_precision_curve table =
]
let%workflow recall_precision_auc_table table =
let labels, scores_per_meth = Utils.result_table_parser [%path table] in
let module RT = Reviewphiltrans_toolbox.Result_table in
let { RT.labels ; scores_per_meth } = RT.of_file [%path table] in
Array.map scores_per_meth ~f:(fun (meth, scores) ->
let _, auc = Biocaml_unix.Bin_pred.recall_precision_curve ~labels ~scores in
meth, auc
......
(library
(name reviewphiltrans)
(libraries biocaml.ez bistro.bioinfo bistro.utils convdet gzt ocaml-r.graphics ocaml-r.grDevices)
(libraries bistro.bioinfo bistro.utils convdet gzt ocaml-r.graphics ocaml-r.grDevices reviewphiltrans_toolbox )
(preprocess
(pps ppx_jane ppx_csv_conv bistro.ppx ppx_here)))
......
(library
(name reviewphiltrans_toolbox)
(libraries biocaml.ez convdet gzt ocaml-r.graphics ocaml-r.grDevices)
(preprocess (pps ppx_jane)))
open Core_kernel
type t = {
labels : bool array ;
scores_per_meth : (string * float array) array ;
}
let of_file fn =
let module D = Owl.Dataframe in
let df = D.of_csv fn in
let labels =
D.get_col_by_name df "Oracle"
|> D.unpack_int_series
|> Array.map ~f:(function
| 0 -> false
| 1 -> true
| _ -> assert false
)
in
let scores meth =
match D.get_col_by_name df meth with
| Float_Series xs -> Some xs
| Int_Series xs -> Some (Array.map xs ~f:Float.of_int)
| String_Series _ -> None (* has NA *)
| _ -> assert false
in
let methods =
D.get_heads df
|> Array.filter ~f:(fun m -> m <> "Oracle" && m <> "Sites")
in
let scores_per_meth =
Array.filter_map methods ~f:(fun m ->
Option.map (scores m) ~f:(fun c -> m, c)
)
in
{ labels ; scores_per_meth }
......@@ -59,31 +59,3 @@ let%pworkflow recall_precision_curve ~labels ~oracle ~results : Bistro.pdf Bistr
List.iteri result_curves ~f:(fun i (x, y) -> OCamlR_graphics.lines ~col:colors.(i) ~x ~y ()) ;
OCamlR_graphics.legend ~pch:[|19|] ~col:colors `bottomleft labels ;
OCamlR_grDevices.dev_off ()
let result_table_parser fn =
let module D = Owl.Dataframe in
let df = D.of_csv fn in
let labels =
D.get_col_by_name df "Oracle"
|> D.unpack_int_series
|> Array.map ~f:(function
| 0 -> false
| 1 -> true
| _ -> assert false
)
in
let scores meth =
match D.get_col_by_name df meth with
| Float_Series xs -> Some xs
| Int_Series xs -> Some (Array.map xs ~f:Float.of_int)
| String_Series _ -> None (* has NA *)
| _ -> assert false
in
let methods =
D.get_heads df
|> Array.filter ~f:(fun m -> m <> "Oracle" && m <> "Sites")
in
labels,
Array.filter_map methods ~f:(fun m ->
Option.map (scores m) ~f:(fun c -> m, c)
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment