void gcta::blup_snp_dosage() { check_autosome(); if(_mu.empty()) calcu_mu(); int i=0, j=0, k=0, col_num=_varcmp_Py.cols(); // Substract each element by 2p for(i=0; i<_keep.size(); i++){ for(j=0; j<_include.size(); j++) _geno_dose[i][_include[j]]-=_mu[_include[j]]; } // Calcuate A matrix cout<<"Calculating the BLUP solution to SNP effects using imputed dosage scores ... "<<endl; vector<double> var_SNP(_include.size()); // variance of each SNP, 2pq eigenMatrix b_SNP=eigenMatrix::Zero(_include.size(), col_num); // variance of each SNP, 2pq for(j=0; j<_include.size(); j++){ for(i=0; i<_keep.size(); i++) var_SNP[j]+=_geno_dose[i][_include[j]]*_geno_dose[i][_include[j]]; var_SNP[j]/=(double)(_keep.size()-1); if(fabs(var_SNP[j])<1.0e-50) var_SNP[j]=0.0; else var_SNP[j]=1.0/var_SNP[j]; } for(k=0; k<_include.size(); k++){ for(i=0; i<_keep.size(); i++){ for(j=0; j<col_num; j++) b_SNP(k,j)+=_geno_dose[i][_include[k]]*_varcmp_Py(i,j); } for(j=0; j<col_num; j++) b_SNP(k,j)=b_SNP(k,j)*var_SNP[k]/(double)_include.size(); } output_blup_snp(b_SNP); }
void gcta::read_indi_blup(string blup_indi_file) { vector< vector<string> > g_buf; ifstream i_indi_blup(blup_indi_file.c_str()); if(!i_indi_blup) throw("Error: can not open the file ["+blup_indi_file+"] to read."); string str_buf, id_buf; vector<string> id, vs_buf; int i=0, j=0, k=0, col_num=0; while(i_indi_blup){ i_indi_blup>>str_buf; if(i_indi_blup.eof()) break; id_buf=str_buf+":"; i_indi_blup>>str_buf; id_buf+=str_buf; getline(i_indi_blup, str_buf); col_num=StrFunc::split_string(str_buf, vs_buf); if(col_num<1) continue; id.push_back(id_buf); g_buf.push_back(vs_buf); } i_indi_blup.close(); update_id_map_kp(id, _id_map, _keep); map<string, int> uni_id_map; map<string, int>::iterator iter; for(i=0; i<_keep.size(); i++) uni_id_map.insert(pair<string,int>(_fid[_keep[i]]+":"+_pid[_keep[i]], i)); _varcmp_Py.setZero(_keep.size(), col_num/2); for(i=0; i<id.size(); i++){ iter=uni_id_map.find(id[i]); if(iter==uni_id_map.end()) continue; for(j=0, k=0; j<col_num; j+=2, k++) _varcmp_Py(iter->second,k)=atof(g_buf[i][j].c_str()); } cout<<"BLUP solution to the total genetic effects for "<<_keep.size()<<" individuals have been read from ["+blup_indi_file+"]."<<endl; }
// blue estimate of SNP effect void gcta::blup_snp_geno() { check_autosome(); if(_mu.empty()) calcu_mu(); int i=0, j=0, k=0, col_num=_varcmp_Py.cols(); double x=0.0, fcount=0.0; // Calcuate A matrix cout<<"Calculating the BLUP solution to SNP effects ..."<<endl; vector<double> var_SNP(_include.size()); eigenMatrix b_SNP=eigenMatrix::Zero(_include.size(), col_num); // variance of each SNP, 2pq for(j=0; j<_include.size(); j++){ var_SNP[j]=_mu[_include[j]]*(1.0-0.5*_mu[_include[j]]); if(fabs(var_SNP[j])<1.0e-50) var_SNP[j]=0.0; else var_SNP[j]=1.0/var_SNP[j]; } for(k=0; k<_include.size(); k++){ fcount=0.0; for(i=0; i<_keep.size(); i++){ if(!_snp_1[_include[k]][i] || _snp_2[_include[k]][i]){ if(_allele1[_include[k]]==_ref_A[_include[k]]) x=_snp_1[_include[k]][i]+_snp_2[_include[k]][i]; else x=2.0-(_snp_1[_include[k]][i]+_snp_2[_include[k]][i]); x=(x-_mu[_include[k]]); for(j=0; j<col_num; j++) b_SNP(k,j)+=x*_varcmp_Py(i,j); fcount+=1.0; } } for(j=0; j<col_num; j++) b_SNP(k,j)=(b_SNP(k,j)*var_SNP[k]/fcount)*((double)_keep.size()/(double)_include.size()); } output_blup_snp(b_SNP); }