about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr Prins2025-11-27 13:42:10 +0100
committerPjotr Prins2025-11-27 13:42:10 +0100
commiteb037e2b78bc6bbeca8dde0c62f9d916e2a7bedc (patch)
treef46bf143b93efbffdb03a0a057f777626f558243
parentfad3d64d66a4705b3da33a90480c7e24c35b9c44 (diff)
downloadpangemma-eb037e2b78bc6bbeca8dde0c62f9d916e2a7bedc.tar.gz
Introduce first test
-rw-r--r--premake5.lua2
-rw-r--r--src/gemma.cpp6
-rw-r--r--src/gemma_io.cpp2
-rw-r--r--src/param.cpp8
-rwxr-xr-xtest/runner16
5 files changed, 27 insertions, 7 deletions
diff --git a/premake5.lua b/premake5.lua
index 0a20977..d380dc4 100644
--- a/premake5.lua
+++ b/premake5.lua
@@ -5,7 +5,7 @@
 --
 -- Including bin
 --
---   premake5 gmake && make verbose=1 config=debug -j 8 && LD_LIBRARY_PATH=$GUIX_ENVIRONMENT/lib ./build/bin/Debug/gemma
+--   premake5 gmake && make verbose=1 config=debug -j 8 && time LD_LIBRARY_PATH=$GUIX_ENVIRONMENT/lib ./test/runner
 --
 -- Or
 --
diff --git a/src/gemma.cpp b/src/gemma.cpp
index 38b4913..fdb19fd 100644
--- a/src/gemma.cpp
+++ b/src/gemma.cpp
@@ -1919,11 +1919,15 @@ void GEMMA::BatchRun(PARAM &cPar) {
 
     time_start = clock();
 
+    if (cPar.error == true) {
+      cout << "error! failed to prepare for calculating relatedness matrix. " << endl;
+      return;
+    }
     cPar.CalcKin(G);
 
     cPar.time_G = (clock() - time_start) / (double(CLOCKS_PER_SEC) * 60.0);
     if (cPar.error == true) {
-      cout << "error! fail to calculate relatedness matrix. " << endl;
+      cout << "error! failed to calculate relatedness matrix. " << endl;
       return;
     }
 
diff --git a/src/gemma_io.cpp b/src/gemma_io.cpp
index 99b04af..664a4bd 100644
--- a/src/gemma_io.cpp
+++ b/src/gemma_io.cpp
@@ -655,7 +655,7 @@ bool ReadFile_fam(const string &file_fam, vector<vector<int>> &indicator_pheno,
 ## Modified (Mutated) Parameters:
 
 1. **`indicator_idv`** (vector<int>&)
-   - Actually **not modified** - only read from to determine which individuals to include
+   - **Not modified** - only read from to determine which individuals to include
 
 2. **`indicator_snp`** (vector<int>&)
    - **Modified**: Cleared at the start (`indicator_snp.clear()`)
diff --git a/src/param.cpp b/src/param.cpp
index 9e55693..82121b9 100644
--- a/src/param.cpp
+++ b/src/param.cpp
@@ -318,7 +318,7 @@ void PARAM::ReadFiles(void) {
 
     trim_individuals(indicator_idv, ni_max);
     trim_individuals(indicator_cvt, ni_max);
-    // The following reads the geno file to get the SNPs
+    // The following reads the geno file to get the SNPs - only for BIMBAM
     if (is_bimbam && ReadFile_bimbam_geno(file_geno, setSnps, W2, indicator_idv, indicator_snp,
                                           maf_level, miss_level, hwe_level, r2_level, mapRS2chr,
                                           mapRS2bp, mapRS2cM, snpInfo, ns_test) == false) {
@@ -392,7 +392,7 @@ void PARAM::ReadFiles(void) {
     infile.clear();
   }
 
-  // Read genotype and phenotype file for multiple BIMBAM files.
+  // Read genotype and phenotype file for multiple BIMBAM files. Note this goes untested.
   if (!file_mgeno.empty()) {
 
     // Annotation file before genotype file.
@@ -1273,8 +1273,8 @@ void PARAM::ReadBIMBAMGenotypes(gsl_matrix *UtX, gsl_matrix *K, const bool calc_
       error = true;
     }
   } else {
-      // Read BIMBAM. Not supposed to be mdb
-      if (is_mdb || ReadFile_geno(file_geno, indicator_idv, indicator_snp, UtX, K, calc_K) == false) {
+      // Read BIMBAM
+      if (is_bimbam && ReadFile_geno(file_geno, indicator_idv, indicator_snp, UtX, K, calc_K) == false) {
       error = true;
     }
   }
diff --git a/test/runner b/test/runner
index ad5b381..1748692 100755
--- a/test/runner
+++ b/test/runner
@@ -5,7 +5,10 @@ exec guile --debug -s "$0" "$@"
 
 (define-module (test-runner)
   #:use-module (ice-9 match)
+  #:use-module (srfi srfi-1) ; for last
+  #:use-module (srfi srfi-13)
   #:use-module (srfi srfi-64)
+  #:use-module (ice-9 rdelim)
   )
 
 (test-begin "runner")
@@ -21,4 +24,17 @@ exec guile --debug -s "$0" "$@"
 ;; Finish the testsuite, and report results.
 (test-end "vec-test")
 
+(test-begin "external-gemma-run")
+(let [(err (system "./build/bin/Debug/gemma -g ./example/mouse_hs1940.geno.txt.gz -p ./example/mouse_hs1940.pheno.txt -gk -o mouse_hs1940 -debug"))]
+  (test-eqv 0 err))
+(let [(err (system "./build/bin/Debug/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 -o mouse_hs1940 -lmm 9 -debug"))]
+  (test-eqv 0 err))
+(call-with-input-file "output/mouse_hs1940.assoc.txt"
+  (lambda (port)
+    (read-line port)  ; skip first line
+    (let* ((fields (string-split (read-line port) #\tab))
+           (last-field (last fields)))
+      (test-eqv 208.0 (truncate (* 1000 (string->number last-field)))))))
+(test-end "external-gemma-run")
+
 (test-end "runner")