From e0671a336595deddaa287a1f1f4f718897d01b90 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 9 Jul 2017 07:38:29 +0000 Subject: Add test framework based on shunit2 --- run_tests.sh | 7 +++++++ test/test_suite.sh | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100755 run_tests.sh create mode 100755 test/test_suite.sh diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 0000000..e8b7d49 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# download shunit2 in order to run tests: +# curl -L "https://dl.dropboxusercontent.com/u/7916095/shunit2-2.0.3.tgz" | tar zx --overwrite + +cd test +./test_suite.sh | tee /dev/stderr | grep -q 'success rate: 100%' diff --git a/test/test_suite.sh b/test/test_suite.sh new file mode 100755 index 0000000..c6aa38e --- /dev/null +++ b/test/test_suite.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +gemma=../bin/gemma + +testCenteredRelatednessMatrix() { + $gemma -g ../example/mouse_hs1940.geno.txt.gz -p ../example/mouse_hs1940.pheno.txt \ + -a ../example/mouse_hs1940.anno.txt -gk -o mouse_hs1940 + assertEquals "3763600" `wc -w < output/mouse_hs1940.cXX.txt` +} + +shunit2=`which shunit2` +if [ -x "$shunit2" ]; then + . $shunit2 +else + # try to run the locally installed shunit2 + . ../shunit2-2.0.3/src/shell/shunit2 +fi -- cgit 1.4.1 From 35405450385ded8797a9a6388e6e2801381f2894 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 9 Jul 2017 08:07:46 +0000 Subject: Test: check result --- test/test_suite.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/test_suite.sh b/test/test_suite.sh index c6aa38e..effc056 100755 --- a/test/test_suite.sh +++ b/test/test_suite.sh @@ -2,10 +2,13 @@ gemma=../bin/gemma -testCenteredRelatednessMatrix() { +testCenteredRelatednessMatrixK() { $gemma -g ../example/mouse_hs1940.geno.txt.gz -p ../example/mouse_hs1940.pheno.txt \ - -a ../example/mouse_hs1940.anno.txt -gk -o mouse_hs1940 + -a ../example/mouse_hs1940.anno.txt -gk -o mouse_hs1940 assertEquals "3763600" `wc -w < output/mouse_hs1940.cXX.txt` + # assertEquals "15f680c" `md5sum < output/mouse_hs1940.cXX.txt | head -c 7` + assertEquals "0.335" `head -c 5 output/mouse_hs1940.cXX.txt` + assertEquals "29.691" `awk '{s+=substr($1,0,6)}END{print s}' output/mouse_hs1940.cXX.txt` } shunit2=`which shunit2` -- cgit 1.4.1 From 0792aee7269e4bf1c2903267e17a12dfebd14884 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 9 Jul 2017 08:33:41 +0000 Subject: Tests: added test for univariate and multivariate LMM Also added 'make check' command in Makefile and documented in INSTALL.md --- .gitignore | 4 +++- INSTALL.md | 4 ++++ Makefile | 2 ++ test/test_suite.sh | 17 +++++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 108e607..d6c227e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,9 +2,11 @@ *.tar.gz src/Eigen example/output +test/output +./output doc/manual.aux doc/manual.bbl doc/manual.blg doc/manual.log doc/manual.out -doc/manual.toc \ No newline at end of file +doc/manual.toc diff --git a/INSTALL.md b/INSTALL.md index f6eb0c0..32d37f3 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -48,3 +48,7 @@ if you get an Eigen error you may need to override the include path. E.g. on GNU Guix with shared libs this may work make EIGEN_INCLUDE_PATH=~/.guix-profile/include/eigen3 FORCE_DYNAMIC=1 + +to run GEMMA tests + + make check diff --git a/Makefile b/Makefile index 0f25d88..a15c043 100644 --- a/Makefile +++ b/Makefile @@ -95,6 +95,8 @@ $(OBJS) : $(HDR) $(CPP) $(CPPFLAGS) $(HEADERS) -c $*.cpp -o $*.o .SUFFIXES : .cpp .c .o $(SUFFIXES) +check: + ./run_tests.sh clean: rm -rf ${SRC_DIR}/*.o ${SRC_DIR}/*~ *~ $(OUTPUT) diff --git a/test/test_suite.sh b/test/test_suite.sh index effc056..8adc5c9 100755 --- a/test/test_suite.sh +++ b/test/test_suite.sh @@ -11,6 +11,23 @@ testCenteredRelatednessMatrixK() { assertEquals "29.691" `awk '{s+=substr($1,0,6)}END{print s}' output/mouse_hs1940.cXX.txt` } +testUnivariateLinearMixedModel() { + $gemma -g ../example/mouse_hs1940.geno.txt.gz -p ../example/mouse_hs1940.pheno.txt -n 1 \ + -a ../example/mouse_hs1940.anno.txt -k ./output/mouse_hs1940.cXX.txt -lmm \ + -o mouse_hs1940_CD8_lmm + assertEquals "118459" `wc -w < output/mouse_hs1940_CD8_lmm.assoc.txt` + assertEquals "92047" `awk '{s+=substr($1,0,6)}END{print s}' output/mouse_hs1940_CD8_lmm.assoc.txt` +} + +testMultivariateLinearMixedModel() { + $gemma -g ../example/mouse_hs1940.geno.txt.gz -p ../example/mouse_hs1940.pheno.txt \ + -n 1 6 -a ../example/mouse_hs1940.anno.txt -k ./output/mouse_hs1940.cXX.txt \ + -lmm -o mouse_hs1940_CD8MCH_lmm + outfn=output/mouse_hs1940_CD8MCH_lmm.assoc.txt + assertEquals "139867" `wc -w < $outfn` + assertEquals "92079" `awk '{s+=substr($1,0,6)}END{print s}' $outfn` +} + shunit2=`which shunit2` if [ -x "$shunit2" ]; then . $shunit2 -- cgit 1.4.1 From d2ea25218f28c01afcb2480960fdf090318a864b Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 9 Jul 2017 08:42:07 +0000 Subject: Tests: more tests --- test/test_suite.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/test_suite.sh b/test/test_suite.sh index 8adc5c9..763c981 100755 --- a/test/test_suite.sh +++ b/test/test_suite.sh @@ -5,6 +5,9 @@ gemma=../bin/gemma testCenteredRelatednessMatrixK() { $gemma -g ../example/mouse_hs1940.geno.txt.gz -p ../example/mouse_hs1940.pheno.txt \ -a ../example/mouse_hs1940.anno.txt -gk -o mouse_hs1940 + assertEquals 0 $? + grep "total computation time" < output/mouse_hs1940.log.txt + assertEquals 0 $? assertEquals "3763600" `wc -w < output/mouse_hs1940.cXX.txt` # assertEquals "15f680c" `md5sum < output/mouse_hs1940.cXX.txt | head -c 7` assertEquals "0.335" `head -c 5 output/mouse_hs1940.cXX.txt` @@ -15,6 +18,9 @@ testUnivariateLinearMixedModel() { $gemma -g ../example/mouse_hs1940.geno.txt.gz -p ../example/mouse_hs1940.pheno.txt -n 1 \ -a ../example/mouse_hs1940.anno.txt -k ./output/mouse_hs1940.cXX.txt -lmm \ -o mouse_hs1940_CD8_lmm + assertEquals 0 $? + grep "total computation time" < output/mouse_hs1940_CD8_lmm.log.txt + assertEquals 0 $? assertEquals "118459" `wc -w < output/mouse_hs1940_CD8_lmm.assoc.txt` assertEquals "92047" `awk '{s+=substr($1,0,6)}END{print s}' output/mouse_hs1940_CD8_lmm.assoc.txt` } @@ -23,6 +29,10 @@ testMultivariateLinearMixedModel() { $gemma -g ../example/mouse_hs1940.geno.txt.gz -p ../example/mouse_hs1940.pheno.txt \ -n 1 6 -a ../example/mouse_hs1940.anno.txt -k ./output/mouse_hs1940.cXX.txt \ -lmm -o mouse_hs1940_CD8MCH_lmm + assertEquals 0 $? + grep "total computation time" < output/mouse_hs1940_CD8MCH_lmm.log.txt + assertEquals 0 $? + outfn=output/mouse_hs1940_CD8MCH_lmm.assoc.txt assertEquals "139867" `wc -w < $outfn` assertEquals "92079" `awk '{s+=substr($1,0,6)}END{print s}' $outfn` -- cgit 1.4.1 From ebb9f253d5fc3bdb9d14de3cb05a8d3292553a94 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 9 Jul 2017 09:03:29 +0000 Subject: Makefile: add OpenBLAS support --- INSTALL.md | 2 +- Makefile | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 32d37f3..de6558b 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -47,7 +47,7 @@ Install listed dependencies and run if you get an Eigen error you may need to override the include path. E.g. on GNU Guix with shared libs this may work - make EIGEN_INCLUDE_PATH=~/.guix-profile/include/eigen3 FORCE_DYNAMIC=1 + make EIGEN_INCLUDE_PATH=~/.guix-profile/include/eigen3 FORCE_DYNAMIC=1 WITH_OPENBLAS=1 to run GEMMA tests diff --git a/Makefile b/Makefile index a15c043..7fba573 100644 --- a/Makefile +++ b/Makefile @@ -10,11 +10,12 @@ # Set this variable to either LNX or MAC SYS = LNX # Leave blank after "=" to disable; put "= 1" to enable -WITH_LAPACK = 1 +WITH_LAPACK = 1 +WITH_OPENBLAS = NO_INTEL_COMPAT = -FORCE_32BIT = -FORCE_DYNAMIC = -DIST_NAME = gemma-0.97 +FORCE_32BIT = +FORCE_DYNAMIC = +DIST_NAME = gemma-0.97 # -------------------------------------------------------------------- # Edit below this line with caution @@ -31,7 +32,7 @@ CPP = g++ CPPFLAGS = -Wall -Weffc++ -O3 -std=gnu++11 -I$(EIGEN_INCLUDE_PATH) ifdef FORCE_DYNAMIC -LIBS = -lgsl -lgslcblas -lblas -pthread -lz +LIBS = -lgsl -lgslcblas -pthread -lz else LIBS = -lgsl -lgslcblas -pthread -lz endif @@ -45,6 +46,8 @@ HDR = # Detailed libary paths, D for dynamic and S for static LIBS_LNX_D_LAPACK = -llapack +LIBS_LNX_D_BLAS = -lblas +LIBS_LNX_D_OPENBLAS = -lopenblas LIBS_MAC_D_LAPACK = -framework Veclib LIBS_LNX_S_LAPACK = /usr/lib/lapack/liblapack.a -lgfortran /usr/lib/atlas-base/libatlas.a /usr/lib/libblas/libblas.a -Wl,--allow-multiple-definition @@ -56,11 +59,14 @@ ifdef WITH_LAPACK ifeq ($(SYS), MAC) LIBS += $(LIBS_MAC_D_LAPACK) else -ifdef FORCE_DYNAMIC - LIBS += $(LIBS_LNX_D_LAPACK) -else - LIBS += $(LIBS_LNX_S_LAPACK) -endif + ifdef FORCE_DYNAMIC + ifdef WITH_OPENBLAS + LIBS += $(LIBS_LNX_D_OPENBLAS) + else + LIBS += $(LIBS_LNX_D_BLAS) + endif + LIBS += $(LIBS_LNX_D_LAPACK) + endif endif SOURCES += $(SRC_DIR)/lapack.cpp HDR += $(SRC_DIR)/lapack.h @@ -95,7 +101,7 @@ $(OBJS) : $(HDR) $(CPP) $(CPPFLAGS) $(HEADERS) -c $*.cpp -o $*.o .SUFFIXES : .cpp .c .o $(SUFFIXES) -check: +check: all ./run_tests.sh clean: -- cgit 1.4.1 From 7ff18ffdf85d3cb66564443bfa9b5f2836f60a25 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 9 Jul 2017 09:04:25 +0000 Subject: Spacing in demo.txt --- example/demo.txt | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/example/demo.txt b/example/demo.txt index 80c5c95..c8082b9 100644 --- a/example/demo.txt +++ b/example/demo.txt @@ -67,17 +67,17 @@ chr rs ps n_miss allele1 allele0 af beta_1 beta_2 Vbeta_1_1 Vbeta_1_2 Vbeta_2_2 1 rs13475700 4098402 0 A C 0.128 -6.727883e-02 1.685363e-01 5.597160e-03 -1.366799e-04 7.574216e-03 1.060482e-01 # The log file also contains Vg and Ve estimates and their standard errors -## REMLE estimate for Vg in the null model: -1.39398 --0.226714 2.08168 -## se(Vg): -0.156661 -0.136319 0.235858 -## REMLE estimate for Ve in the null model: -0.348882 -0.0490525 0.414433 -## se(Ve): -0.0206226 +## REMLE estimate for Vg in the null model: +1.39398 +-0.226714 2.08168 +## se(Vg): +0.156661 +0.136319 0.235858 +## REMLE estimate for Ve in the null model: +0.348882 +0.0490525 0.414433 +## se(Ve): +0.0206226 0.0166233 0.0266869 # Since there are individuals with partially missing phenotypes, one can impute these missing values before association tests -- cgit 1.4.1 From c978835c3630286414df6076d38aad16277cdb6b Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 9 Jul 2017 11:34:59 +0000 Subject: Run test_suite directly from Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7fba573..8b5b113 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,7 @@ $(OBJS) : $(HDR) .SUFFIXES : .cpp .c .o $(SUFFIXES) check: all - ./run_tests.sh + cd test && ./test_suite.sh clean: rm -rf ${SRC_DIR}/*.o ${SRC_DIR}/*~ *~ $(OUTPUT) -- cgit 1.4.1 From d92fc5359540d7c860140f74f9f905d83b24f82d Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 9 Jul 2017 12:25:44 +0000 Subject: Makefile: force unit tests to throw a make error on less than 100% success --- Makefile | 3 +-- test/test_suite.sh | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8b5b113..748c4f2 100644 --- a/Makefile +++ b/Makefile @@ -102,8 +102,7 @@ $(OBJS) : $(HDR) .SUFFIXES : .cpp .c .o $(SUFFIXES) check: all - cd test && ./test_suite.sh - + cd test && ./test_suite.sh | grep -q 'success rate: 100%' clean: rm -rf ${SRC_DIR}/*.o ${SRC_DIR}/*~ *~ $(OUTPUT) diff --git a/test/test_suite.sh b/test/test_suite.sh index 763c981..d65bf40 100755 --- a/test/test_suite.sh +++ b/test/test_suite.sh @@ -11,6 +11,7 @@ testCenteredRelatednessMatrixK() { assertEquals "3763600" `wc -w < output/mouse_hs1940.cXX.txt` # assertEquals "15f680c" `md5sum < output/mouse_hs1940.cXX.txt | head -c 7` assertEquals "0.335" `head -c 5 output/mouse_hs1940.cXX.txt` + # FIXME: The following test fails in the Guix build system (https://github.com/xiangzhou/GEMMA/issues/55) assertEquals "29.691" `awk '{s+=substr($1,0,6)}END{print s}' output/mouse_hs1940.cXX.txt` } -- cgit 1.4.1 From 6cb25f227b0d42a1268c51542f96b9ffafba0bbb Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 9 Jul 2017 12:45:20 +0000 Subject: Makefile: fix output on make check --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 748c4f2..3e8276e 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,8 @@ $(OBJS) : $(HDR) .SUFFIXES : .cpp .c .o $(SUFFIXES) check: all - cd test && ./test_suite.sh | grep -q 'success rate: 100%' + cd test && ./test_suite.sh | tee ../test.log + grep -q 'success rate: 100%' test.log clean: rm -rf ${SRC_DIR}/*.o ${SRC_DIR}/*~ *~ $(OUTPUT) -- cgit 1.4.1 From e415101f7cb6b3e45a2bf49e3f60aa133cbc6517 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Tue, 11 Jul 2017 08:59:33 +0000 Subject: Makefile: compile without -Weffc++ as suggested by https://stackoverflow.com/questions/11496942/understanding-weffc#11529328 reduces warnings --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3e8276e..1a1a87b 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ SRC_DIR = ./src CPP = g++ -CPPFLAGS = -Wall -Weffc++ -O3 -std=gnu++11 -I$(EIGEN_INCLUDE_PATH) +CPPFLAGS = -Wall -O3 -std=gnu++11 -I$(EIGEN_INCLUDE_PATH) ifdef FORCE_DYNAMIC LIBS = -lgsl -lgslcblas -pthread -lz @@ -104,6 +104,7 @@ $(OBJS) : $(HDR) check: all cd test && ./test_suite.sh | tee ../test.log grep -q 'success rate: 100%' test.log + clean: rm -rf ${SRC_DIR}/*.o ${SRC_DIR}/*~ *~ $(OUTPUT) -- cgit 1.4.1 From 3695a36d116710338a2d89006b1c636ce312b8bc Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Tue, 11 Jul 2017 09:05:46 +0000 Subject: Makefile: compiler warnings optional --- Makefile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1a1a87b..c944309 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ # Set this variable to either LNX or MAC SYS = LNX # Leave blank after "=" to disable; put "= 1" to enable +SHOW_COMPILER_WARNINGS = WITH_LAPACK = 1 WITH_OPENBLAS = NO_INTEL_COMPAT = @@ -29,12 +30,16 @@ SRC_DIR = ./src CPP = g++ -CPPFLAGS = -Wall -O3 -std=gnu++11 -I$(EIGEN_INCLUDE_PATH) +CPPFLAGS = -O3 -std=gnu++11 -I$(EIGEN_INCLUDE_PATH) + +ifdef SHOW_COMPILER_WARNINGS + CPPFLAGS += -Wall +endif ifdef FORCE_DYNAMIC -LIBS = -lgsl -lgslcblas -pthread -lz + LIBS = -lgsl -lgslcblas -pthread -lz else -LIBS = -lgsl -lgslcblas -pthread -lz + LIBS = -lgsl -lgslcblas -pthread -lz endif OUTPUT = $(BIN_DIR)/gemma -- cgit 1.4.1 From c3bc17415916a38aae675805b7f26a4cb6aafeca Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Tue, 11 Jul 2017 09:11:41 +0000 Subject: Makefile: silence compiler warnings for Eigen libs --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c944309..72994be 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ SRC_DIR = ./src CPP = g++ -CPPFLAGS = -O3 -std=gnu++11 -I$(EIGEN_INCLUDE_PATH) +CPPFLAGS = -O3 -std=gnu++11 -isystem$(EIGEN_INCLUDE_PATH) ifdef SHOW_COMPILER_WARNINGS CPPFLAGS += -Wall -- cgit 1.4.1 From d6098a5f318543b525878c6cf45ddfe8ec923d9d Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 16 Jul 2017 11:05:39 +0000 Subject: sunit2: added instructions --- .gitignore | 1 + INSTALL.md | 17 +++++++++++++++++ run_tests.sh | 3 +-- test/test_suite.sh | 12 +++++++++--- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index d6c227e..5088ec4 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ doc/manual.blg doc/manual.log doc/manual.out doc/manual.toc +contrib/ diff --git a/INSTALL.md b/INSTALL.md index de6558b..e4da6ff 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -52,3 +52,20 @@ path. E.g. on GNU Guix with shared libs this may work to run GEMMA tests make check + +## Run tests + +GEMMA uses the shunit2 test framework (version 2.0) and can be found +[here](https://github.com/genenetwork/shunit2) + +In the source tree: + + git clone https://github.com/genenetwork/shunit2 contrib/shunit2 + +and run + + make check + +or + + ./run_tests.sh diff --git a/run_tests.sh b/run_tests.sh index e8b7d49..181f687 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash -# download shunit2 in order to run tests: -# curl -L "https://dl.dropboxusercontent.com/u/7916095/shunit2-2.0.3.tgz" | tar zx --overwrite +# download shunit2 in order to run tests (see INSTALL.md) cd test ./test_suite.sh | tee /dev/stderr | grep -q 'success rate: 100%' diff --git a/test/test_suite.sh b/test/test_suite.sh index d65bf40..f1a1c6f 100755 --- a/test/test_suite.sh +++ b/test/test_suite.sh @@ -40,9 +40,15 @@ testMultivariateLinearMixedModel() { } shunit2=`which shunit2` -if [ -x "$shunit2" ]; then +if [ -e "../contrib/shunit2/source/2.0/src/shell/shunit2" ]; then + echo try to run the locally installed shunit2 + . ../contrib/shunit2/source/2.0/src/shell/shunit2 +elif [ -e "../shunit2-2.0.3/src/shell/shunit2" ]; then + echo try to run the older locally installed shunit2 + . ../shunit2-2.0.3/src/shell/shunit2 +elif [ -x "$shunit2" ]; then + echo run system shunit2 . $shunit2 else - # try to run the locally installed shunit2 - . ../shunit2-2.0.3/src/shell/shunit2 + echo "Can not find shunit2 - see INSTALL.md" fi -- cgit 1.4.1