about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr Prins2017-10-06 10:02:45 +0000
committerPjotr Prins2017-10-06 10:02:45 +0000
commit6e95011f7d23246baef78cb2f6fdbe12f5c0793e (patch)
treed96be8822c9c6b72da9ed8fd1e6184444b4a185a
parent2add397847701d8f939eab55bacddb54fdb8c641 (diff)
downloadpangemma-6e95011f7d23246baef78cb2f6fdbe12f5c0793e.tar.gz
LMM: lifter line no
-rw-r--r--src/lmm.cpp13
-rw-r--r--src/lmm.h2
2 files changed, 10 insertions, 5 deletions
diff --git a/src/lmm.cpp b/src/lmm.cpp
index 65f8d26..47ede97 100644
--- a/src/lmm.cpp
+++ b/src/lmm.cpp
@@ -1289,7 +1289,7 @@ in.
 
  */
 
-void LMM::Analyze(std::function< string(void) >& fetch_line,
+void LMM::Analyze(std::function< string(size_t) >& fetch_line,
                   const gsl_matrix *U, const gsl_vector *eval,
                   const gsl_matrix *UtW, const gsl_vector *Uty,
                   const gsl_matrix *W, const gsl_vector *y,
@@ -1377,13 +1377,14 @@ void LMM::Analyze(std::function< string(void) >& fetch_line,
 
   for (size_t t = 0; t < indicator_snp.size(); ++t) {
     // for every SNP
-    string line = fetch_line();
     if (t % d_pace == 0 || t == (ns_total - 1)) {
       ProgressBar("Reading SNPs  ", t, ns_total - 1);
     }
     if (indicator_snp[t] == 0)
       continue;
 
+    string line = fetch_line(t);
+
     char *ch_ptr = strtok((char *)line.c_str(), " , \t");
     enforce_msg(ch_ptr, "Parsing BIMBAM genofile"); // just to be sure
 
@@ -1456,10 +1457,14 @@ void LMM::AnalyzeBimbam(const gsl_matrix *U, const gsl_vector *eval,
 
   igzstream infile(file_geno.c_str(), igzstream::in);
   enforce_msg(infile, "error reading genotype file");
+  size_t prev_line = 0;
 
-  std::function<string(void)>  fetch_line = [&]() {
+  std::function<string(size_t)>  fetch_line = [&](size_t num) {
     string line;
-    safeGetline(infile, line);
+    while (prev_line <= num) {
+      safeGetline(infile, line);
+      prev_line++;
+    }
     return line;
   };
 
diff --git a/src/lmm.h b/src/lmm.h
index bd303b0..dd937a6 100644
--- a/src/lmm.h
+++ b/src/lmm.h
@@ -90,7 +90,7 @@ public:
   void AnalyzeGene(const gsl_matrix *U, const gsl_vector *eval,
                    const gsl_matrix *UtW, const gsl_vector *Utx,
                    const gsl_matrix *W, const gsl_vector *x);
-  void Analyze(std::function< string(void) >& fetch_line,
+  void Analyze(std::function< string(size_t) >& fetch_line,
                const gsl_matrix *U, const gsl_vector *eval,
                const gsl_matrix *UtW, const gsl_vector *Uty,
                const gsl_matrix *W, const gsl_vector *y,