package biotk
Source file idr.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105open Core type fields = string list [@@deriving show] let from_file from_fields fn = try Ok ( In_channel.read_lines fn |> List.map ~f:(fun l -> String.split l ~on:'\t' |> from_fields ) ) with exn -> Error (`Msg (Exn.to_string exn)) module Maybe_strand = struct type t = [`Plus | `Minus] option let of_string = function | "+" -> Some `Plus | "-" -> Some `Minus | "." -> None | _ -> failwith "Incorrect syntax for strand field" end module Narrow_output = struct module Row = struct type t = { chrom : string ; chromStart : int ; chromEnd : int ; name : string ; score : int ; strand : Maybe_strand.t ; signalValue : float ; pvalue : float ; qvalue : float ; summit : int ; localIDR : float ; globalIDR : float ; } let from_fields = function | chrom :: chromStart :: chromEnd :: name :: score :: strand :: signalValue :: pvalue :: qvalue :: summit :: localIDR :: globalIDR :: _ -> { chrom ; chromStart = Int.of_string chromStart ; chromEnd = Int.of_string chromEnd ; name ; score = Int.of_string score ; strand = Maybe_strand.of_string strand ; signalValue = Float.of_string signalValue ; pvalue = Float.of_string pvalue ; qvalue = Float.of_string qvalue ; summit = Int.of_string summit ; localIDR = Float.of_string localIDR ; globalIDR = Float.of_string globalIDR ; } | l -> failwithf "Expected more fields, got %s" (show_fields l) () let loc r = GLoc.{ chr = r.chrom ; lo = r.chromStart ; hi = r.chromEnd } end let from_file = from_file Row.from_fields end module Broad_output = struct module Row = struct type t = { chrom : string ; chromStart : int ; chromEnd : int ; name : string ; score : int ; strand : Maybe_strand.t ; signalValue : float ; pvalue : float ; qvalue : float ; localIDR : float ; globalIDR : float ; } let from_fields = function | chrom :: chromStart :: chromEnd :: name :: score :: strand :: signalValue :: pvalue :: qvalue :: localIDR :: globalIDR :: _ -> { chrom ; chromStart = Int.of_string chromStart ; chromEnd = Int.of_string chromEnd ; name ; score = Int.of_string score ; strand = Maybe_strand.of_string strand ; signalValue = Float.of_string signalValue ; pvalue = Float.of_string pvalue ; qvalue = Float.of_string qvalue ; localIDR = Float.of_string localIDR ; globalIDR = Float.of_string globalIDR ; } | l -> failwithf "Expected more fields, got %s" (show_fields l) () let loc r = GLoc.{ chr = r.chrom ; lo = r.chromStart ; hi = r.chromEnd } end let from_file = from_file Row.from_fields end