ready_dataset.ml 2.35 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 =
27
  let phy = (Bppsuite.fa2phy rd.fna) in
28
  Repo.[
Carine Rey's avatar
Carine Rey committed
29
    [
30
      item ["input_tree.nhx"] rd.input_tree ;
31
      item ["recalculated_tree.nw"] (Phyml.phyml_tree ~tree:rd.input_tree phy );
32 33 34 35 36 37 38
      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 ;
39
      item ["simulated_sequences.phy"] phy ;
40
      item ["simulated_sequences.faa"] rd.faa ;
Carine Rey's avatar
Carine Rey committed
41 42
    ] ;
    match rd.fna_infos with
43 44 45
    | Some w -> [item ["simulated_sequences.fna_infos"] w]
    | None -> []
      ;
46
  ]
Carine Rey's avatar
Carine Rey committed
47
  |> List.concat
48

Carine Rey's avatar
Carine Rey committed
49 50 51 52 53 54
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 [
55 56
        List.map fna_infos_l ~f:(fun fna_infos -> dep fna_infos) ;
      ])
Carine Rey's avatar
Carine Rey committed
57
  ]
Carine Rey's avatar
Carine Rey committed
58 59 60 61 62

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
63
  let fna_infos_l = List.map [r_d1.fna_infos ; r_d2.fna_infos] ~f:(fun fna_infos ->
64
      match fna_infos with
Carine Rey's avatar
Carine Rey committed
65 66
      | Some i -> [i]
      | None -> []
67
    ) |> List.concat in
Carine Rey's avatar
Carine Rey committed
68 69
  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
70
  ready_dataset