Skip to content

Commit

Permalink
v1.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
YinLiLin committed Dec 31, 2024
1 parent f4bcb71 commit 22b8ee2
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 134 deletions.
3 changes: 0 additions & 3 deletions R/MVP.r
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ function(phe, geno, map, K=NULL, nPC.GLM=NULL, nPC.MLM=NULL, nPC.FarmCPU=NULL,
}
}

logging.log("Check if NAs exist in genotype", "\n", verbose = verbose)
if(hasNA(geno@address, mrkbycol = MrkByCol, geno_ind = seqTaxa, threads = ncpus)) stop("NA is not allowed in genotype, use 'MVP.Data.impute' to impute.")

logging.log("Calculate allele frequency...", "\n", verbose = verbose)
marker_freq <- BigRowMean(geno@address, MrkByCol, threads = ncpus, geno_ind = seqTaxa) / 2
map$MAF <- ifelse(marker_freq > 0.5, 1 - marker_freq, marker_freq)
Expand Down
32 changes: 16 additions & 16 deletions src/assoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ SEXP glm_c(const arma::vec &y, const arma::mat &X, const arma::mat & iXX, XPtr<B
#pragma omp parallel for
for(int l = 0; l < cnt; l++){
for(int k = 0; k < n; k++){
Z_buffer(k, l) = genomat[(i_marker + l)][k];
Z_buffer(k, l) = (double)genomat[(i_marker + l)][k];
}
}
}else{
#pragma omp parallel for
for(int k = 0; k < n; k++){
for(int l = 0; l < cnt; l++){
Z_buffer(k, l) = genomat[k][(i_marker + l)];
Z_buffer(k, l) = (double)genomat[k][(i_marker + l)];
}
}
}
Expand All @@ -140,14 +140,14 @@ SEXP glm_c(const arma::vec &y, const arma::mat &X, const arma::mat & iXX, XPtr<B
#pragma omp parallel for
for(int l = 0; l < cnt; l++){
for(int k = 0; k < n; k++){
Z_buffer(k, l) = genomat[_marker_ind[(i_marker + l)]][k];
Z_buffer(k, l) = (double)genomat[_marker_ind[(i_marker + l)]][k];
}
}
}else{
#pragma omp parallel for
for(int k = 0; k < n; k++){
for(int l = 0; l < cnt; l++){
Z_buffer(k, l) = genomat[k][_marker_ind[(i_marker + l)]];
Z_buffer(k, l) = (double)genomat[k][_marker_ind[(i_marker + l)]];
}
}
}
Expand All @@ -158,14 +158,14 @@ SEXP glm_c(const arma::vec &y, const arma::mat &X, const arma::mat & iXX, XPtr<B
#pragma omp parallel for
for(int l = 0; l < cnt; l++){
for(int k = 0; k < n; k++){
Z_buffer(k, l) = genomat[(i_marker + l)][_geno_ind[k]];
Z_buffer(k, l) = (double)genomat[(i_marker + l)][_geno_ind[k]];
}
}
}else{
#pragma omp parallel for
for(int k = 0; k < n; k++){
for(int l = 0; l < cnt; l++){
Z_buffer(k, l) = genomat[_geno_ind[k]][(i_marker + l)];
Z_buffer(k, l) = (double)genomat[_geno_ind[k]][(i_marker + l)];
}
}
}
Expand All @@ -174,14 +174,14 @@ SEXP glm_c(const arma::vec &y, const arma::mat &X, const arma::mat & iXX, XPtr<B
#pragma omp parallel for
for(int l = 0; l < cnt; l++){
for(int k = 0; k < n; k++){
Z_buffer(k, l) = genomat[_marker_ind[(i_marker + l)]][_geno_ind[k]];
Z_buffer(k, l) = (double)genomat[_marker_ind[(i_marker + l)]][_geno_ind[k]];
}
}
}else{
#pragma omp parallel for
for(int k = 0; k < n; k++){
for(int l = 0; l < cnt; l++){
Z_buffer(k, l) = genomat[_geno_ind[k]][_marker_ind[(i_marker + l)]];
Z_buffer(k, l) = (double)genomat[_geno_ind[k]][_marker_ind[(i_marker + l)]];
}
}
}
Expand Down Expand Up @@ -322,14 +322,14 @@ SEXP mlm_c(const arma::vec & y, const arma::mat & X, const arma::mat & U, const
#pragma omp parallel for
for(int l = 0; l < cnt; l++){
for(int k = 0; k < n; k++){
Z_buffer(k, l) = genomat[(i_marker + l)][k];
Z_buffer(k, l) = (double)genomat[(i_marker + l)][k];
}
}
}else{
#pragma omp parallel for
for(int k = 0; k < n; k++){
for(int l = 0; l < cnt; l++){
Z_buffer(k, l) = genomat[k][(i_marker + l)];
Z_buffer(k, l) = (double)genomat[k][(i_marker + l)];
}
}
}
Expand All @@ -338,14 +338,14 @@ SEXP mlm_c(const arma::vec & y, const arma::mat & X, const arma::mat & U, const
#pragma omp parallel for
for(int l = 0; l < cnt; l++){
for(int k = 0; k < n; k++){
Z_buffer(k, l) = genomat[_marker_ind[(i_marker + l)]][k];
Z_buffer(k, l) = (double)genomat[_marker_ind[(i_marker + l)]][k];
}
}
}else{
#pragma omp parallel for
for(int k = 0; k < n; k++){
for(int l = 0; l < cnt; l++){
Z_buffer(k, l) = genomat[k][_marker_ind[(i_marker + l)]];
Z_buffer(k, l) = (double)genomat[k][_marker_ind[(i_marker + l)]];
}
}
}
Expand All @@ -356,14 +356,14 @@ SEXP mlm_c(const arma::vec & y, const arma::mat & X, const arma::mat & U, const
#pragma omp parallel for
for(int l = 0; l < cnt; l++){
for(int k = 0; k < n; k++){
Z_buffer(k, l) = genomat[(i_marker + l)][_geno_ind[k]];
Z_buffer(k, l) = (double)genomat[(i_marker + l)][_geno_ind[k]];
}
}
}else{
#pragma omp parallel for
for(int k = 0; k < n; k++){
for(int l = 0; l < cnt; l++){
Z_buffer(k, l) = genomat[_geno_ind[k]][(i_marker + l)];
Z_buffer(k, l) = (double)genomat[_geno_ind[k]][(i_marker + l)];
}
}
}
Expand All @@ -372,14 +372,14 @@ SEXP mlm_c(const arma::vec & y, const arma::mat & X, const arma::mat & U, const
#pragma omp parallel for
for(int l = 0; l < cnt; l++){
for(int k = 0; k < n; k++){
Z_buffer(k, l) = genomat[_marker_ind[(i_marker + l)]][_geno_ind[k]];
Z_buffer(k, l) = (double)genomat[_marker_ind[(i_marker + l)]][_geno_ind[k]];
}
}
}else{
#pragma omp parallel for
for(int k = 0; k < n; k++){
for(int l = 0; l < cnt; l++){
Z_buffer(k, l) = genomat[_geno_ind[k]][_marker_ind[(i_marker + l)]];
Z_buffer(k, l) = (double)genomat[_geno_ind[k]][_marker_ind[(i_marker + l)]];
}
}
}
Expand Down
32 changes: 19 additions & 13 deletions src/impute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void impute_marker(SEXP pBigMat, bool mrkbycol = true, int threads=0, bool verbo
}

template <typename T>
bool hasNA(XPtr<BigMatrix> pMat, double NA_C, bool mrkbycol = true, const Nullable<arma::uvec> geno_ind = R_NilValue, const Nullable<arma::uvec> marker_ind = R_NilValue, const int threads = 1) {
bool hasNA(XPtr<BigMatrix> pMat, bool mrkbycol = true, const Nullable<arma::uvec> geno_ind = R_NilValue, const Nullable<arma::uvec> marker_ind = R_NilValue, const int threads = 1) {

omp_setup(threads);

Expand All @@ -124,7 +124,8 @@ bool hasNA(XPtr<BigMatrix> pMat, double NA_C, bool mrkbycol = true, const Nullab
for (int j = 0; j < m; j++) {
if(HasNA) continue;
for (int i = 0; i < n; i++) {
if (mat[_marker_ind[j]][_geno_ind[i]] == NA_C) {
// if (mat[_marker_ind[j]][_geno_ind[i]] == NA_C) {
if (isna(mat[_marker_ind[j]][_geno_ind[i]])) {
HasNA = true;
}
}
Expand All @@ -134,7 +135,8 @@ bool hasNA(XPtr<BigMatrix> pMat, double NA_C, bool mrkbycol = true, const Nullab
for (int j = 0; j < n; j++) {
if(HasNA) continue;
for (int i = 0; i < m; i++) {
if (mat[_geno_ind[j]][_marker_ind[i]] == NA_C) {
// if (mat[_geno_ind[j]][_marker_ind[i]] == NA_C) {
if (isna(mat[_geno_ind[j]][_marker_ind[i]])) {
HasNA = true;
}
}
Expand All @@ -146,7 +148,8 @@ bool hasNA(XPtr<BigMatrix> pMat, double NA_C, bool mrkbycol = true, const Nullab
for (int j = 0; j < pMat->ncol(); j++) {
if(HasNA) continue;
for (int i = 0; i < n; i++) {
if (mat[j][_geno_ind[i]] == NA_C) {
// if (mat[j][_geno_ind[i]] == NA_C) {
if (isna(mat[j][_geno_ind[i]])) {
HasNA = true;
}
}
Expand All @@ -156,7 +159,8 @@ bool hasNA(XPtr<BigMatrix> pMat, double NA_C, bool mrkbycol = true, const Nullab
for (int j = 0; j < n; j++) {
if(HasNA) continue;
for (int i = 0; i < pMat->nrow(); i++) {
if (mat[_geno_ind[j]][i] == NA_C) {
// if (mat[_geno_ind[j]][i] == NA_C) {
if (isna(mat[_geno_ind[j]][i])) {
HasNA = true;
}
}
Expand All @@ -172,7 +176,8 @@ bool hasNA(XPtr<BigMatrix> pMat, double NA_C, bool mrkbycol = true, const Nullab
for (int j = 0; j < m; j++) {
if(HasNA) continue;
for (int i = 0; i < pMat->nrow(); i++) {
if (mat[_marker_ind[j]][i] == NA_C) {
// if (mat[_marker_ind[j]][i] == NA_C) {
if (isna(mat[_marker_ind[j]][i])) {
HasNA = true;
}
}
Expand All @@ -182,7 +187,8 @@ bool hasNA(XPtr<BigMatrix> pMat, double NA_C, bool mrkbycol = true, const Nullab
for (int j = 0; j < pMat->ncol(); j++) {
if(HasNA) continue;
for (int i = 0; i < m; i++) {
if (mat[j][_marker_ind[i]] == NA_C) {
// if (mat[j][_marker_ind[i]] == NA_C) {
if (isna(mat[j][_marker_ind[i]])) {
HasNA = true;
}
}
Expand All @@ -193,14 +199,14 @@ bool hasNA(XPtr<BigMatrix> pMat, double NA_C, bool mrkbycol = true, const Nullab
for (int j = 0; j < pMat->ncol(); j++) {
if(HasNA) continue;
for (int i = 0; i < pMat->nrow(); i++) {
if (mat[j][i] == NA_C) {
// if (mat[j][i] == NA_C) {
if (isna(mat[j][i])) {
HasNA = true;
}
}
}
}
}

return HasNA;
}

Expand All @@ -210,13 +216,13 @@ bool hasNA(SEXP pBigMat, bool mrkbycol = true, const Nullable<arma::uvec> geno_i

switch(xpMat->matrix_type()) {
case 1:
return hasNA<char>(xpMat, NA_CHAR, mrkbycol, geno_ind, marker_ind, threads);
return hasNA<char>(xpMat, mrkbycol, geno_ind, marker_ind, threads);
case 2:
return hasNA<short>(xpMat, NA_SHORT, mrkbycol, geno_ind, marker_ind, threads);
return hasNA<short>(xpMat, mrkbycol, geno_ind, marker_ind, threads);
case 4:
return hasNA<int>(xpMat, NA_INTEGER, mrkbycol, geno_ind, marker_ind, threads);
return hasNA<int>(xpMat, mrkbycol, geno_ind, marker_ind, threads);
case 8:
return hasNA<double>(xpMat, NA_REAL, mrkbycol, geno_ind, marker_ind, threads);
return hasNA<double>(xpMat, mrkbycol, geno_ind, marker_ind, threads);
default:
throw Rcpp::exception("unknown type detected for big.matrix object!");
}
Expand Down
Loading

0 comments on commit 22b8ee2

Please sign in to comment.