diff options
author | Peter Carbonetto | 2017-05-04 10:52:24 -0500 |
---|---|---|
committer | Peter Carbonetto | 2017-05-04 10:52:24 -0500 |
commit | 452f232cb627d7180bf1c845dff9ddd88af6a600 (patch) | |
tree | 7b4b114dae947b01c552743b34be14214686e399 | |
parent | 03d7d2556a9284dc0ac3e155b5c9a8d69b1b21ee (diff) | |
download | pangemma-452f232cb627d7180bf1c845dff9ddd88af6a600.tar.gz |
Fixed problems with duplicate symbols in io.o, lmm.o, param.o and vc.o; created a Makefile for Mac OS X (tested on 10.11, i.e., El Capitan).
-rw-r--r-- | Makefile.osx | 119 | ||||
-rw-r--r-- | src/io.cpp | 30 | ||||
-rw-r--r-- | src/lmm.cpp | 24 | ||||
-rw-r--r-- | src/param.h | 3 | ||||
-rw-r--r-- | src/vc.cpp | 27 |
5 files changed, 132 insertions, 71 deletions
diff --git a/Makefile.osx b/Makefile.osx new file mode 100644 index 0000000..e5d5a26 --- /dev/null +++ b/Makefile.osx @@ -0,0 +1,119 @@ +#Makefile + +# Supported platforms +# Unix / Linux LNX +# Mac MAC +# Compilation options +# link to LAPACK WITH_LAPACK +# 32-bit binary FORCE_32BIT +# dynamic compilation FORCE_DYNAMIC +# float precision FORCE_FLOAT + +# Set this variable to either LNX or MAC +SYS = MAC +# Leave blank after "=" to disable; put "= 1" to enable +# Disable WITH_LAPACK option can slow computation speed significantly and is not recommended +# Disable WITH_ARPACK option only disable -apprx option in the software +WITH_LAPACK = 1 +FORCE_32BIT = +FORCE_DYNAMIC = 1 +FORCE_FLOAT = +DIST_NAME = gemma-0.95alpha + +# -------------------------------------------------------------------- +# Edit below this line with caution +# -------------------------------------------------------------------- +BIN_DIR = ./bin + +SRC_DIR = ./src + +CPP = g++ + +CPPFLAGS = -F /System/Library/Frameworks -Wall -O3 \ + -I/usr/local/opt/gsl@1/include + +LIBS = -lgsl -lgslcblas -lz -L/usr/local/opt/gsl@1/lib + +OUTPUT = $(BIN_DIR)/gemma + +ifdef FORCE_FLOAT +OUTPUT = $(BIN_DIR)/gemmaf +endif + +SOURCES = $(SRC_DIR)/main.cpp + +HDR = + +# Detailed libary paths, D for dynamic and S for static + +LIBS_LNX_D_LAPACK = -llapack +LIBS_MAC_D_LAPACK = -framework Accelerate +LIBS_LNX_S_LAPACK = /usr/lib/lapack/liblapack.a -lgfortran /usr/lib/atlas-base/libatlas.a /usr/lib/libblas/libblas.a -Wl,--allow-multiple-definition + +# Options + +ifdef FORCE_FLOAT + CPPFLAGS += -DFORCE_FLOAT + SOURCES += $(SRC_DIR)/param_float.cpp $(SRC_DIR)/gemma_float.cpp $(SRC_DIR)/io_float.cpp $(SRC_DIR)/lm_float.cpp $(SRC_DIR)/vc_float.cpp $(SRC_DIR)/lmm_float.cpp $(SRC_DIR)/mvlmm_float.cpp $(SRC_DIR)/bslmm_float.cpp $(SRC_DIR)/prdt_float.cpp $(SRC_DIR)/mathfunc_float.cpp $(SRC_DIR)/gzstream.cpp $(SRC_DIR)/eigenlib.cpp + HDR += $(SRC_DIR)/param_float.h $(SRC_DIR)/gemma_float.h $(SRC_DIR)/io_float.h $(SRC_DIR)/lm_float.h $(SRC_DIR)/lmm_float.h $(SRC_DIR)/vc_float.h $(SRC_DIR)/mvlmm_float.h $(SRC_DIR)/bslmm_float.h $(SRC_DIR)/prdt_float.h $(SRC_DIR)/mathfunc_float.h $(SRC_DIR)/gzstream.h $(SRC_DIR)/eigenlib.h +else + SOURCES += $(SRC_DIR)/param.cpp $(SRC_DIR)/gemma.cpp $(SRC_DIR)/io.cpp $(SRC_DIR)/lm.cpp $(SRC_DIR)/lmm.cpp $(SRC_DIR)/vc.cpp $(SRC_DIR)/mvlmm.cpp $(SRC_DIR)/bslmm.cpp $(SRC_DIR)/prdt.cpp $(SRC_DIR)/mathfunc.cpp $(SRC_DIR)/gzstream.cpp $(SRC_DIR)/eigenlib.cpp + # HDR += $(SRC_DIR)/param.h $(SRC_DIR)/gemma.h $(SRC_DIR)/io.h $(SRC_DIR)/lm.h $(SRC_DIR)/lmm.h $(SRC_DIR)/vc.h $(SRC_DIR)/mvlmm.h $(SRC_DIR)/bslmm.h $(SRC_DIR)/prdt.h $(SRC_DIR)/mathfunc.h $(SRC_DIR)/gzstream.h $(SRC_DIR)/eigenlib.h +endif + +ifdef WITH_LAPACK + OBJS += $(SRC_DIR)/lapack.o + CPPFLAGS += -DWITH_LAPACK +ifeq ($(SYS), MAC) + LIBS += $(LIBS_MAC_D_LAPACK) +else +ifdef FORCE_DYNAMIC + LIBS += $(LIBS_LNX_D_LAPACK) +else + LIBS += $(LIBS_LNX_S_LAPACK) +endif +endif + SOURCES += $(SRC_DIR)/lapack.cpp + HDR += $(SRC_DIR)/lapack.h +endif + +ifdef FORCE_32BIT + CPPFLAGS += -m32 +else + CPPFLAGS += -m64 +endif + +ifdef FORCE_DYNAMIC +else + CPPFLAGS += -static +endif + + +# all +OBJS = $(SOURCES:.cpp=.o) + +all: $(OUTPUT) + +$(OUTPUT): $(OBJS) + $(CPP) $(CPPFLAGS) $(OBJS) $(LIBS) -o $(OUTPUT) + +$(OBJS) : $(HDR) + +.cpp.o: + $(CPP) $(CPPFLAGS) $(HEADERS) -c $*.cpp -o $*.o +.SUFFIXES : .cpp .c .o $(SUFFIXES) + + +clean: + rm -rf ${SRC_DIR}/*.o ${SRC_DIR}/*~ *~ ${SRC_DIR}/*_float.* $(OUTPUT) + +DIST_COMMON = COPYING.txt README.txt Makefile +DIST_SUBDIRS = src doc example bin + +tar: + mkdir -p ./$(DIST_NAME) + cp $(DIST_COMMON) ./$(DIST_NAME)/ + cp -r $(DIST_SUBDIRS) ./$(DIST_NAME)/ + tar cvzf $(DIST_NAME).tar.gz ./$(DIST_NAME)/ + rm -r ./$(DIST_NAME) + @@ -47,10 +47,9 @@ #include "io.h" #endif - using namespace std; - +bool ReadHeader_io (const string &line, HEADER &header); //Print process bar void ProgressBar (string str, double p, double total) @@ -181,7 +180,7 @@ bool ReadFile_snps_header (const string &file_snps, set<string> &setSnps) //read header HEADER header; !safeGetline(infile, line).eof(); - ReadHeader (line, header); + ReadHeader_io (line, header); if (header.rs_col==0 && (header.chr_col==0 || header.pos_col==0) ) { cout<<"missing rs id in the hearder"<<endl; @@ -2501,7 +2500,7 @@ bool bgenKin (const string &file_oxford, vector<int> &indicator_snp, const int k //read header to determine which column contains which item -bool ReadHeader (const string &line, HEADER &header) +bool ReadHeader_io (const string &line, HEADER &header) { string rs_ptr[]={"rs","RS","snp","SNP","snps","SNPS","snpid","SNPID","rsid","RSID","MarkerName"}; set<string> rs_set(rs_ptr, rs_ptr+11); @@ -2636,7 +2635,7 @@ bool ReadFile_cat (const string &file_cat, map<string, size_t> &mapRS2cat, size_ //read header HEADER header; !safeGetline(infile, line).eof(); - ReadHeader (line, header); + ReadHeader_io (line, header); //use the header to count the number of categories n_vc=header.coln; @@ -3209,7 +3208,7 @@ bool ReadFile_wsnp (const string &file_wcat, const size_t n_vc, map<string, vect //read header HEADER header; !safeGetline(infile, line).eof(); - ReadHeader (line, header); + ReadHeader_io (line, header); while (!safeGetline(infile, line).eof()) { if (isBlankLine(line)) {continue;} @@ -3282,7 +3281,7 @@ void ReadFile_beta (const string &file_beta, const map<string, size_t> &mapRS2ca //read header HEADER header; !safeGetline(infile, line).eof(); - ReadHeader (line, header); + ReadHeader_io (line, header); if (header.n_col==0 ) { if ( (header.nobs_col==0 && header.nmis_col==0) && (header.ncase_col==0 && header.ncontrol_col==0) ) { @@ -3413,7 +3412,7 @@ void ReadFile_beta (const string &file_beta, const map<string, double> &mapRS2wA //read header HEADER header; !safeGetline(infile, line).eof(); - ReadHeader (line, header); + ReadHeader_io (line, header); if (header.n_col==0 ) { if ( (header.nobs_col==0 && header.nmis_col==0) && (header.ncase_col==0 && header.ncontrol_col==0) ) { @@ -3846,21 +3845,6 @@ void ReadFile_mstudy (const string &file_mstudy, gsl_matrix *Vq_mat, gsl_vector return; } - -//copied from lmm.cpp; is used in the following function compKtoV -//map a number 1-(n_cvt+2) to an index between 0 and [(n_c+2)^2+(n_c+2)]/2-1 -size_t GetabIndex (const size_t a, const size_t b, const size_t n_cvt) { - if (a>n_cvt+2 || b>n_cvt+2 || a<=0 || b<=0) {cout<<"error in GetabIndex."<<endl; return 0;} - size_t index; - size_t l, h; - if (b>a) {l=a; h=b;} else {l=b; h=a;} - - size_t n=n_cvt+2; - index=(2*n-l+2)*(l-1)/2+h-l; - - return index; -} - //read reference file void ReadFile_mref (const string &file_mref, gsl_matrix *S_mat, gsl_matrix *Svar_mat, gsl_vector *s_vec, size_t &ni) { diff --git a/src/lmm.cpp b/src/lmm.cpp index 044f33c..a707534 100644 --- a/src/lmm.cpp +++ b/src/lmm.cpp @@ -183,30 +183,6 @@ void LMM::WriteFiles () return; } - - - - - - - - - - -//map a number 1-(n_cvt+2) to an index between 0 and [(n_c+2)^2+(n_c+2)]/2-1 -size_t GetabIndex (const size_t a, const size_t b, const size_t n_cvt) { - if (a>n_cvt+2 || b>n_cvt+2 || a<=0 || b<=0) {cout<<"error in GetabIndex."<<endl; return 0;} - size_t index; - size_t l, h; - if (b>a) {l=a; h=b;} else {l=b; h=a;} - - size_t n=n_cvt+2; - index=(2*n-l+2)*(l-1)/2+h-l; - - return index; -} - - void CalcPab (const size_t n_cvt, const size_t e_mode, const gsl_vector *Hi_eval, const gsl_matrix *Uab, const gsl_vector *ab, gsl_matrix *Pab) { size_t index_ab, index_aw, index_bw, index_ww; diff --git a/src/param.h b/src/param.h index 4b4ad29..8db3590 100644 --- a/src/param.h +++ b/src/param.h @@ -299,6 +299,7 @@ public: void UpdateSNP (const map<string, double> &mapRS2wA); }; - +size_t GetabIndex (const size_t a, const size_t b, const size_t n_cvt); + #endif @@ -453,7 +453,7 @@ int LogRL_dev12 (const gsl_vector *log_sigma2, void *params, gsl_vector *dev1, g //read header to determine which column contains which item -bool ReadHeader (const string &line, HEADER &header) +bool ReadHeader_vc (const string &line, HEADER &header) { string rs_ptr[]={"rs","RS","snp","SNP","snps","SNPS","snpid","SNPID","rsid","RSID"}; set<string> rs_set(rs_ptr, rs_ptr+10); @@ -586,7 +586,7 @@ void ReadFile_cor (const string &file_cor, const set<string> &setSnps, vector<st //header !safeGetline(infile, line).eof(); - ReadHeader (line, header); + ReadHeader_vc (line, header); if (header.n_col==0 ) { if (header.nobs_col==0 && header.nmis_col==0) { @@ -700,7 +700,7 @@ void ReadFile_beta (const bool flag_priorscale, const string &file_beta, const m //read header HEADER header; !safeGetline(infile, line).eof(); - ReadHeader (line, header); + ReadHeader_vc (line, header); if (header.n_col==0 ) { if (header.nobs_col==0 && header.nmis_col==0) { @@ -869,7 +869,7 @@ void ReadFile_cor (const string &file_cor, const vector<string> &vec_rs, const v HEADER header; !safeGetline(infile, line).eof(); - ReadHeader (line, header); + ReadHeader_vc (line, header); while (!safeGetline(infile, line).eof()) { //do not read cor values this time; upto col_n-1 @@ -1059,25 +1059,6 @@ void ReadFile_cor (const string &file_cor, const vector<string> &vec_rs, const v return; } - - - - -//copied from lmm.cpp; is used in the following function VCss -//map a number 1-(n_cvt+2) to an index between 0 and [(n_c+2)^2+(n_c+2)]/2-1 -size_t GetabIndex (const size_t a, const size_t b, const size_t n_cvt) { - if (a>n_cvt+2 || b>n_cvt+2 || a<=0 || b<=0) {cout<<"error in GetabIndex."<<endl; return 0;} - size_t index; - size_t l, h; - if (b>a) {l=a; h=b;} else {l=b; h=a;} - - size_t n=n_cvt+2; - index=(2*n-l+2)*(l-1)/2+h-l; - - return index; -} - - //use the new method to calculate variance components with summary statistics //first, use a function CalcS to compute S matrix (where the diagonal elements are part of V(q) ), and then use bootstrap to compute the variance for S, use a set of genotypes, phenotypes, and individual ids, and snp category label void CalcVCss(const gsl_matrix *Vq, const gsl_matrix *S_mat, const gsl_matrix *Svar_mat, const gsl_vector *q_vec, const gsl_vector *s_vec, const double df, vector<double> &v_pve, vector<double> &v_se_pve, double &pve_total, double &se_pve_total, vector<double> &v_sigma2, vector<double> &v_se_sigma2, vector<double> &v_enrich, vector<double> &v_se_enrich) { |