diff options
author | zsloan | 2022-02-02 20:10:00 +0000 |
---|---|---|
committer | zsloan | 2022-02-02 14:15:25 -0600 |
commit | 750bc975650d27e67d1d0b3f6ecaab6582304b44 (patch) | |
tree | c35ef02507b42e89287e0f9761ba46baf3768135 /scripts/rqtl_wrapper.R | |
parent | 9ac9e6a305e5e96d24a67a7469e3f2ea66fc0c72 (diff) | |
download | genenetwork3-750bc975650d27e67d1d0b3f6ecaab6582304b44.tar.gz |
Fix R/qtl covar bug
The rqtl_wrapper script was throwing an error when only a single
categorical covariate was used. This is apparently because "covars[,name]"
throws an error in such a situation. Using just "covars" in such a
situation prevents the error. So I just added an if statement checking
the number of covariates. There might be some better way to deal with
this in R, but this is the best I could come up with.
Diffstat (limited to 'scripts/rqtl_wrapper.R')
-rw-r--r-- | scripts/rqtl_wrapper.R | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/scripts/rqtl_wrapper.R b/scripts/rqtl_wrapper.R index b7a9ae0..13c2684 100644 --- a/scripts/rqtl_wrapper.R +++ b/scripts/rqtl_wrapper.R @@ -202,14 +202,19 @@ if (!is.null(opt$addcovar)) { name <- paste0("T_", covarDescr[x, 1]) # The covar description file doesn't have T_ in trait names (the cross object does) type <- covarDescr[x, 2] if(type == "categorical"){ - if(length(table(covars[,name])) > 2){ # More then 2 levels create the model matrix for the factor - mdata <- data.frame(toExpand = as.factor(covars[, name])) + verbose_print('Binding covars to covars\n') + if (nrow(covarDescr) < 2){ + this_covar = covars + } else { + this_covar = covars[,name] + } + if(length(table(this_covar)) > 2){ # More then 2 levels create the model matrix for the factor + mdata <- data.frame(toExpand = as.factor(this_covar)) options(na.action='na.pass') modelmatrix <- model.matrix(~ toExpand + 0, mdata)[,-1] covars <- cbind(covars, modelmatrix) }else{ # 2 levels? just bind the trait as covar - verbose_print('Binding covars to covars\n') - covars <- cbind(covars, covars[,name]) + covars <- cbind(covars, this_covar) } } } |