about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr Prins2017-11-11 07:44:30 +0000
committerPjotr Prins2017-11-11 07:44:30 +0000
commit9ec8fa75c6e3f22d951db14fe7512221a65da8e3 (patch)
tree452a3c10a73120b99e8ff387df64b63e5d97b23e
parentbd1195dbe0759aa48ac4360313640d4bb8517f34 (diff)
downloadpangemma-9ec8fa75c6e3f22d951db14fe7512221a65da8e3.tar.gz
Cleaning up buffer use thanks to compiler warnings
-rw-r--r--src/param.cpp38
-rwxr-xr-xtest/test_suite.sh4
2 files changed, 21 insertions, 21 deletions
diff --git a/src/param.cpp b/src/param.cpp
index 919e258..4ae5adf 100644
--- a/src/param.cpp
+++ b/src/param.cpp
@@ -267,16 +267,16 @@ void PARAM::ReadFiles(void) {
     ProcessCvtPhen();
 
     // Obtain covariate matrix.
-    gsl_matrix *W = gsl_matrix_alloc(ni_test, n_cvt);
-    CopyCvt(W);
+    auto W1 = gsl_matrix_safe_alloc(ni_test, n_cvt);
+    CopyCvt(W1);
 
     file_str = file_bfile + ".bed";
-    if (ReadFile_bed(file_str, setSnps, W, indicator_idv, indicator_snp,
+    if (ReadFile_bed(file_str, setSnps, W1, indicator_idv, indicator_snp,
                      snpInfo, maf_level, miss_level, hwe_level, r2_level,
                      ns_test) == false) {
       error = true;
     }
-    gsl_matrix_free(W);
+    gsl_matrix_free(W1);
     ns_total = indicator_snp.size();
   }
 
@@ -300,17 +300,17 @@ void PARAM::ReadFiles(void) {
     ProcessCvtPhen();
 
     // Obtain covariate matrix.
-    gsl_matrix *W = gsl_matrix_alloc(ni_test, n_cvt);
-    CopyCvt(W);
+    auto W2 = gsl_matrix_safe_alloc(ni_test, n_cvt);
+    CopyCvt(W2);
 
     trim_individuals(indicator_idv, ni_max);
     trim_individuals(indicator_cvt, ni_max);
-    if (ReadFile_geno(file_geno, setSnps, W, indicator_idv, indicator_snp,
+    if (ReadFile_geno(file_geno, setSnps, W2, indicator_idv, indicator_snp,
                       maf_level, miss_level, hwe_level, r2_level, mapRS2chr,
                       mapRS2bp, mapRS2cM, snpInfo, ns_test) == false) {
       error = true;
     }
-    gsl_matrix_free(W);
+    gsl_matrix_free(W2);
 
     ns_total = indicator_snp.size();
   }
@@ -326,7 +326,7 @@ void PARAM::ReadFiles(void) {
 
     string file_name;
     size_t t = 0, ns_test_tmp = 0;
-    gsl_matrix *W;
+    gsl_matrix *W3 = NULL;
     while (!safeGetline(infile, file_name).eof()) {
       file_str = file_name + ".bim";
 
@@ -358,12 +358,12 @@ void PARAM::ReadFiles(void) {
         ProcessCvtPhen();
 
         // Obtain covariate matrix.
-        W = gsl_matrix_alloc(ni_test, n_cvt);
-        CopyCvt(W);
+        W3 = gsl_matrix_safe_alloc(ni_test, n_cvt);
+        CopyCvt(W3);
       }
 
       file_str = file_name + ".bed";
-      if (ReadFile_bed(file_str, setSnps, W, indicator_idv, indicator_snp,
+      if (ReadFile_bed(file_str, setSnps, W3, indicator_idv, indicator_snp,
                        snpInfo, maf_level, miss_level, hwe_level, r2_level,
                        ns_test_tmp) == false) {
         error = true;
@@ -376,7 +376,7 @@ void PARAM::ReadFiles(void) {
       t++;
     }
 
-    gsl_matrix_free(W);
+    if (W3) gsl_matrix_free(W3);
 
     infile.close();
     infile.clear();
@@ -402,8 +402,8 @@ void PARAM::ReadFiles(void) {
     ProcessCvtPhen();
 
     // Obtain covariate matrix.
-    gsl_matrix *W = gsl_matrix_alloc(ni_test, n_cvt);
-    CopyCvt(W);
+    gsl_matrix *W4 = gsl_matrix_safe_alloc(ni_test, n_cvt);
+    CopyCvt(W4);
 
     igzstream infile(file_mgeno.c_str(), igzstream::in);
     if (!infile) {
@@ -415,7 +415,7 @@ void PARAM::ReadFiles(void) {
     string file_name;
     size_t ns_test_tmp;
     while (!safeGetline(infile, file_name).eof()) {
-      if (ReadFile_geno(file_name, setSnps, W, indicator_idv, indicator_snp,
+      if (ReadFile_geno(file_name, setSnps, W4, indicator_idv, indicator_snp,
                         maf_level, miss_level, hwe_level, r2_level, mapRS2chr,
                         mapRS2bp, mapRS2cM, snpInfo, ns_test_tmp) == false) {
         error = true;
@@ -427,7 +427,7 @@ void PARAM::ReadFiles(void) {
       ns_total += indicator_snp.size();
     }
 
-    gsl_matrix_free(W);
+    gsl_matrix_free(W4);
 
     infile.close();
     infile.clear();
@@ -455,8 +455,8 @@ void PARAM::ReadFiles(void) {
     ProcessCvtPhen();
 
     // Obtain covariate matrix.
-    gsl_matrix *W = gsl_matrix_alloc(ni_test, n_cvt);
-    CopyCvt(W);
+    // gsl_matrix *W5 = gsl_matrix_alloc(ni_test, n_cvt);
+    // CopyCvt(W5);
 
     if (ReadFile_gene(file_gene, vec_read, snpInfo, ng_total) == false) {
       error = true;
diff --git a/test/test_suite.sh b/test/test_suite.sh
index 92b01fb..5cfc848 100755
--- a/test/test_suite.sh
+++ b/test/test_suite.sh
@@ -13,7 +13,7 @@ testBslmm1() {
     assertEquals 0 $?
     outfn1=output/$outn.hyp.txt
     outfn2=output/$outn.param.txt
-    assertEquals "45181.93" `perl -nle 'foreach $x (split(/\s+/,$_)) { $sum += sprintf("%.2f",(substr($x,,0,6))) } END { printf "%.2f",$sum }' $outfn1`
+    assertEquals "45181" `perl -nle 'foreach $x (split(/\s+/,$_)) { $sum += sprintf("%.0f",(substr($x,,0,6))) } END { printf "%.0f",$sum }' $outfn1`
     assertEquals "4043967139.42" `perl -nle 'foreach $x (split(/\s+/,$_)) { $sum += sprintf("%.2f",(substr($x,,0,6))) } END { printf "%.2f",$sum }' $outfn2`
 }
 
@@ -42,7 +42,7 @@ testBslmm3() {
            -w 1000 -s 10000 -seed 1
     assertEquals 0 $?
     outfn=output/$outn.hyp.txt
-    assertEquals "29130.74" `perl -nle 'foreach $x (split(/\s+/,$_)) { $sum += sprintf("%.2f",(substr($x,,0,6))) } END { printf "%.2f",$sum }' $outfn`
+    assertEquals "291" `perl -nle 'foreach $x (split(/\s+/,$_)) { $sum += sprintf("%.0f",(substr($x,,0,6))) } END { printf "%.0f",100*$sum }' $outfn`
 }
 
 testBslmm4() {