From c1132606169875be6d07b54b30e8ae9446341bc2 Mon Sep 17 00:00:00 2001
From: Peter Carbonetto
Date: Sun, 4 Jun 2017 12:06:36 -0500
Subject: Removed FORCE_FLOAT from prdt.h/prdt.cpp.
---
src/prdt.cpp | 274 +++++++++++++++++++++++++++++------------------------------
1 file changed, 136 insertions(+), 138 deletions(-)
(limited to 'src/prdt.cpp')
diff --git a/src/prdt.cpp b/src/prdt.cpp
index 2875119..db0fa14 100644
--- a/src/prdt.cpp
+++ b/src/prdt.cpp
@@ -1,6 +1,6 @@
/*
Genome-wide Efficient Mixed Model Association (GEMMA)
- Copyright (C) 2011 Xiang Zhou
+ 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,10 +13,8 @@
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 .
- */
-
-
+ along with this program. If not, see .
+*/
#include
#include
@@ -33,28 +31,16 @@
#include "gsl/gsl_linalg.h"
#include "gsl/gsl_blas.h"
-
#include "io.h"
-#include "lapack.h" //for functions EigenDecomp
+#include "lapack.h"
#include "gzstream.h"
-
-#ifdef FORCE_FLOAT
-#include "io_float.h"
-#include "prdt_float.h"
-#include "mathfunc_float.h"
-#else
#include "io.h"
#include "prdt.h"
#include "mathfunc.h"
-#endif
using namespace std;
-
-
-
-void PRDT::CopyFromParam (PARAM &cPar)
-{
+void PRDT::CopyFromParam (PARAM &cPar) {
a_mode=cPar.a_mode;
d_pace=cPar.d_pace;
@@ -81,19 +67,14 @@ void PRDT::CopyFromParam (PARAM &cPar)
return;
}
-void PRDT::CopyToParam (PARAM &cPar)
-{
+void PRDT::CopyToParam (PARAM &cPar) {
cPar.ns_test=ns_test;
cPar.time_eigen=time_eigen;
return;
}
-
-
-
-void PRDT::WriteFiles (gsl_vector *y_prdt)
-{
+void PRDT::WriteFiles (gsl_vector *y_prdt) {
string file_str;
file_str=path_out+"/"+file_out;
file_str+=".";
@@ -101,7 +82,10 @@ void PRDT::WriteFiles (gsl_vector *y_prdt)
file_str+=".txt";
ofstream outfile (file_str.c_str(), ofstream::out);
- if (!outfile) {cout<<"error writing file: "<size2; j++) {
- outfile<size, ni_total=G->size1;
gsl_matrix *Goo=gsl_matrix_alloc (ni_test, ni_test);
@@ -190,7 +172,9 @@ void PRDT::AddBV (gsl_matrix *G, const gsl_vector *u_hat, gsl_vector *y_prdt)
clock_t time_start=clock();
EigenDecomp (Goo, U, eval, 0);
for (size_t i=0; isize; i++) {
- if (gsl_vector_get(eval,i)<1e-10) {gsl_vector_set(eval, i, 0);}
+ if (gsl_vector_get(eval,i)<1e-10) {
+ gsl_vector_set(eval, i, 0);
+ }
}
time_eigen=(clock()-time_start)/(double(CLOCKS_PER_SEC)*60.0);
@@ -198,12 +182,15 @@ void PRDT::AddBV (gsl_matrix *G, const gsl_vector *u_hat, gsl_vector *y_prdt)
gsl_blas_dgemv (CblasTrans, 1.0, U, u_hat, 0.0, Utu);
for (size_t i=0; isize; i++) {
d=gsl_vector_get(eval, i);
- if (d!=0) {d=gsl_vector_get(Utu, i)/d; gsl_vector_set(Utu, i, d);}
+ if (d!=0) {
+ d=gsl_vector_get(Utu, i)/d;
+ gsl_vector_set(Utu, i, d);
+ }
}
gsl_blas_dgemv (CblasNoTrans, 1.0, U, Utu, 0.0, eval);
gsl_blas_dgemv (CblasNoTrans, 1.0, Gfo, eval, 1.0, y_prdt);
- //free matrices
+ // Free matrices.
gsl_matrix_free(Goo);
gsl_matrix_free(Gfo);
gsl_matrix_free(U);
@@ -215,13 +202,12 @@ void PRDT::AddBV (gsl_matrix *G, const gsl_vector *u_hat, gsl_vector *y_prdt)
return;
}
-
-
-void PRDT::AnalyzeBimbam (gsl_vector *y_prdt)
-{
+void PRDT::AnalyzeBimbam (gsl_vector *y_prdt) {
igzstream infile (file_geno.c_str(), igzstream::in);
-// ifstream infile (file_geno.c_str(), ifstream::in);
- if (!infile) {cout<<"error reading genotype file:"<size==n_miss) {cout<<"snp "<size==n_miss) {
+ cout << "snp " << rs << " has missing genotype for all " <<
+ "individuals and will be ignored." << endl;
+ continue;}
+
x_mean/=(double)(x->size-n_miss);
x_train_mean/=(double)(n_train_nomiss);
@@ -303,17 +305,13 @@ void PRDT::AnalyzeBimbam (gsl_vector *y_prdt)
return;
}
-
-
-
-
-
-
-void PRDT::AnalyzePlink (gsl_vector *y_prdt)
-{
+void PRDT::AnalyzePlink (gsl_vector *y_prdt) {
string file_bed=file_bfile+".bed";
ifstream infile (file_bed.c_str(), ios::binary);
- if (!infile) {cout<<"error reading bed file:"< b;
@@ -324,11 +322,11 @@ void PRDT::AnalyzePlink (gsl_vector *y_prdt)
gsl_vector *x=gsl_vector_alloc (y_prdt->size);
- //calculate n_bit and c, the number of bit for each snp
+ // Calculate n_bit and c, the number of bit for each SNP.
if (indicator_idv.size()%4==0) {n_bit=indicator_idv.size()/4;}
else {n_bit=indicator_idv.size()/4+1; }
- //print the first three majic numbers
+ // Print the first 3 magic numbers.
for (size_t i=0; i<3; ++i) {
infile.read(ch,1);
b=ch[0];
@@ -337,39 +335,71 @@ void PRDT::AnalyzePlink (gsl_vector *y_prdt)
ns_test=0;
for (vector::size_type t=0; tsize==n_miss) {cout<<"snp "<size==n_miss) {
+ cout << "snp " << rs << " has missing genotype for all " <<
+ "individuals and will be ignored."<size-n_miss);
x_train_mean/=(double)(n_train_nomiss);
@@ -407,13 +441,10 @@ void PRDT::AnalyzePlink (gsl_vector *y_prdt)
return;
}
-
-
-
-//predict missing phenotypes using ridge regression
-//Y_hat contains fixed effects
-void PRDT::MvnormPrdt (const gsl_matrix *Y_hat, const gsl_matrix *H, gsl_matrix *Y_full)
-{
+// Predict missing phenotypes using ridge regression.
+// Y_hat contains fixed effects
+void PRDT::MvnormPrdt (const gsl_matrix *Y_hat, const gsl_matrix *H,
+ gsl_matrix *Y_full) {
gsl_vector *y_obs=gsl_vector_alloc (np_obs);
gsl_vector *y_miss=gsl_vector_alloc (np_miss);
gsl_matrix *H_oo=gsl_matrix_alloc (np_obs, np_obs);
@@ -422,20 +453,22 @@ void PRDT::MvnormPrdt (const gsl_matrix *Y_hat, const gsl_matrix *H, gsl_matrix
size_t c_obs1=0, c_obs2=0, c_miss1=0, c_miss2=0;
- //obtain H_oo, H_mo
+ // Obtain H_oo, H_mo.
c_obs1=0; c_miss1=0;
for (vector::size_type i1=0; i1::size_type j1=0; j1::size_type i2=0; i2::size_type i2=0;
+ i2::size_type j2=0; j2::size_type j2=0;
+ j2::size_type i=0; i::size_type i=0;
+ i::size_type j=0; j::size_type i=0; i::size_type i=0;
+ i::size_type j=0; j::size_type i=0; i::size_type j=0; j<2; ++j) {
- if (indicator_pheno[i][j]==1) {
- gsl_vector_set (y_obs, c_obs1, gsl_matrix_get (Y_full, i, j+k*2)-gsl_matrix_get (Y_hat, i, j) );
- c_obs1++;
- } else {
- gsl_vector_set (y_miss, c_miss1, gsl_matrix_get (Y_hat, i, j) );
- c_miss1++;
- }
- }
- }
-
- LUSolve (H_oo, pmt, y_obs, Hiy);
-
- gsl_blas_dgemv (CblasNoTrans, 1.0, H_mo, Hiy, 1.0, y_miss);
-
- //put back predicted y_miss to Y_full
- c_miss1=0;
- for (vector::size_type i=0; i::size_type j=0; j<2; ++j) {
- if (indicator_pheno[i][j]==0) {
- gsl_matrix_set (Y_full, i, j+k*2, gsl_vector_get (y_miss, c_miss1) );
- c_miss1++;
- }
- }
- }
- }
- }
-*/
- //free matrices
+
+ // Free matrices.
gsl_vector_free(y_obs);
gsl_vector_free(y_miss);
gsl_matrix_free(H_oo);
--
cgit v1.2.3