Commit 75f7c5f3 authored by Philippe Veber's avatar Philippe Veber
Browse files

inhouse_tdg09: handle gaps

parent e202eeac
...@@ -63,9 +63,12 @@ module Inhouse_implementation = struct ...@@ -63,9 +63,12 @@ module Inhouse_implementation = struct
type t = Alignment.t * int type t = Alignment.t * int
type species = int type species = int
let get_aa (al, j) sp = let get_aa (al, j) sp =
match Amino_acid.of_char al.Alignment.sequences.(sp).[j] with match al.Alignment.sequences.(sp).[j] with
| Some aa -> aa | '-' -> None
| None -> failwith "Unexpected character in alignment" | c ->
match Amino_acid.of_char c with
| Some aa -> Some aa
| None -> failwithf "Unexpected character in alignment: %C" c ()
end end
let reindex_tree alignment (tree : Convergence_tree.t) = let reindex_tree alignment (tree : Convergence_tree.t) =
......
...@@ -177,7 +177,7 @@ end ...@@ -177,7 +177,7 @@ end
module type Site = sig module type Site = sig
type t type t
type species type species
val get_aa : t -> species -> Amino_acid.t val get_aa : t -> species -> Amino_acid.t option
end end
module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with type species = Leaf_info.species) = struct module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with type species = Leaf_info.species) = struct
...@@ -201,7 +201,7 @@ module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with t ...@@ -201,7 +201,7 @@ module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with t
fun b -> (f (Branch_info.length b) :> mat) fun b -> (f (Branch_info.length b) :> mat)
in in
let leaf_state = aa_of_leaf_info site in let leaf_state = aa_of_leaf_info site in
CTMC.pruning tree ~transition_matrix ~leaf_state ~root_frequencies:pi CTMC.pruning_with_missing_values tree ~transition_matrix ~leaf_state ~root_frequencies:pi
let clip f param = let clip f param =
if Float.(param.(0) > 3.) then Float.infinity if Float.(param.(0) > 3.) then Float.infinity
...@@ -246,7 +246,7 @@ module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with t ...@@ -246,7 +246,7 @@ module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with t
fun b -> (f (Branch_info.length b) :> mat) fun b -> (f (Branch_info.length b) :> mat)
in in
let leaf_state = aa_of_leaf_info site in let leaf_state = aa_of_leaf_info site in
CTMC.pruning tree ~transition_matrix ~leaf_state ~root_frequencies:(stationary_distribution :> Vector.t) CTMC.pruning_with_missing_values tree ~transition_matrix ~leaf_state ~root_frequencies:(stationary_distribution :> Vector.t)
let counts xs = let counts xs =
Amino_acid.Table.init (fun aa -> List.count xs ~f:(Amino_acid.equal aa)) Amino_acid.Table.init (fun aa -> List.count xs ~f:(Amino_acid.equal aa))
...@@ -309,7 +309,7 @@ module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with t ...@@ -309,7 +309,7 @@ module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with t
let inner_maximum_log_likelihood ?debug ?mode ~exchangeability_matrix tree site = let inner_maximum_log_likelihood ?debug ?mode ~exchangeability_matrix tree site =
let counts = let counts =
Tree.leaves tree Tree.leaves tree
|> List.map ~f:(aa_of_leaf_info site) |> List.filter_map ~f:(aa_of_leaf_info site)
|> counts |> counts
in in
let schema = param_schema ?mode counts in let schema = param_schema ?mode counts in
...@@ -370,7 +370,7 @@ module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with t ...@@ -370,7 +370,7 @@ module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with t
in in
let root_frequencies = (param.stationary_distribution0 :> Vector.t) in let root_frequencies = (param.stationary_distribution0 :> Vector.t) in
let leaf_state = aa_of_leaf_info site in let leaf_state = aa_of_leaf_info site in
CTMC.pruning tree ~transition_matrix ~leaf_state ~root_frequencies CTMC.pruning_with_missing_values tree ~transition_matrix ~leaf_state ~root_frequencies
let tuple_map (x, y) ~f = (f x, f y) let tuple_map (x, y) ~f = (f x, f y)
...@@ -381,7 +381,7 @@ module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with t ...@@ -381,7 +381,7 @@ module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with t
| `Ancestral -> true | `Ancestral -> true
| `Convergent -> false | `Convergent -> false
) )
|> tuple_map ~f:(List.map ~f:(aa_of_leaf_info site)) |> tuple_map ~f:(List.filter_map ~f:(aa_of_leaf_info site))
|> tuple_map ~f:Model2.counts |> tuple_map ~f:Model2.counts
let initial_param schema tree site = let initial_param schema tree site =
...@@ -406,7 +406,7 @@ module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with t ...@@ -406,7 +406,7 @@ module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with t
let inner_maximum_log_likelihood ?debug ?mode ?model2_opt ~exchangeability_matrix tree site = let inner_maximum_log_likelihood ?debug ?mode ?model2_opt ~exchangeability_matrix tree site =
let schema = let schema =
Tree.leaves tree Tree.leaves tree
|> List.map ~f:(aa_of_leaf_info site) |> List.filter_map ~f:(aa_of_leaf_info site)
|> Model2.counts |> Model2.counts
|> Model2.param_schema ?mode |> Model2.param_schema ?mode
in in
...@@ -464,7 +464,7 @@ module Pack = struct ...@@ -464,7 +464,7 @@ module Pack = struct
module Site = struct module Site = struct
type t = Amino_acid.t array type t = Amino_acid.t array
type species = int type species = int
let get_aa = Array.get let get_aa x i = Some (Array.get x i)
let of_simulation s = let of_simulation s =
Tree.leaves s Tree.leaves s
|> Array.of_list |> Array.of_list
......
...@@ -116,7 +116,7 @@ end ...@@ -116,7 +116,7 @@ end
module type Site = sig module type Site = sig
type t type t
type species type species
val get_aa : t -> species -> Amino_acid.t val get_aa : t -> species -> Amino_acid.t option
end end
module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with type species = Leaf_info.species) : module Make(Branch_info : Branch_info)(Leaf_info : Leaf_info)(Site : Site with type species = Leaf_info.species) :
......
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