ready_dataset.ml 2.28 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
open File_formats
7
open Bppsuite
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
  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
20
  let fna_infos = raw_dataset.fna_infos in
21 22
  let tree_dataset = Tree_dataset.prepare input_tree in
  let faa = Bppsuite.fna2faa ~fna in
Carine Rey's avatar
Carine Rey committed
23
  { input_tree; tree_dataset ; fna; faa; fna_infos}
24 25 26

let repo rd =
  Repo.[
Carine Rey's avatar
Carine Rey committed
27
    [
28 29 30 31 32 33 34 35 36
      item ["input_tree.nhx"] rd.input_tree ;
      item ["tree.H0.node_ids" ] (Tree_dataset.nodes rd.tree_dataset H0) ;
      item ["tree.Ha.node_ids" ] (Tree_dataset.nodes rd.tree_dataset HaPCOC) ;
      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) ;
      item ["tree.convergent_topology" ] (Tree_dataset.topological_tree rd.tree_dataset) ;
      item ["simulated_sequences.fna"] rd.fna ;
      item ["simulated_sequences.phy"] (Bppsuite.fa2phy rd.fna) ;
37
      item ["simulated_sequences.faa"] rd.faa ;
Carine Rey's avatar
Carine Rey committed
38 39
    ] ;
    match rd.fna_infos with
40 41 42
    | 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
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 [
53 54
        List.map fna_infos_l ~f:(fun fna_infos -> dep fna_infos) ;
      ])
Carine Rey's avatar
Carine Rey committed
55
  ]
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
  let fna_infos_l = List.map [r_d1.fna_infos ; r_d2.fna_infos] ~f:(fun fna_infos ->
62
      match fna_infos with
Carine Rey's avatar
Carine Rey committed
63 64
      | Some i -> [i]
      | None -> []
65
    ) |> List.concat in
Carine Rey's avatar
Carine Rey committed
66 67
  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