From 750bc975650d27e67d1d0b3f6ecaab6582304b44 Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 2 Feb 2022 20:10:00 +0000 Subject: 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. --- scripts/rqtl_wrapper.R | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'scripts') 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) } } } -- cgit v1.2.3