diff options
| author | Pjotr Prins | 2025-12-04 12:37:48 +0100 |
|---|---|---|
| committer | Pjotr Prins | 2025-12-04 12:37:48 +0100 |
| commit | d95db7c5f117bc945b224bd8815feb8c0076e7ba (patch) | |
| tree | 74f5341974e9ebc0762176f932324deadf477fab /src | |
| parent | aa1f2d54b052e0830c327828dc759938b29ac2a9 (diff) | |
| download | pangemma-d95db7c5f117bc945b224bd8815feb8c0076e7ba.tar.gz | |
Output has same values as original!
Diffstat (limited to 'src')
| -rw-r--r-- | src/lmm.cpp | 25 | ||||
| -rw-r--r-- | src/lmm.h | 9 |
2 files changed, 24 insertions, 10 deletions
diff --git a/src/lmm.cpp b/src/lmm.cpp index 1d3b8e0..d13ce3c 100644 --- a/src/lmm.cpp +++ b/src/lmm.cpp @@ -1928,7 +1928,7 @@ void LMM::mdb_analyze(std::function< SnpNameValues2(size_t) >& fetch_snp, statistics (beta, standard errors, p-values) and stores results in sumStat. */ - auto batch_compute = [&](size_t l) { // using a C++ closure + auto batch_compute = [&](size_t l, const Markers &markers) { // using a C++ closure // Compute SNPs in batch, note the computations are independent per SNP debug_msg("enter batch_compute"); assert(l>0); @@ -1986,8 +1986,9 @@ void LMM::mdb_analyze(std::function< SnpNameValues2(size_t) >& fetch_snp, time_opt += (clock() - time_start) / (double(CLOCKS_PER_SEC) * 60.0); + auto markerinfo = markers[i]; // Store summary data. - SUMSTAT2 st = {beta, se, lambda_remle, lambda_mle, p_wald, p_lrt, p_score, logl_H1}; + SUMSTAT2 st = {markerinfo, beta, se, lambda_remle, lambda_mle, p_wald, p_lrt, p_score, logl_H1}; sumstat2.push_back(st); } }; @@ -2001,6 +2002,7 @@ void LMM::mdb_analyze(std::function< SnpNameValues2(size_t) >& fetch_snp, } */ const size_t progress_step = (num_markers/50>d_pace ? num_markers/50 : d_pace); + Markers markers; assert(num_markers > 0); for (size_t t = 0; t < num_markers; ++t) { @@ -2021,6 +2023,8 @@ void LMM::mdb_analyze(std::function< SnpNameValues2(size_t) >& fetch_snp, // auto mpos = get<3>(tup); auto markerinfo = get<1>(tup); auto gs = get<2>(tup); + + markers.push_back(markerinfo); // cout << t << " SNP: " << snp << endl; // check whether SNP is included in gwasnps (used by LOCO) @@ -2066,13 +2070,16 @@ void LMM::mdb_analyze(std::function< SnpNameValues2(size_t) >& fetch_snp, gsl_vector_safe_memcpy(&Xlarge_col.vector, x); c++; // count markers going in + if (c % msize == 0) { - batch_compute(msize); + batch_compute(msize,markers); + markers.clear(); + markers.reserve(msize); } } if (c % msize) - batch_compute(c % msize); + batch_compute(c % msize,markers); ProgressBar("Reading markers", num_markers - 1, num_markers - 1); cout << endl; cout << "Counted markers " << c << " sumStat " << sumstat2.size() << endl; @@ -2092,8 +2099,14 @@ void LMM::mdb_analyze(std::function< SnpNameValues2(size_t) >& fetch_snp, auto sumstats = [&] (SUMSTAT2 st) { outfile << scientific << setprecision(6); - - // outfile << st.marker << "\t"; + auto tup = st.markerinfo; + auto name = get<0>(tup); + auto chr = get<1>(tup); + auto pos = get<2>(tup); + + outfile << chr << "\t"; + outfile << name << "\t"; + outfile << pos << "\t"; if (a_mode != M_LMM2) { outfile << st.beta << "\t"; outfile << st.se << "\t"; diff --git a/src/lmm.h b/src/lmm.h index c24872c..35064c7 100644 --- a/src/lmm.h +++ b/src/lmm.h @@ -45,9 +45,14 @@ public: size_t e_mode; }; +typedef tuple< string, uint16_t, uint32_t, uint32_t > MarkerChrPos; +typedef vector<MarkerChrPos> Markers; +typedef tuple< string,vector<double> > SnpNameValues; +typedef tuple< bool,MarkerChrPos,vector<double> > SnpNameValues2; // Results for LMM. class SUMSTAT2 { public: + MarkerChrPos markerinfo; double beta; // REML estimator for beta. double se; // SE for beta. double lambda_remle; // REML estimator for lambda. @@ -60,10 +65,6 @@ public: // 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,MarkerChrPos,vector<double> > SnpNameValues2; class LMM { |
