about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPjotr Prins2025-12-04 12:08:35 +0100
committerPjotr Prins2025-12-04 12:08:35 +0100
commit956e23d88788d15a93a68f773b3a7939260ec124 (patch)
treeb95dc131689032b08996197ca2a0bf1bebeebb43 /src
parentfd58087fc723fc7d82dac8b8fd9cc5cf8c854bee (diff)
downloadpangemma-956e23d88788d15a93a68f773b3a7939260ec124.tar.gz
Unpack marker
Diffstat (limited to 'src')
-rw-r--r--src/lmm.cpp40
-rw-r--r--src/lmm.h19
2 files changed, 31 insertions, 28 deletions
diff --git a/src/lmm.cpp b/src/lmm.cpp
index 324e310..d3bfbbf 100644
--- a/src/lmm.cpp
+++ b/src/lmm.cpp
@@ -1876,22 +1876,6 @@ void LMM::Analyze(std::function< SnpNameValues(size_t) >& fetch_snp,
  */
 
 
-// Results for LMM.
-class SUMSTAT2 {
-public:
-  double beta;         // REML estimator for beta.
-  double se;           // SE for beta.
-  double lambda_remle; // REML estimator for lambda.
-  double lambda_mle;   // MLE estimator for lambda.
-  double p_wald;       // p value from a Wald test.
-  double p_lrt;        // p value from a likelihood ratio test.
-  double p_score;      // p value from a score test.
-  double logl_H1;      // log likelihood under the alternative
-                       // hypothesis as a measure of goodness of fit,
-                       // see https://github.com/genetics-statistics/GEMMA/issues/81
-};
-
-
 
 void LMM::mdb_analyze(std::function< SnpNameValues2(size_t) >& fetch_snp,
                       const gsl_matrix *U, const gsl_vector *eval,
@@ -2211,11 +2195,11 @@ void LMM::mdb_calc_gwa(const gsl_matrix *U, const gsl_vector *eval,
     auto success = cursor.get(key, value, mdb_fetch);
     mdb_fetch = MDB_NEXT;
 
-    string marker;
     uint8_t chr;
-    uint64_t pos;
+    uint32_t pos;
     // size_t pos;
     vector<double> gs;
+    MarkerChrPos markerinfo;
 
     if (success) {
       size_t num_floats = value.size() / sizeof(float);
@@ -2230,18 +2214,20 @@ void LMM::mdb_calc_gwa(const gsl_matrix *U, const gsl_vector *eval,
       // "S>L>L>"
       const uint8_t* data = reinterpret_cast<const uint8_t*>(key.data());
       chr = static_cast<uint8_t>(data[1]);
-      // Extract big-endian uint32 manually abcd -> dcba
-      pos = (static_cast<uint32_t>(data[2]) << 24) |
-        (static_cast<uint32_t>(data[4]) << 8)  |
-        (static_cast<uint32_t>(data[3]) << 16) |
-        (static_cast<uint32_t>(data[5]));
-      auto pos2 = __builtin_bswap32(pos);
+      // Extract big-endian uint32
+      // uint32_t rest = static_cast<uint32_t>(data[2]);
+      uint32_t pos =  (data[2] << 24) | (data[3] << 16) |
+        (data[4] << 8) | data[5];
+
+      uint32_t num = (data[6] << 24) | (data[7] << 16) |
+        (data[8] << 8) | data[9];
 
       string_view value2;
       marker_mdb.get(rtxn,key,value2);
-      marker = string(value2);
+      auto marker = string(value2);
       // 1       rs13476251      174792257
-      cout << static_cast<int>(chr) << ":" << pos2 << "|" << pos << " " << marker << endl ;
+      // cout << static_cast<int>(chr) << ":" << pos2 << " line " << rest2 << ":" << marker << endl ;
+      markerinfo = make_tuple(marker,chr,pos,num);
 
       auto size = num_floats;
       gs.reserve(size);
@@ -2250,7 +2236,7 @@ void LMM::mdb_calc_gwa(const gsl_matrix *U, const gsl_vector *eval,
       }
       // cout << "!!!!" << size << snp << ": " << gs[0] << "," << gs[1] << "," << gs[2] << "," << gs[3] << endl;
     }
-    return make_tuple(success, chr, pos, marker, gs);
+    return make_tuple(success, chr, pos, markerinfo, gs);
   };
   LMM::mdb_analyze(fetch_snp,U,eval,UtW,Uty,W,y,gwasnps,num_markers);
 }
diff --git a/src/lmm.h b/src/lmm.h
index 65d37b2..10dacde 100644
--- a/src/lmm.h
+++ b/src/lmm.h
@@ -45,8 +45,25 @@ public:
   size_t e_mode;
 };
 
+// Results for LMM.
+class SUMSTAT2 {
+public:
+  double beta;         // REML estimator for beta.
+  double se;           // SE for beta.
+  double lambda_remle; // REML estimator for lambda.
+  double lambda_mle;   // MLE estimator for lambda.
+  double p_wald;       // p value from a Wald test.
+  double p_lrt;        // p value from a likelihood ratio test.
+  double p_score;      // p value from a score test.
+  double logl_H1;      // log likelihood under the alternative
+                       // hypothesis as a measure of goodness of fit,
+                       // see https://github.com/genetics-statistics/GEMMA/issues/81
+};
+
+typedef tuple< string, uint16_t, uint32_t, uint32_t > MarkerChrPos;
+
 typedef tuple< string,vector<double> > SnpNameValues;
-typedef tuple< bool,uint8_t,size_t,string,vector<double> > SnpNameValues2;
+typedef tuple< bool,uint8_t,size_t,MarkerChrPos,vector<double> > SnpNameValues2;
 
 class LMM {