Commit a17d17a6 authored by Philippe Veber's avatar Philippe Veber
Browse files

tk/Mutsel_simulator_cpg: cosmetic changes to dinucleotide_ratios

parent 10553ec5
......@@ -116,22 +116,26 @@ module Evolution_model = struct
let stationary_distribution p = NSCodon_rate_matrix.stationary_distribution (rate_matrix p)
let dinucleotide_ratios (sequence:NSCodon.t array) =
let seq = Array.concat_map ~f:(fun codon ->
let nucleotides_of_codons codons =
Array.concat_map codons ~f:(fun codon ->
let x, y, z = NSCodon.nucleotides codon in
[|x;y;z|]
) sequence
in
let single_counts = Nucleotide.Table.init (fun nuc ->
Array.count seq ~f:(fun seq_nuc -> Nucleotide.equal seq_nuc nuc))
in
)
let nucleotide_counts seq =
Nucleotide.Table.init (fun nuc ->
Array.count seq ~f:(Nucleotide.equal nuc)
)
let dinucleotide_ratios codon_sequence =
let nucleotide_sequence = nucleotides_of_codons codon_sequence in
let single_counts = nucleotide_counts nucleotide_sequence in
Nucleotide.Table.init (fun nuc1 ->
Nucleotide.Table.init (fun nuc2 ->
let expected = Nucleotide.Table.(get single_counts nuc1 * get single_counts nuc2)
in
let observed = Array.counti seq ~f:(fun pos nuc ->
if pos = Array.length seq then false
else Nucleotide.(equal nuc nuc1 && equal seq.(pos+1) nuc2)
let expected = Nucleotide.Table.(get single_counts nuc1 * get single_counts nuc2) in
let observed = Array.counti nucleotide_sequence ~f:(fun pos nuc ->
if pos = Array.length nucleotide_sequence then false
else Nucleotide.(equal nuc nuc1 && equal nucleotide_sequence.(pos+1) nuc2)
)
in
float_of_int observed /. float_of_int expected
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment