package phylogenetics

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file dna.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
open Core

type t = string

let of_string_unsafe x = x

let of_string_exn s =
  match String.find s ~f:(function
      | 'a' | 'A' | 'c' | 'C'
      | 'g' | 'G' | 't' | 'T' -> false
      | _ -> true
    )
  with
  | None -> s
  | Some c -> invalid_argf "of_string_exn: unexpected character '%c'" c ()


let of_codons codons = 
  Array.map codons ~f:Codon.Universal_genetic_code.NS.to_string
  |> String.concat_array
  |> of_string_exn

let gc_contents s =
  let n = String.count s ~f:(function
      | 'C' | 'G' -> true
      | 'A' | 'T' -> false
      | _ -> assert false
    )
  in
  float n /. float (String.length s)