Permalink
Browse files

a few systematic/reproducible tests

  • Loading branch information...
1 parent 59e8eda commit 836981552d411b97f9360af9e1222782688f5d59 @mlin committed Apr 13, 2014
Showing with 111 additions and 4 deletions.
  1. +4 −0 .gitignore
  2. +5 −1 Makefile
  3. +3 −2 src/Makefile
  4. +1 −0 src/_tags
  5. +96 −0 src/test.ml
  6. +2 −1 src/testSim.ml
View
@@ -0,0 +1,4 @@
+PhyloCSF.Linux.x86_64
+PhyloCSF.Darwin.x86_64
+_build
+*.native
View
@@ -11,7 +11,11 @@ PhyloCSF: CamlPaml
CamlPaml:
$(MAKE) -C lib/CamlPaml $(MFLAGS) reinstall
-
+
+test: PhyloCSF
+ $(MAKE) -C lib/CamlPaml $(MFLAGS) test
+ $(MAKE) -C src $(MFLAGS) test
+
clean:
$(MAKE) -C lib/CamlPaml clean
$(MAKE) -C src clean
View
@@ -1,8 +1,9 @@
all:
ocamlbuild PhyloCSF.native
-test:
- ocamlbuild testSim.native
+test: all
+ ocamlbuild testSim.native test.native
+ ./test.native -verbose
clean:
rm -f *~
View
@@ -1,3 +1,4 @@
<**/*.ml> or <**/*.mli>: pp(ocaml+twt)
+<test.ml> or <test.native>: pkg_should, pkg_oUnit, pkg_str
true: debug, pkg_batteries, pkg_CamlPaml
View
@@ -0,0 +1,96 @@
+open Batteries
+open Printf
+open OUnit
+open Should
+
+let dn_here = Filename.dirname Sys.argv.(0)
+
+let fn_PhyloCSF = Filename.concat dn_here "PhyloCSF.native"
+
+(* test results on the three bundled example alignments *)
+
+let run_PhyloCSF species params =
+ let cmd = sprintf "%s %s %s" fn_PhyloCSF (Filename.concat dn_here ("../PhyloCSF_Parameters/" ^ species)) params
+
+ let phylocsf_in = Unix.open_process_in ~cleanup:true cmd
+
+ let phylocsf_answer = input_line phylocsf_in
+ match Unix.close_process_in phylocsf_in with
+ | Unix.WEXITED 0 -> String.nsplit phylocsf_answer "\t"
+ | _ -> raise Exit
+
+let talAA () =
+ let ans = run_PhyloCSF "12flies" "../PhyloCSF_Examples/tal-AA.fa"
+ print_endline (String.join "\t" ans)
+ List.nth ans 1 $hould # equal "score(decibans)"
+ float_of_string (List.nth ans 2) $hould # be # within (297.62,297.63)
+
+let aldh2_ex5_out () =
+ let ans = run_PhyloCSF "29mammals" "../PhyloCSF_Examples/ALDH2.exon5.fa"
+ print_endline (String.join "\t" ans)
+ List.nth ans 1 $hould # equal "score(decibans)"
+ float_of_string (List.nth ans 2) $hould # be # within (-178.93,-178.92)
+
+let aldh2_ex5_in () =
+ let ans = run_PhyloCSF "29mammals" "../PhyloCSF_Examples/ALDH2.exon5.fa --frames=6"
+ print_endline (String.join "\t" ans)
+ List.nth ans 1 $hould # equal "max_score(decibans)"
+ float_of_string (List.nth ans 2) $hould # be # within (218.26,218.27)
+ int_of_string (List.nth ans 3) $hould # equal 1
+ int_of_string (List.nth ans 4) $hould # equal 111
+ List.nth ans 5 $hould # equal "+"
+
+let aldh2_mRNA () =
+ let ans = run_PhyloCSF "29mammals" "../PhyloCSF_Examples/Aldh2.mRNA.fa --orf=ATGStop --frames=3 --removeRefGaps --aa"
+ print_endline (String.join "\t" ans)
+ List.nth ans 1 $hould # equal "max_score(decibans)"
+ float_of_string (List.nth ans 2) $hould # be # within (2013.92,2013.93)
+ int_of_string (List.nth ans 3) $hould # equal 343
+ int_of_string (List.nth ans 4) $hould # equal 1899
+ string (List.nth ans 5) $hould # be # matching (Str.regexp "^MLRAALTTVRRGPRLSRLLSAAA.*")
+
+let example_tests = "examples" >::: [
+ "tal-AA" >:: talAA;
+ "ALDH2 ex5 out-of-frame" >:: aldh2_ex5_out;
+ "ALDH2 ex5 in-frame" >:: aldh2_ex5_in;
+ "Aldh2 mRNA" >:: aldh2_mRNA
+ ]
+
+(* simulations
+ FIXME: currently there is no verification of the results except that PhyloCSF
+ successfully exits; you have to eyeball the test stdout. *)
+
+let fn_testSim = Filename.concat dn_here "testSim.native"
+
+let check cmd = match Sys.command cmd with
+ | 0 -> ()
+ | c when (c=130 || c=255) -> exit c (* ctrl-C *)
+ | c -> failwith (sprintf "Child process exit code %d" c)
+
+let sim_AsIs_fixed () =
+ check (sprintf "%s --maxUTR=0 --constantFrame --constantStrand 12flies ' --strategy=fixed'" fn_testSim)
+
+let sim_AsIs_mle () =
+ check (sprintf "%s --maxUTR=0 --constantFrame --constantStrand 12flies ' --strategy=mle'" fn_testSim)
+
+let sim_ATGStop_fixed () =
+ check (sprintf "%s 12flies ' --orf=ATGStop --frames=6 --strategy=fixed'" fn_testSim)
+
+let sim_ATGStop_mle () =
+ check (sprintf "%s 12flies ' --orf=ATGStop --frames=6 --strategy=mle'" fn_testSim)
+
+
+let sim_tests = "simulations" >::: [
+ "AsIs_fixed" >:: sim_AsIs_fixed;
+ "AsIs_mle" >:: sim_AsIs_mle;
+ "ATGStop_fixed" >:: sim_ATGStop_fixed;
+ "ATGStop_mle" >:: sim_ATGStop_mle
+ ]
+
+let all_tests =
+ "PhyloCSF" >::: [
+ sim_tests;
+ example_tests
+ ]
+
+run_test_tt_main all_tests
View
@@ -16,7 +16,7 @@ module Codon = CamlPaml.Code.Codon64
let opt_parser = OptParser.make ~usage:"%prog 12flies \" --frames=6 --orf=ATGStop --strategy=fixed\"" ()
let opt ?group ?h ?hide ?s ?short_names ?l ?long_names x = OptParser.add opt_parser ?group ?help:h ?hide ?short_name:s ?long_name:l x; x
-let n = opt ~s:'n' (StdOpt.int_option ~default:8 ())
+let n = opt ~s:'n' (StdOpt.int_option ~default:5 ())
let min_utr = opt ~l:"minUTR" (StdOpt.int_option ~default:10 ())
let max_utr = opt ~l:"maxUTR" (StdOpt.int_option ~default:50 ())
let min_cds = opt ~l:"minCDS" (StdOpt.int_option ~default:40 ())
@@ -138,6 +138,7 @@ let run_phylocsf aln =
let phylocsf_answer = input_line phylocsf_in
match Unix.close_process (phylocsf_in,phylocsf_out) with
| Unix.WEXITED 0 -> String.nsplit phylocsf_answer "\t"
+ | Unix.WEXITED c -> exit c
| _ -> raise Exit
let main () =

0 comments on commit 8369815

Please sign in to comment.