From 836981552d411b97f9360af9e1222782688f5d59 Mon Sep 17 00:00:00 2001 From: Mike Lin Date: Sat, 12 Apr 2014 22:01:27 -0700 Subject: [PATCH] a few systematic/reproducible tests --- .gitignore | 4 +++ Makefile | 6 +++- src/Makefile | 5 +-- src/_tags | 1 + src/test.ml | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/testSim.ml | 3 +- 6 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 src/test.ml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fefab16 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +PhyloCSF.Linux.x86_64 +PhyloCSF.Darwin.x86_64 +_build +*.native diff --git a/Makefile b/Makefile index 7c91983..9667ce0 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/Makefile b/src/Makefile index 98bbae2..3e161b8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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 *~ diff --git a/src/_tags b/src/_tags index ea5007d..de65795 100644 --- a/src/_tags +++ b/src/_tags @@ -1,3 +1,4 @@ <**/*.ml> or <**/*.mli>: pp(ocaml+twt) + or : pkg_should, pkg_oUnit, pkg_str true: debug, pkg_batteries, pkg_CamlPaml diff --git a/src/test.ml b/src/test.ml new file mode 100644 index 0000000..a0420bb --- /dev/null +++ b/src/test.ml @@ -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 diff --git a/src/testSim.ml b/src/testSim.ml index a71a19d..1dd8c68 100644 --- a/src/testSim.ml +++ b/src/testSim.ml @@ -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 () =