Commit c39f81c7 authored by Louis Duchemin's avatar Louis Duchemin
Browse files

In-house LMM x Gemma : fixes not positive-definite matrix

parent 23f9cbc2
...@@ -43,7 +43,7 @@ let orthomam_echolocation = { ...@@ -43,7 +43,7 @@ let orthomam_echolocation = {
Orthomam.tree_of_db Orthomam.tree_of_db
~branch_length_unit:`Amino_acid ~branch_length_unit:`Amino_acid
~convergent_species:Orthomam.species_with_echolocation ~convergent_species:Orthomam.species_with_echolocation
(Codepitk.Orthomam_db.make "omm") (Codepitk.Orthomam_db.make "/home/louis/Data/omm")
) ; ) ;
rooted = false ; rooted = false ;
branch_scale = 1. ; branch_scale = 1. ;
...@@ -60,12 +60,12 @@ let meth ?(requires_rooted_tree = false) f label = ...@@ -60,12 +60,12 @@ let meth ?(requires_rooted_tree = false) f label =
{ f ; label ; requires_rooted_tree } { f ; label ; requires_rooted_tree }
let methods = Pipeline.[ let methods = Pipeline.[
meth tdg09 "tdg09" ; (* meth tdg09 "tdg09" ;
meth pcoc "pcoc" ; meth pcoc "pcoc" ; *)
(* meth pcoc_v2 ~col:3 "pcoc v2" ; *) (* meth pcoc_v2 ~col:3 "pcoc v2" ; *)
meth (gemma ~lmm_test:`Score ~relatedness_mode:`Standardized) "gemma" ; meth (gemma ~lmm_test:`Score ~relatedness_mode:`Standardized) "gemma" ;
meth inhouse_lmm "LMM" ; meth inhouse_lmm "LMM" ;
meth (lmm_with_gemma_matrix ~relatedness_mode:`Standardized) "LMM_Gemma"; meth (lmm_with_gemma_matrix ~relatedness_mode:`Centered) "LMM_Gemma";
meth multinomial_asymptotic_lrt "multinomial" ; meth multinomial_asymptotic_lrt "multinomial" ;
meth topological "topological" ~requires_rooted_tree:true ; meth topological "topological" ~requires_rooted_tree:true ;
] ]
...@@ -89,6 +89,7 @@ let benchmark_rds ?(seed = 42) { tree = t ; rooted ; ne_s ; branch_scale ; _ } = ...@@ -89,6 +89,7 @@ let benchmark_rds ?(seed = 42) { tree = t ; rooted ; ne_s ; branch_scale ; _ } =
let () = let () =
let open Bistro_utils.Repo in let open Bistro_utils.Repo in
let datasets = [ besnard2009 ; rubisco ; oneline_rodent ; orthomam_echolocation ] in let datasets = [ besnard2009 ; rubisco ; oneline_rodent ; orthomam_echolocation ] in
(* let datasets = [ besnard2009 ] in *)
let repo = let repo =
List.map datasets ~f:(fun d -> List.map datasets ~f:(fun d ->
item [d.label ^ ".rds"] (benchmark_rds d) item [d.label ^ ".rds"] (benchmark_rds d)
...@@ -96,3 +97,22 @@ let () = ...@@ -96,3 +97,22 @@ let () =
in in
let loggers = [ Bistro_utils.Console_logger.create () ] in let loggers = [ Bistro_utils.Console_logger.create () ] in
build_main ~loggers ~np:4 ~mem:(`GB 4) repo ~outdir:"res" build_main ~loggers ~np:4 ~mem:(`GB 4) repo ~outdir:"res"
(* module Top = Bistro_utils.Toplevel_eval.Make(struct
let np = 10
let mem = 8
end)() *)
(*
let () =
let q =
Pipeline.query ~seed:42 ~tree:(NHX besnard2009.tree) ~branch_scale:1. ~ne_s:(1., 1.)
~profiles:"example/aa_fitness/263SelectedProfiles.tsv"
~n_h0:90 ~n_ha:10 ()
in
(* Gemma.calculate_relatedness_matrix
~mode:`Standardized
~genotype:(Gemma.genotype_of_fasta (Pipeline.amino_acid_alignment q))
~phenotype:(Gemma.phenotype_of_tree (Pipeline.tree ~branch_length_unit:`Amino_acid q)) *)
Pipeline.lmm_with_gemma_matrix q ~relatedness_mode:`Standardized
|> Top.path
|> print_endline *)
\ No newline at end of file
open Core_kernel
open Bistro
type assignment =
| Path : string * _ path workflow -> assignment
module type Toplevel = sig
val eval : 'a workflow -> 'a
end
let path var_id w = Path (var_id, w)
let rconsole (module T : Toplevel) code assignments =
let paths =
List.map assignments ~f:(fun (Path (_, w)) -> Workflow.path w)
|> Workflow.list
|> T.eval
in
print_endline code ;
List.iter2_exn assignments paths ~f:(fun (Path (var_id, _)) path ->
Printf.printf "%s <- '%s'\n" var_id path
)
open Bistro
type assignment
module type Toplevel = sig
val eval : 'a workflow -> 'a
end
val path :
string ->
_ path workflow ->
assignment
val rconsole :
(module Toplevel) ->
string ->
assignment list ->
unit
...@@ -109,8 +109,8 @@ let phenotypes_of_tree t = ...@@ -109,8 +109,8 @@ let phenotypes_of_tree t =
correlation matrix, provided in sparse representation, [n] being correlation matrix, provided in sparse representation, [n] being
the dimension of the (square) matrix and [cors] the list of non-zero coefficients *) the dimension of the (square) matrix and [cors] the list of non-zero coefficients *)
let transform_matrix n cors = let transform_matrix n cors =
let sigma () = matrix_of_correlations n cors in let sigma = matrix_of_correlations n cors in
let mat_C = in_place (L.potrf ~up:false) (sigma ()) in let mat_C = in_place (L.potrf ~up:false) sigma in
for i = 1 to L.Mat.dim1 mat_C do for i = 1 to L.Mat.dim1 mat_C do
for j = i + 1 to L.Mat.dim2 mat_C do for j = i + 1 to L.Mat.dim2 mat_C do
mat_C.{i, j} <- 0. mat_C.{i, j} <- 0.
...@@ -123,8 +123,12 @@ let load_relatedness_matrix filename = ...@@ -123,8 +123,12 @@ let load_relatedness_matrix filename =
In_channel.read_lines filename In_channel.read_lines filename
|> List.mapi ~f:(fun i row -> |> List.mapi ~f:(fun i row ->
String.split row ~on:'\t' String.split row ~on:'\t'
|> List.mapi ~f:(fun j value -> i, j, (float_of_string value)) |> List.mapi ~f:(fun j value ->
) in (* small addition on the diagonal to ensure eigen values are strictly positive *)
let m_ij = float_of_string value +. if i = j then 0.000001 else 0. in
i, j, m_ij
)
) in
transform_matrix (List.length rowwise_matrix) (List.concat rowwise_matrix) transform_matrix (List.length rowwise_matrix) (List.concat rowwise_matrix)
......
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