Commit df7bfedf authored by Philippe Veber's avatar Philippe Veber
Browse files

Utils: fixed recall_precision_curve

parent 0f482db8
......@@ -34,23 +34,35 @@ let%pworkflow fasta_cappend fa1 fa2 =
|> Out_channel.write_lines [%dest]
let%pworkflow recall_precision_curve ~labels ~oracle ~results : pdf file =
let open Codepitk in
let n = Array.length labels in
let colors = Array.sub [|"blue";"green";"red";"tan1";"royalblue4";"darkorchid"|] ~pos:0 ~len:n in
let labels = [%param labels] in
let load_results fn =
let open Owl.Dataframe in
match get_col (of_csv ~sep:'\t' fn) 1 with
| Float_Series xs -> xs
| Int_Series xs -> Array.map xs ~f:Float.of_int
| _ -> assert false
let df = Dataframe.from_file fn |> Rresult.R.failwith_error_msg in
match Dataframe.get_col df 1 with
| Some (Floats xs) -> Array.map xs ~f:Option.some
| Some (Float_opts xs) -> xs
| Some (Ints xs) -> Array.map xs ~f:(fun i -> Some (Float.of_int i))
| Some (Int_opts xs) -> Array.map xs ~f:(Option.map ~f:Float.of_int)
| _ -> failwith "expected a numeric column at pos 1"
in
let oracle =
load_results [%path oracle]
|> Array.map ~f:Float.(( <> ) 0.)
|> Array.map ~f:(Option.map ~f:Float.(( <> ) 0.))
in
let results = List.map ~f:load_results [%eval Bistro.Workflow.path_list results] in
let filter_table x y =
Array.filter_mapi x ~f:(fun i x_i ->
match x_i, y.(i) with
| Some _, Some _ -> x_i
| None, _ | _, None -> None
)
in
let result_curves =
List.map results ~f:(fun scores ->
let scores = filter_table scores oracle
and oracle = filter_table oracle scores in
Biocaml_unix.Bin_pred.recall_precision_curve ~scores ~labels:oracle
|> fst
|> Array.unzip
......@@ -59,7 +71,7 @@ let%pworkflow recall_precision_curve ~labels ~oracle ~results : pdf file =
OCamlR_grDevices.pdf [%dest] ;
OCamlR_graphics.plot ~xlab:"Recall" ~ylab:"Precision" ~xlim:(0., 1.) ~ylim:(0., 1.) ~x:[||] ~y:[||] () ;
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_graphics.legend ~pch:[|19|] ~col:colors `topright labels ;
OCamlR_grDevices.dev_off ()
let%pworkflow [@version 2] newick_of_nhx (t : nhx file) : newick file =
......
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