Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case of N GWAS = 2 #2

Open
danielcoral opened this issue Apr 2, 2023 · 0 comments
Open

Case of N GWAS = 2 #2

danielcoral opened this issue Apr 2, 2023 · 0 comments

Comments

@danielcoral
Copy link

There seems to be a bug if attempting to run a cross-trait GWAS with only 2 traits. It seems to be in step3, in lines 161-175, when doing:

tresm <- foreach(i = 1:nrow(pairma),
                   .combine = "rbind",
                   .inorder = T) %dopar%
    CorE.ICE(pairma[i, 1], pairma[i, 2], resinfm, maSpltRw, maSpltN, cgwasenv)
  tresm <- signif(tresm, 7)

  corm <- cbind(cgwasenv$.TRAIT_NAME[pairma[,1]],
                cgwasenv$.TRAIT_NAME[pairma[,2]],
                signif(resinfm[pairma[,1], 4]-1, 7),
                signif(resinfm[pairma[,2], 4]-1, 7),
                tresm)

  colnames(corm) <- c("GWAS1", "GWAS2",
                      "T1Eff", "T2Eff",
                      "StatCor", "Psi", "EffCov", "allPi", "T1sEff", "T2sEff", "EffsCov", "sigPi")

It fails at naming the columns because the corm object does not end up with the desired number of columns.

With the following changes the function works:

step3 <- function(cgwasenv) {
  logOutput("========== C-GWAS step 3 : GetPsi ==========\n\n", cgwasenv = cgwasenv)
  logOutput("Estimating background correlation for ",
            nrow(pairma <- t(combn(seq_len(cgwasenv$.TRAIT_NUM), 2))),
            " GWAS pairs ..\n", cgwasenv = cgwasenv)

  minsnpn = 1e5
  maSpltRw = ceiling(cgwasenv$.SNP_N / minsnpn)
  maSpltN = floor(cgwasenv$.SNP_N / maSpltRw) * maSpltRw
  resinfm <- as.matrix(
               read.table(file.path(cgwasenv$.CGWAS_DETAIL_PATH, "SummaryGetI.txt"),
                          header = T)[,-1])

  threadNCur <- min(cgwasenv$.PARAL_NUM, nrow(pairma))
  cl <- makeCluster(threadNCur)
  registerDoParallel(cl)
  # globalVariables(c('i'))
  i <- 1 # assign parallel control variants

  tresm <- foreach(i = 1:nrow(pairma),
                   .combine = "rbind",
                   .inorder = T) %dopar%
    CorE.ICE(pairma[i, 1], pairma[i, 2], resinfm, maSpltRw, maSpltN, cgwasenv)
  tresm <- signif(tresm, 7)
  if(is.null(dim(tresm))){
    tresm <- matrix(tresm, 1)
  }
  corm <- cbind(cgwasenv$.TRAIT_NAME[pairma[,1]],
                cgwasenv$.TRAIT_NAME[pairma[,2]],
                signif(resinfm[pairma[,1], 4]-1, 7),
                signif(resinfm[pairma[,2], 4]-1, 7),
                tresm)
  colnames(corm) <- c("GWAS1", "GWAS2",
                      "T1Eff", "T2Eff",
                      "StatCor", "Psi", "EffCov", "allPi", "T1sEff", "T2sEff", "EffsCov", "sigPi")
  write.table(corm,
              file.path(cgwasenv$.CGWAS_DETAIL_PATH, "BCCorrelationStat.txt"),
              row.names = F, quote = F, sep = "\t")
  write.table(corm[, c(1,2,5,6,8,12), drop = FALSE],
              file.path(cgwasenv$.CGWAS_DETAIL_PATH, "SummaryGetPsi.txt"),
              row.names = F, quote = F, sep = "\t")
  logOutput("Summary of GetPsi written to Details/SummaryGetPsi.txt\n", cgwasenv = cgwasenv)

  stopCluster(cl)

  logOutput("\nC-GWAS step 3 completed\n", cgwasenv = cgwasenv)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant