aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Carbonetto2017-05-31 10:02:50 -0500
committerPeter Carbonetto2017-05-31 10:02:50 -0500
commit38de84d5d6e72728c06a57f8eeea0bb975f7192e (patch)
treef68e038c1e45e6c6e36eca1d81061e988c00965f
parent3f5d57d302188525f266ec041ebb745f6931876e (diff)
downloadpangemma-38de84d5d6e72728c06a57f8eeea0bb975f7192e.tar.gz
Removing FORCE_FLOAT from some more C++ source files.
-rw-r--r--src/io.cpp94
-rw-r--r--src/io.h149
2 files changed, 138 insertions, 105 deletions
diff --git a/src/io.cpp b/src/io.cpp
index ccaec30..1a4d466 100644
--- a/src/io.cpp
+++ b/src/io.cpp
@@ -1,6 +1,6 @@
/*
- Genome-wide Efficient Mixed Model Association (GEMMA)
- Copyright (C) 2011 Xiang Zhou
+ Genome-wide Efficient Mixed Model Association (GEMMA)
+ Copyright (C) 2011-2017 Xiang Zhou
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -13,7 +13,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
@@ -40,19 +40,12 @@
#include "gzstream.h"
#include "mathfunc.h"
#include "eigenlib.h"
-
-#ifdef FORCE_FLOAT
-#include "io_float.h"
-#else
#include "io.h"
-#endif
-
using namespace std;
-//Print process bar
-void ProgressBar (string str, double p, double total)
-{
+// 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];
@@ -68,10 +61,8 @@ void ProgressBar (string str, double p, double total)
return;
}
-
-//Print process bar (with acceptance ratio)
-void ProgressBar (string str, double p, double total, double ratio)
-{
+// 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];
@@ -83,37 +74,31 @@ void ProgressBar (string str, double p, double total, double ratio)
cout<<bar[i];
}
cout<<setprecision(2)<<fixed<<progress<<"% "<<ratio<<"\r"<<flush;
-
-
return;
}
-
-bool isBlankLine(char const* line)
-{
- for ( char const* cp = line; *cp; ++cp )
- {
- if ( !isspace(*cp) ) return false;
+bool isBlankLine(char const* line) {
+ for ( char const* cp = line; *cp; ++cp ) {
+ if ( !isspace(*cp) )
+ return false;
}
return true;
}
-bool isBlankLine(std::string const& line)
-{
+bool isBlankLine(std::string const& line) {
return isBlankLine(line.c_str());
}
-// in case files are ended with "\r" or "\r\n"
-std::istream& safeGetline(std::istream& is, std::string& t)
-{
+// In case files are ended with "\r" or "\r\n".
+std::istream& safeGetline(std::istream& is, std::string& t) {
t.clear();
- // The characters in the stream are read one-by-one using a std::streambuf.
- // That is faster than reading them one-by-one using the std::istream.
- // Code that uses streambuf this way must be guarded by a sentry object.
- // The sentry object performs various tasks,
- // such as thread synchronization and updating the stream state.
-
+ // The characters in the stream are read one-by-one using a
+ // std::streambuf. That is faster than reading them one-by-one
+ // using the std::istream. Code that uses streambuf this way must
+ // be guarded by a sentry object. The sentry object performs
+ // various tasks, such as thread synchronization and updating the
+ // stream state.
std::istream::sentry se(is, true);
std::streambuf* sb = is.rdbuf();
@@ -127,7 +112,9 @@ std::istream& safeGetline(std::istream& is, std::string& t)
sb->sbumpc();
return is;
case EOF:
- // Also handle the case when the last line has no line ending
+
+ // Also handle the case when the last line has no line
+ // ending.
if(t.empty())
is.setstate(std::ios::eofbit);
return is;
@@ -137,16 +124,15 @@ std::istream& safeGetline(std::istream& is, std::string& t)
}
}
-//Read snp file
-bool ReadFile_snps (const string &file_snps, set<string> &setSnps)
-{
+// Read SNP file.
+bool ReadFile_snps (const string &file_snps, set<string> &setSnps) {
setSnps.clear();
- //ifstream infile (file_snps.c_str(), ifstream::in);
- //if (!infile) {cout<<"error! fail to open snps file: "<<file_snps<<endl; return false;}
-
igzstream infile (file_snps.c_str(), igzstream::in);
- if (!infile) {cout<<"error! fail to open snps file: "<<file_snps<<endl; return false;}
+ if (!infile) {
+ cout << "error! fail to open snps file: " << file_snps << endl;
+ return false;
+ }
string line;
char *ch_ptr;
@@ -162,21 +148,19 @@ bool ReadFile_snps (const string &file_snps, set<string> &setSnps)
return true;
}
-
-bool ReadFile_snps_header (const string &file_snps, set<string> &setSnps)
-{
+bool ReadFile_snps_header (const string &file_snps, set<string> &setSnps) {
setSnps.clear();
- //ifstream infile (file_snps.c_str(), ifstream::in);
- //if (!infile) {cout<<"error! fail to open snps file: "<<file_snps<<endl; return false;}
-
igzstream infile (file_snps.c_str(), igzstream::in);
- if (!infile) {cout<<"error! fail to open snps file: "<<file_snps<<endl; return false;}
+ if (!infile) {
+ cout << "error! fail to open snps file: " << file_snps << endl;
+ return false;
+ }
string line, rs, chr, pos;
char *ch_ptr;
- //read header
+ // Read header.
HEADER header;
!safeGetline(infile, line).eof();
ReadHeader_io (line, header);
@@ -210,7 +194,6 @@ bool ReadFile_snps_header (const string &file_snps, set<string> &setSnps)
return true;
}
-
//Read log file
bool ReadFile_log (const string &file_log, double &pheno_mean)
{
@@ -4085,14 +4068,7 @@ void ReadFile_mref (const string &file_mref, gsl_matrix *S_mat, gsl_matrix *Svar
//free matrices
gsl_matrix_free(S_sub);
gsl_matrix_free(Svar_sub);
- //gsl_matrix_free(V_sub);
gsl_vector_free(s);
return;
}
-
-
-
-
-
-
diff --git a/src/io.h b/src/io.h
index 073812c..365127a 100644
--- a/src/io.h
+++ b/src/io.h
@@ -1,6 +1,6 @@
/*
- Genome-wide Efficient Mixed Model Association (GEMMA)
- Copyright (C) 2011 Xiang Zhou
+ Genome-wide Efficient Mixed Model Association (GEMMA)
+ Copyright (C) 2011-2017 Xiang Zhou
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -13,13 +13,12 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __IO_H__
#define __IO_H__
-
#include <vector>
#include <map>
#include <algorithm>
@@ -27,18 +26,10 @@
#include "gsl/gsl_matrix.h"
#include "gzstream.h"
-
-#ifdef FORCE_FLOAT
-#include "param_float.h"
-#else
#include "param.h"
-#endif
using namespace std;
-
-
-
void ProgressBar (string str, double p, double total);
void ProgressBar (string str, double p, double total, double ratio);
std::istream& safeGetline(std::istream& is, std::string& t);
@@ -48,36 +39,86 @@ bool ReadFile_snps_header (const string &file_snps, set<string> &setSnps);
bool ReadFile_log (const string &file_log, double &pheno_mean);
bool ReadFile_bim (const string &file_bim, vector<SNPINFO> &snpInfo);
-bool ReadFile_fam (const string &file_fam, vector<vector<int> > &indicator_pheno, vector<vector<double> > &pheno, map<string, int> &mapID2num, const vector<size_t> &p_column);
-
-bool ReadFile_cvt (const string &file_cvt, vector<int> &indicator_cvt, vector<vector<double> > &cvt, size_t &n_cvt);
-bool ReadFile_anno (const string &file_bim, map<string, string> &mapRS2chr, map<string, long int> &mapRS2bp, map<string, double> &mapRS2cM);
-bool ReadFile_pheno (const string &file_pheno, vector<vector<int> > &indicator_pheno, vector<vector<double> > &pheno, const vector<size_t> &p_column);
-bool ReadFile_column (const string &file_pheno, vector<int> &indicator_idv, vector<double> &pheno, const int &p_column);
-
-bool ReadFile_geno (const string &file_geno, const set<string> &setSnps, const gsl_matrix *W, vector<int> &indicator_idv, vector<int> &indicator_snp, const double &maf_level, const double &miss_level, const double &hwe_level, const double &r2_level, map<string, string> &mapRS2chr, map<string, long int> &mapRS2bp, map<string, double> &mapRS2cM, vector<SNPINFO> &snpInfo, size_t &ns_test);
-bool ReadFile_bed (const string &file_bed, const set<string> &setSnps, const gsl_matrix *W, vector<int> &indicator_idv, vector<int> &indicator_snp, vector<SNPINFO> &snpInfo, const double &maf_level, const double &miss_level, const double &hwe_level, const double &r2_level, size_t &ns_test);
-bool Bimbam_ReadOneSNP (const size_t inc, const vector<int> &indicator_idv, igzstream &infile, gsl_vector *geno, double &geno_mean);
-void Plink_ReadOneSNP (const int pos, const vector<int> &indicator_idv, ifstream &infile, gsl_vector *geno, double &geno_mean);
-
-void ReadFile_kin (const string &file_kin, vector<int> &indicator_idv, map<string, int> &mapID2num, const size_t k_mode, bool &error, gsl_matrix *G);
-void ReadFile_mk (const string &file_mk, vector<int> &indicator_idv, map<string, int> &mapID2num, const size_t k_mode, bool &error, gsl_matrix *G);
+bool ReadFile_fam (const string &file_fam,
+ vector<vector<int> > &indicator_pheno,
+ vector<vector<double> > &pheno,
+ map<string, int> &mapID2num,
+ const vector<size_t> &p_column);
+
+bool ReadFile_cvt (const string &file_cvt,
+ vector<int> &indicator_cvt,
+ vector<vector<double> > &cvt,
+ size_t &n_cvt);
+bool ReadFile_anno (const string &file_bim, map<string, string> &mapRS2chr,
+ map<string, long int> &mapRS2bp,
+ map<string, double> &mapRS2cM);
+bool ReadFile_pheno (const string &file_pheno,
+ vector<vector<int> > &indicator_pheno,
+ vector<vector<double> > &pheno,
+ const vector<size_t> &p_column);
+bool ReadFile_column (const string &file_pheno, vector<int> &indicator_idv,
+ vector<double> &pheno, const int &p_column);
+
+bool ReadFile_geno (const string &file_geno, const set<string> &setSnps,
+ const gsl_matrix *W, vector<int> &indicator_idv,
+ vector<int> &indicator_snp, const double &maf_level,
+ const double &miss_level, const double &hwe_level,
+ const double &r2_level, map<string, string> &mapRS2chr,
+ map<string, long int> &mapRS2bp,
+ map<string, double> &mapRS2cM, vector<SNPINFO> &snpInfo,
+ size_t &ns_test);
+bool ReadFile_bed (const string &file_bed, const set<string> &setSnps,
+ const gsl_matrix *W, vector<int> &indicator_idv,
+ vector<int> &indicator_snp, vector<SNPINFO> &snpInfo,
+ const double &maf_level, const double &miss_level,
+ const double &hwe_level, const double &r2_level,
+ size_t &ns_test);
+bool Bimbam_ReadOneSNP (const size_t inc, const vector<int> &indicator_idv,
+ igzstream &infile, gsl_vector *geno,
+ double &geno_mean);
+void Plink_ReadOneSNP (const int pos, const vector<int> &indicator_idv,
+ ifstream &infile, gsl_vector *geno, double &geno_mean);
+
+void ReadFile_kin (const string &file_kin, vector<int> &indicator_idv,
+ map<string, int> &mapID2num, const size_t k_mode,
+ bool &error, gsl_matrix *G);
+void ReadFile_mk (const string &file_mk, vector<int> &indicator_idv,
+ map<string, int> &mapID2num, const size_t k_mode,
+ bool &error, gsl_matrix *G);
void ReadFile_eigenU (const string &file_u, bool &error, gsl_matrix *U);
void ReadFile_eigenD (const string &file_d, bool &error, gsl_vector *eval);
-bool BimbamKin (const string &file_geno, vector<int> &indicator_snp, const int k_mode, const int display_pace, gsl_matrix *matrix_kin);
-bool PlinkKin (const string &file_bed, vector<int> &indicator_snp, const int k_mode, const int display_pace, gsl_matrix *matrix_kin);
-
-bool ReadFile_geno (const string &file_geno, vector<int> &indicator_idv, vector<int> &indicator_snp, gsl_matrix *UtX, gsl_matrix *K, const bool calc_K);
-bool ReadFile_bed (const string &file_bed, vector<int> &indicator_idv, vector<int> &indicator_snp, gsl_matrix *UtX, gsl_matrix *K, const bool calc_K);
-bool ReadFile_geno (const string &file_geno, vector<int> &indicator_idv, vector<int> &indicator_snp, vector<vector<unsigned char> > &Xt, gsl_matrix *K, const bool calc_K, const size_t ni_test, const size_t ns_test);
-bool ReadFile_bed (const string &file_bed, vector<int> &indicator_idv, vector<int> &indicator_snp, vector<vector<unsigned char> > &Xt, gsl_matrix *K, const bool calc_K, const size_t ni_test, const size_t ns_test);
-
-bool ReadFile_est (const string &file_est, const vector<size_t> &est_column, map<string, double> &mapRS2est);
+bool BimbamKin (const string &file_geno, vector<int> &indicator_snp,
+ const int k_mode, const int display_pace,
+ gsl_matrix *matrix_kin);
+bool PlinkKin (const string &file_bed, vector<int> &indicator_snp,
+ const int k_mode, const int display_pace,
+ gsl_matrix *matrix_kin);
+
+bool ReadFile_geno (const string &file_geno, vector<int> &indicator_idv,
+ vector<int> &indicator_snp, gsl_matrix *UtX,
+ gsl_matrix *K, const bool calc_K);
+bool ReadFile_bed (const string &file_bed, vector<int> &indicator_idv,
+ vector<int> &indicator_snp, gsl_matrix *UtX,
+ gsl_matrix *K, const bool calc_K);
+bool ReadFile_geno (const string &file_geno, vector<int> &indicator_idv,
+ vector<int> &indicator_snp,
+ vector<vector<unsigned char> > &Xt, gsl_matrix *K,
+ const bool calc_K, const size_t ni_test,
+ const size_t ns_test);
+bool ReadFile_bed (const string &file_bed, vector<int> &indicator_idv,
+ vector<int> &indicator_snp,
+ vector<vector<unsigned char> > &Xt, gsl_matrix *K,
+ const bool calc_K, const size_t ni_test,
+ const size_t ns_test);
+
+bool ReadFile_est (const string &file_est, const vector<size_t> &est_column,
+ map<string, double> &mapRS2est);
bool CountFileLines (const string &file_input, size_t &n_lines);
-bool ReadFile_gene (const string &file_gene, vector<double> &vec_read, vector<SNPINFO> &snpInfo, size_t &ng_total);
+bool ReadFile_gene (const string &file_gene, vector<double> &vec_read,
+ vector<SNPINFO> &snpInfo, size_t &ng_total);
bool ReadHeader_io (const string &line, HEADER &header);
bool ReadFile_cat (const string &file_cat, map<string, size_t> &mapRS2cat, size_t &n_vc);
@@ -97,16 +138,32 @@ void ReadFile_beta (const string &file_beta, const map<string, size_t> &mapRS2ca
void ReadFile_beta (const string &file_beta, const map<string, double> &mapRS2wA, map<string, string> &mapRS2A1, map<string, double> &mapRS2z);
void Calcq (const size_t n_block, const vector<size_t> &vec_cat, const vector<size_t> &vec_ni, const vector<double> &vec_weight, const vector<double> &vec_z2, gsl_matrix *Vq, gsl_vector *q, gsl_vector *s);
-void ReadFile_study (const string &file_study, gsl_matrix *Vq, gsl_vector *q_vec, gsl_vector *s_vec, size_t &ni);
-void ReadFile_ref (const string &file_ref, gsl_matrix *S_mat, gsl_matrix *Svar_mat, gsl_vector *s_vec, size_t &ni);
-void ReadFile_mstudy (const string &file_mstudy, gsl_matrix *Vq, gsl_vector *q_vec, gsl_vector *s_vec, size_t &ni);
-void ReadFile_mref (const string &file_mref, gsl_matrix *S_mat, gsl_matrix *Svar_mat, gsl_vector *s_vec, size_t &ni);
-
-// WJA added
-bool bgenKin (const string &file_geno, vector<int> &indicator_snp, const int k_mode, const int display_pace, gsl_matrix *matrix_kin);
-bool ReadFile_bgen(const string &file_bgen, const set<string> &setSnps, const gsl_matrix *W, vector<int> &indicator_idv, vector<int> &indicator_snp, vector<SNPINFO> &snpInfo, const double &maf_level, const double &miss_level, const double &hwe_level, const double &r2_level, size_t &ns_test);
-bool ReadFile_sample(const string &file_sample, vector<vector<int> > &indicator_pheno, vector<vector<double> > &pheno, const vector<size_t> &p_column, vector<int> &indicator_cvt, vector<vector<double> > &cvt, size_t &n_cvt);
-
+void ReadFile_study (const string &file_study, gsl_matrix *Vq,
+ gsl_vector *q_vec, gsl_vector *s_vec, size_t &ni);
+void ReadFile_ref (const string &file_ref, gsl_matrix *S_mat,
+ gsl_matrix *Svar_mat, gsl_vector *s_vec, size_t &ni);
+void ReadFile_mstudy (const string &file_mstudy, gsl_matrix *Vq,
+ gsl_vector *q_vec, gsl_vector *s_vec, size_t &ni);
+void ReadFile_mref (const string &file_mref, gsl_matrix *S_mat,
+ gsl_matrix *Svar_mat, gsl_vector *s_vec, size_t &ni);
+
+// WJA added.
+bool bgenKin (const string &file_geno, vector<int> &indicator_snp,
+ const int k_mode, const int display_pace,
+ gsl_matrix *matrix_kin);
+bool ReadFile_bgen(const string &file_bgen, const set<string> &setSnps,
+ const gsl_matrix *W, vector<int> &indicator_idv,
+ vector<int> &indicator_snp, vector<SNPINFO> &snpInfo,
+ const double &maf_level, const double &miss_level,
+ const double &hwe_level, const double &r2_level,
+ size_t &ns_test);
+bool ReadFile_sample(const string &file_sample,
+ vector<vector<int> > &indicator_pheno,
+ vector<vector<double> > &pheno,
+ const vector<size_t> &p_column,
+ vector<int> &indicator_cvt,
+ vector<vector<double> > &cvt,
+ size_t &n_cvt);
#endif