/*
Genome-wide Efficient Mixed Model Association (GEMMA)
Copyright (C) 2011 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 .
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "gsl/gsl_vector.h"
#include "gsl/gsl_matrix.h"
#include "gsl/gsl_linalg.h"
#include "gsl/gsl_blas.h"
#include "io.h"
#include "lapack.h" //for functions EigenDecomp
#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)
{
a_mode=cPar.a_mode;
d_pace=cPar.d_pace;
file_bfile=cPar.file_bfile;
file_geno=cPar.file_geno;
file_out=cPar.file_out;
path_out=cPar.path_out;
indicator_pheno=cPar.indicator_pheno;
indicator_cvt=cPar.indicator_cvt;
indicator_idv=cPar.indicator_idv;
snpInfo=cPar.snpInfo;
mapRS2est=cPar.mapRS2est;
time_eigen=0;
n_ph=cPar.n_ph;
np_obs=cPar.np_obs;
np_miss=cPar.np_miss;
ns_total=cPar.ns_total;
ns_test=0;
return;
}
void PRDT::CopyToParam (PARAM &cPar)
{
cPar.ns_test=ns_test;
cPar.time_eigen=time_eigen;
return;
}
void PRDT::WriteFiles (gsl_vector *y_prdt)
{
string file_str;
file_str=path_out+"/"+file_out;
file_str+=".";
file_str+="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);
gsl_matrix *Gfo=gsl_matrix_alloc (ni_total-ni_test, ni_test);
gsl_matrix *U=gsl_matrix_alloc (ni_test, ni_test);
gsl_vector *eval=gsl_vector_alloc (ni_test);
gsl_vector *Utu=gsl_vector_alloc (ni_test);
gsl_vector *w=gsl_vector_alloc (ni_total);
gsl_permutation *pmt=gsl_permutation_alloc (ni_test);
//center matrix G based on indicator_idv
for (size_t i=0; isize; i++) {
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);
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);}
}
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
gsl_matrix_free(Goo);
gsl_matrix_free(Gfo);
gsl_matrix_free(U);
gsl_vector_free(eval);
gsl_vector_free(Utu);
gsl_vector_free(w);
gsl_permutation_free(pmt);
return;
}
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);
gsl_vector *x_miss=gsl_vector_alloc (y_prdt->size);
ns_test=0;
//start reading genotypes and analyze
for (size_t t=0; tsize==n_miss) {cout<<"snp "<size-n_miss);
x_train_mean/=(double)(n_train_nomiss);
for (size_t i=0; isize; ++i) {
geno=gsl_vector_get(x, i);
if (gsl_vector_get (x_miss, i)==0) {
gsl_vector_set(x, i, x_mean-x_train_mean);
} else {
gsl_vector_set(x, i, geno-x_train_mean);
}
}
gsl_vector_scale (x, effect_size);
gsl_vector_add (y_prdt, x);
ns_test++;
}
cout< b;
string rs;
size_t n_bit, n_miss, ci_total, ci_test, n_train_nomiss;
double geno, x_mean, x_train_mean, effect_size;
gsl_vector *x=gsl_vector_alloc (y_prdt->size);
//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
for (size_t i=0; i<3; ++i) {
infile.read(ch,1);
b=ch[0];
}
ns_test=0;
for (vector::size_type t=0; tsize==n_miss) {cout<<"snp "<size-n_miss);
x_train_mean/=(double)(n_train_nomiss);
for (size_t i=0; isize; ++i) {
geno=gsl_vector_get(x, i);
if (geno==-9) {
gsl_vector_set(x, i, x_mean-x_train_mean);
} else {
gsl_vector_set(x, i, geno-x_train_mean);
}
}
gsl_vector_scale (x, effect_size);
gsl_vector_add (y_prdt, x);
ns_test++;
}
cout<::size_type i1=0; i1::size_type j1=0; j1::size_type i2=0; i2::size_type j2=0; j2::size_type i=0; i::size_type j=0; j::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
gsl_vector_free(y_obs);
gsl_vector_free(y_miss);
gsl_matrix_free(H_oo);
gsl_matrix_free(H_mo);
gsl_vector_free(Hiy);
return;
}