about summary refs log tree commit diff
path: root/src/lmm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lmm.cpp')
-rw-r--r--src/lmm.cpp50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/lmm.cpp b/src/lmm.cpp
index 1319d7c..1e5e229 100644
--- a/src/lmm.cpp
+++ b/src/lmm.cpp
@@ -108,11 +108,11 @@ void LMM::WriteFiles() {
 
   file_str = path_out + "/" + file_out;
   file_str += ".assoc.txt";
-  checkpoint("lmm-write-files",file_str.c_str());
+  checkpoint("lmm-write-files",file_str);
 
   ofstream outfile(file_str.c_str(), ofstream::out);
   if (!outfile) {
-    cout << "error writing file: " << file_str.c_str() << endl;
+    cout << "error writing file: " << file_str << endl;
     return;
   }
 
@@ -206,21 +206,29 @@ void LMM::WriteFiles() {
 
     common_header();
 
-    size_t t = 0;
-    for (size_t i = 0; i < snpInfo.size(); ++i) {
-      if (indicator_snp[i] == 0)
-        continue;
-      auto snp = snpInfo[i].rs_number;
-      if (process_gwasnps && setGWASnps.count(snp) == 0)
-        continue;
-      // cout << t << endl;
-      outfile << snpInfo[i].chr << "\t" << snpInfo[i].rs_number << "\t"
-              << snpInfo[i].base_position << "\t" << snpInfo[i].n_miss << "\t"
-              << snpInfo[i].a_minor << "\t" << snpInfo[i].a_major << "\t"
-              << fixed << setprecision(3) << snpInfo[i].maf << "\t";
-
-      sumstats(sumStat[t]);
-      t++;
+    if (snpInfo.size()) {
+      size_t t = 0;
+      for (size_t i = 0; i < snpInfo.size(); ++i) {
+        if (indicator_snp[i] == 0)
+          continue;
+        auto snp = snpInfo[i].rs_number;
+        if (process_gwasnps && setGWASnps.count(snp) == 0)
+          continue;
+        // cout << t << endl;
+        outfile << snpInfo[i].chr << "\t" << snpInfo[i].rs_number << "\t"
+                << snpInfo[i].base_position << "\t" << snpInfo[i].n_miss << "\t"
+                << snpInfo[i].a_minor << "\t" << snpInfo[i].a_major << "\t"
+                << fixed << setprecision(3) << snpInfo[i].maf << "\t";
+
+        sumstats(sumStat[t]);
+        t++;
+      }
+    }
+    else
+    {
+      for (auto &s : sumStat) {
+        sumstats(s);
+      }
     }
   }
 
@@ -2008,7 +2016,7 @@ void LMM::mdb_analyze(std::function< SnpNameValues2(size_t) >& fetch_snp,
       continue;
     auto snp = get<1>(tup);
     auto gs = get<2>(tup);
-    cout << t << " SNP: " << snp << endl;
+    // cout << t << " SNP: " << snp << endl;
 
     // check whether SNP is included in gwasnps (used by LOCO)
     /*
@@ -2061,8 +2069,8 @@ void LMM::mdb_analyze(std::function< SnpNameValues2(size_t) >& fetch_snp,
   if (c % msize)
     batch_compute(c % msize);
   ProgressBar("Reading SNPS", num_markers - 1, num_markers - 1);
-  // cout << "Counted SNPs " << c << " sumStat " << sumStat.size() << endl;
   cout << endl;
+  cout << "Counted SNPs " << c << " sumStat " << sumStat.size() << endl;
   checkpoint_nofile("end-lmm-mdb-analyze");
 
   gsl_vector_safe_free(x);
@@ -2125,7 +2133,7 @@ void LMM::mdb_calc_gwa(const gsl_matrix *U, const gsl_vector *eval,
 
     if (result) {
       size_t num_floats = value.size() / sizeof(float);
-      cout << string(key) << ":" << num_floats << "," << ni_total << " " << endl;
+      // cout << string(key) << ":" << num_floats << "," << ni_total << " " << endl;
       assert(num_floats == ni_total);
       const float* gsbuf = reinterpret_cast<const float*>(value.data());
       auto snp = string(key);
@@ -2135,7 +2143,7 @@ void LMM::mdb_calc_gwa(const gsl_matrix *U, const gsl_vector *eval,
       for (size_t i = 0; i < size; ++i) {
         gs.push_back(static_cast<double>(gsbuf[i]));
       }
-      cout << "!!!!" << size << snp << ": " << gs[0] << "," << gs[1] << "," << gs[2] << "," << gs[3] << endl;
+      // cout << "!!!!" << size << snp << ": " << gs[0] << "," << gs[1] << "," << gs[2] << "," << gs[3] << endl;
     }
     // return { result,snp,gs };
     return make_tuple(result, snp, gs);