diff options
-rw-r--r-- | src/io.cpp | 54 | ||||
-rw-r--r-- | src/io.h | 4 | ||||
-rw-r--r-- | src/lm.cpp | 6 | ||||
-rw-r--r-- | src/mvlmm.cpp | 8 | ||||
-rw-r--r-- | src/param.cpp | 4 | ||||
-rw-r--r-- | src/param.h | 3 | ||||
-rwxr-xr-x | test/test_suite.sh | 6 |
7 files changed, 30 insertions, 55 deletions
@@ -49,43 +49,17 @@ using namespace std; // Print progress bar. -void ProgressBar(string str, double p, double total) { - double progress = (100.0 * p / total); - int barsize = (int)(progress / 2.0); - char bar[51]; - - cout << str; - for (int i = 0; i < 50; i++) { - if (i < barsize) { - bar[i] = '='; - } else { - bar[i] = ' '; - } - cout << bar[i]; - } - cout << setprecision(2) << fixed << progress << "%\r" << flush; - - return; -} - -// Print progress bar with acceptance ratio. void ProgressBar(string str, double p, double total, double ratio) { - double progress = (100.0 * p / total); - int barsize = (int)(progress / 2.0); - char bar[51]; - - cout << str; - for (int i = 0; i < 50; i++) { - if (i < barsize) { - bar[i] = '='; - } else { - bar[i] = ' '; - } - cout << bar[i]; - } - cout << setprecision(2) << fixed << progress << "% " << ratio << "\r" - << flush; - return; + assert(p<=total); + const double progress = (100.0 * p / total); + const uint barsize = (int)(progress / 2.0); // characters + cout << str << " "; + cout << std::string(barsize,'='); + cout << std::string(50-barsize,' '); + cout << setprecision(0) << fixed << progress << "%"; + if (ratio != -1.0) + cout << setprecision(2) << " " << ratio; + cout << "\r" << flush; } bool isBlankLine(char const *line) { @@ -1407,7 +1381,7 @@ bool BimbamKin(const string file_geno, const set<string> ksnps, string line; !safeGetline(infile, line).eof(); if (t % display_pace == 0 || t == (indicator_snp.size() - 1)) { - ProgressBar("Reading SNPs ", t, indicator_snp.size() - 1); + ProgressBar("Reading SNPs", t, indicator_snp.size() - 1); } if (indicator_snp[t] == 0) continue; @@ -1556,7 +1530,7 @@ bool PlinkKin(const string &file_bed, vector<int> &indicator_snp, for (size_t t = 0; t < indicator_snp.size(); ++t) { if (t % display_pace == 0 || t == (indicator_snp.size() - 1)) { - ProgressBar("Reading SNPs ", t, indicator_snp.size() - 1); + ProgressBar("Reading SNPs", t, indicator_snp.size() - 1); } if (indicator_snp[t] == 0) { continue; @@ -2713,7 +2687,7 @@ bool BimbamKinUncentered(const string &file_geno, const set<string> ksnps, for (size_t t = 0; t < indicator_snp.size(); ++t) { !safeGetline(infile, line).eof(); if (t % display_pace == 0 || t == (indicator_snp.size() - 1)) { - ProgressBar("Reading SNPs ", t, indicator_snp.size() - 1); + ProgressBar("Reading SNPs", t, indicator_snp.size() - 1); } if (indicator_snp[t] == 0) continue; @@ -2918,7 +2892,7 @@ bool PlinkKin(const string &file_bed, const int display_pace, for (size_t t = 0; t < indicator_snp.size(); ++t) { if (t % display_pace == 0 || t == (indicator_snp.size() - 1)) { - ProgressBar("Reading SNPs ", t, indicator_snp.size() - 1); + ProgressBar("Reading SNPs", t, indicator_snp.size() - 1); } if (indicator_snp[t] == 0) { continue; @@ -32,8 +32,8 @@ using namespace std; -void ProgressBar(string str, double p, double total); -void ProgressBar(string str, double p, double total, double ratio); +void ProgressBar(string str, double p, double total, double ratio = -1.0); + std::istream &safeGetline(std::istream &is, std::string &t); bool ReadFile_snps(const string file_snps, set<string> &setSnps); @@ -331,7 +331,7 @@ void LM::AnalyzeGene(const gsl_matrix *W, const gsl_vector *x) { for (size_t t = 0; t < ng_total; t++) { getline(infile, line); if (t % d_pace == 0 || t == ng_total - 1) { - ProgressBar("Performing Analysis ", t, ng_total - 1); + ProgressBar("Performing Analysis", t, ng_total - 1); } ch_ptr = strtok((char *)line.c_str(), " , \t"); rs = ch_ptr; @@ -421,7 +421,7 @@ void LM::AnalyzeBimbam(const gsl_matrix *W, const gsl_vector *y) { for (size_t t = 0; t < indicator_snp.size(); ++t) { getline(infile, line); if (t % d_pace == 0 || t == (ns_total - 1)) { - ProgressBar("Reading SNPs ", t, ns_total - 1); + ProgressBar("Reading SNPs", t, ns_total - 1); } if (indicator_snp[t] == 0) { continue; @@ -547,7 +547,7 @@ void LM::AnalyzePlink(const gsl_matrix *W, const gsl_vector *y) { for (vector<SNPINFO>::size_type t = 0; t < snpInfo.size(); ++t) { if (t % d_pace == 0 || t == snpInfo.size() - 1) { - ProgressBar("Reading SNPs ", t, snpInfo.size() - 1); + ProgressBar("Reading SNPs", t, snpInfo.size() - 1); } if (indicator_snp[t] == 0) { continue; diff --git a/src/mvlmm.cpp b/src/mvlmm.cpp index 88df111..c0dc143 100644 --- a/src/mvlmm.cpp +++ b/src/mvlmm.cpp @@ -3190,7 +3190,7 @@ void MVLMM::AnalyzeBimbam(const gsl_matrix *U, const gsl_vector *eval, for (size_t t = 0; t < indicator_snp.size(); ++t) { !safeGetline(infile, line).eof(); if (t % d_pace == 0 || t == (ns_total - 1)) { - ProgressBar("Reading SNPs ", t, ns_total - 1); + ProgressBar("Reading SNPs", t, ns_total - 1); } if (indicator_snp[t] == 0) { continue; @@ -3639,7 +3639,7 @@ void MVLMM::AnalyzePlink(const gsl_matrix *U, const gsl_vector *eval, } for (vector<SNPINFO>::size_type t = 0; t < snpInfo.size(); ++t) { if (t % d_pace == 0 || t == snpInfo.size() - 1) { - ProgressBar("Reading SNPs ", t, snpInfo.size() - 1); + ProgressBar("Reading SNPs", t, snpInfo.size() - 1); } if (indicator_snp[t] == 0) { continue; @@ -4167,7 +4167,7 @@ void MVLMM::AnalyzeBimbamGXE(const gsl_matrix *U, const gsl_vector *eval, for (size_t t = 0; t < indicator_snp.size(); ++t) { !safeGetline(infile, line).eof(); if (t % d_pace == 0 || t == (ns_total - 1)) { - ProgressBar("Reading SNPs ", t, ns_total - 1); + ProgressBar("Reading SNPs", t, ns_total - 1); } if (indicator_snp[t] == 0) { continue; @@ -4624,7 +4624,7 @@ void MVLMM::AnalyzePlinkGXE(const gsl_matrix *U, const gsl_vector *eval, for (vector<SNPINFO>::size_type t = 0; t < snpInfo.size(); ++t) { if (t % d_pace == 0 || t == snpInfo.size() - 1) { - ProgressBar("Reading SNPs ", t, snpInfo.size() - 1); + ProgressBar("Reading SNPs", t, snpInfo.size() - 1); } if (indicator_snp[t] == 0) { continue; diff --git a/src/param.cpp b/src/param.cpp index 8452fb8..d637481 100644 --- a/src/param.cpp +++ b/src/param.cpp @@ -87,7 +87,7 @@ void trim_individuals(vector<int> &idvs, size_t ni_max, bool debug) { // ---- PARAM class implementation PARAM::PARAM(void) - : mode_silence(false), a_mode(0), k_mode(1), d_pace(100000), + : mode_silence(false), a_mode(0), k_mode(1), d_pace(DEFAULT_PACE), file_out("result"), path_out("./output/"), miss_level(0.05), maf_level(0.01), hwe_level(0), r2_level(0.9999), l_min(1e-5), l_max(1e5), n_region(10), p_nr(0.001), em_prec(0.0001), nr_prec(0.0001), @@ -1150,7 +1150,7 @@ void PARAM::CheckData(void) { } // Set d_pace to 1000 for gene expression. - if (!file_gene.empty() && d_pace == 100000) { + if (!file_gene.empty() && d_pace == DEFAULT_PACE) { d_pace = 1000; } diff --git a/src/param.h b/src/param.h index 3976440..4b473c0 100644 --- a/src/param.h +++ b/src/param.h @@ -27,6 +27,7 @@ #include <vector> #define K_BATCH_SIZE 10000 // #snps used for batched K +#define DEFAULT_PACE 1000 using namespace std; @@ -124,7 +125,7 @@ public: uint a_mode; // Analysis mode, 1/2/3/4 for Frequentist tests int k_mode; // Kinship read mode: 1: n by n matrix, 2: id/id/k_value; vector<size_t> p_column; // Which phenotype column needs analysis. - size_t d_pace; // Display pace + size_t d_pace = DEFAULT_PACE; // Display pace (-pace switch) string file_bfile, file_mbfile; string file_geno, file_mgeno; diff --git a/test/test_suite.sh b/test/test_suite.sh index 350fc27..dc6053a 100755 --- a/test/test_suite.sh +++ b/test/test_suite.sh @@ -62,7 +62,7 @@ testUnivariateLinearMixedModel() { assertEquals "4038540440.86" `perl -nle 'foreach $x (split(/\s+/,$_)) { $sum += sprintf("%.2f",(substr($x,,0,6))) } END { printf "%.2f",$sum }' $outfn` } -testMultivariateLinearMixedModel() { +testLinearMixedModelPhenotypes() { $gemma -g ../example/mouse_hs1940.geno.txt.gz \ -p ../example/mouse_hs1940.pheno.txt \ -n 1 6 \ @@ -92,8 +92,8 @@ testPlinkStandardRelatednessMatrixK() { # Test for https://github.com/genetics-statistics/GEMMA/issues/58 # fixed GSLv2 NaN's that appeared with covariates. -testPlinkMultivariateLinearMixedModel() { - testname=testPlinkMultivariateLinearMixedModel +testPlinkLinearMixedModelCovariates() { + testname=testPlinkLinearMixedModelCovariates datadir=../example $gemma -bfile $datadir/HLC \ -k output/testPlinkStandardRelatednessMatrixK.sXX.txt \ |