ready_dataset.ml 2.19 KB
Newer Older
Carine Rey's avatar
Carine Rey committed
1
open Core
2 3
open Bistro.Std
open Bistro_utils
Carine Rey's avatar
Carine Rey committed
4 5
open Bistro.EDSL
open Bistro_bioinfo.Std
6 7
open File_formats

Carine Rey's avatar
Carine Rey committed
8

9 10 11 12
type t = {
  input_tree: nhx workflow ;
  tree_dataset : [`tree_dataset] directory workflow ;
  fna: nucleotide_fasta workflow ;
Carine Rey's avatar
Carine Rey committed
13
  fna_infos: text_file workflow option ;
14 15 16 17 18 19 20
  faa: aminoacid_fasta workflow ;
}


let of_raw (raw_dataset : Raw_dataset.t) =
  let input_tree = raw_dataset.input_tree in
  let fna = raw_dataset.fna in
Carine Rey's avatar
Carine Rey committed
21
  let fna_infos = raw_dataset.fna_infos in
22 23
  let tree_dataset = Tree_dataset.prepare input_tree in
  let faa = Bppsuite.fna2faa ~fna in
Carine Rey's avatar
Carine Rey committed
24
  { input_tree; tree_dataset ; fna; faa; fna_infos}
25 26 27

let repo rd =
  Repo.[
Carine Rey's avatar
Carine Rey committed
28
    [
29 30
    item ["input_tree.nhx"] rd.input_tree ;
    item ["tree.H0.node_ids" ] (Tree_dataset.nodes rd.tree_dataset H0) ;
Carine Rey's avatar
Carine Rey committed
31
    item ["tree.Ha.node_ids" ] (Tree_dataset.nodes rd.tree_dataset HaPCOC) ;
32 33 34
    item ["tree.only_convergent_tags.nhx" ] (Tree_dataset.tree rd.tree_dataset `Detection) ;
    item ["tree.only_node_ids.nhx" ] (Tree_dataset.tree rd.tree_dataset `Simulation) ;
    item ["tree.diffsel" ] (Tree_dataset.diffsel_tree rd.tree_dataset) ;
35
    item ["tree.convergent_topology" ] (Tree_dataset.topological_tree rd.tree_dataset) ;
36 37
    item ["simulated_sequences.fna"] rd.fna ;
    item ["simulated_sequences.faa"] rd.faa ;
Carine Rey's avatar
Carine Rey committed
38 39 40 41 42
    ] ;
    match rd.fna_infos with
     | Some w -> [item ["simulated_sequences.fna_infos"] w]
     | None -> []
    ;
43
  ]
Carine Rey's avatar
Carine Rey committed
44
  |> List.concat
45 46
  |> Repo.shift "ready_dataset"

Carine Rey's avatar
Carine Rey committed
47 48 49 50 51 52 53 54 55
let to_raw { input_tree ; fna ; fna_infos} =
  { Raw_dataset.input_tree ; fna ; fna_infos}

let paste_fna_infos  ~(fna_infos_l: text_file workflow list) : text_file workflow =
  workflow ~descr:"cat" [
    cmd "cat" ~stdout:dest (List.concat [
      List.map fna_infos_l ~f:(fun fna_infos -> dep fna_infos) ;
    ])
  ]
Carine Rey's avatar
Carine Rey committed
56 57 58 59 60

let paste d1 d2 =
  let r_d1 = to_raw d1 in
  let r_d2 = to_raw d2 in
  let fna = Bppsuite.paste_fna [r_d1.fna ; r_d2.fna ] in
Carine Rey's avatar
Carine Rey committed
61 62 63 64 65 66 67
  let fna_infos_l = List.map [r_d1.fna_infos ; r_d2.fna_infos] ~f:(fun fna_infos ->
     match fna_infos with
      | Some i -> [i]
      | None -> []
     ) |> List.concat in
  let fna_infos = Some (paste_fna_infos ~fna_infos_l) in
  let ready_dataset = of_raw {Raw_dataset.input_tree=r_d1.input_tree ; fna; fna_infos} in
Carine Rey's avatar
Carine Rey committed
68
  ready_dataset