From 992ecdf174420fbfde0370cb05722f2ffcf2a5ea Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Fri, 12 Oct 2018 15:21:17 -0400 Subject: [PATCH 01/41] Initial draft of effect size from GLM methods --- R/effectsize.R | 137 ++++++++++++++++++++++++++++++++++++++++ man/vertexEffectSize.Rd | 36 +++++++++++ 2 files changed, 173 insertions(+) create mode 100644 R/effectsize.R create mode 100644 man/vertexEffectSize.Rd diff --git a/R/effectsize.R b/R/effectsize.R new file mode 100644 index 00000000..eef1ff2f --- /dev/null +++ b/R/effectsize.R @@ -0,0 +1,137 @@ +#' Effect Sizes +#' +#' Takes the output of a minc modelling function and computes the unbiased hedges g* +#' and variance of hedges g* +#' @param buffer The results of a vertex/anat/mincLm run +#' @param columns A vector of column names. By default the threshold will +#' be computed for all factor columns. +#' @details This code implements the methods from Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x +#' for computing effect size of group comparisons from a GLM +#' @return A matrix with columns of hedgesg and hedgesg_var for each factor predictor in the GLM +#' or for each column supplied. +#' @examples +#' \dontrun{ +#' getRMINCTestData() +#' # read the text file describing the dataset +#' gf <- read.csv("/tmp/rminctestdata/test_data_set.csv") +#' # run a linear model relating the data in all voxels to Genotype +#' vs <- mincLm(jacobians_fixed_2 ~ Sex, gf) +#' effectsize <- mincEffectSize(vs) +#' } +#' @export +vertexEffectSize <- function(buffer, columns = NULL) +{ + #Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x + #Unbiased corrector function J from https://en.wikipedia.org/wiki/Effect_size#Hedges'_g + #Watch out for exploding gamma function + J <- function(a) { + out <- tryCatch({ + return (gamma(a / 2) / (sqrt(a / 2) * gamma((a - 1) / 2))) + }, + error = function(cond) { + return(1) + }, + warning = function(cond) { + return(1) + }) + return(out) + } + # g_biased = t ( n1 + n2 ) / sqrt(n1*n2)*sqrt(df) + # g_unbiased = g_biased * J(n1 + n2 - 2) + # g_variance_unbiased = (n1 + n2) / (n1*n2) + g_unbiased**2 / (2 * (n1 + n2 - 2)) + # N = n1+n2 + # NN = n1*n2 + + originalMincAttrs <- mincAttributes(buffer) + stattype <- originalMincAttrs$`stat-type` + # Remove coefficients from buffer + if (!is.null(stattype)) { + for (nStat in 1:length(stattype)) { + if (stattype[nStat] == 'beta' || + stattype[nStat] == 'R-squared' || + stattype[nStat] == "logLik" || stattype[nStat] == "F") { + if (!exists('indicesToRemove')) { + indicesToRemove = nStat + } + else { + indicesToRemove = c(indicesToRemove, nStat) + } + } + } + if (exists('indicesToRemove')) { + updatedAttrs <- originalMincAttrs + updatedAttrs$`stat-type` <- + updatedAttrs$`stat-type`[-indicesToRemove] + updatedAttrs$dimnames[[2]] <- + updatedAttrs$dimnames[[2]][-indicesToRemove] + + buffer <- buffer[, -indicesToRemove] + buffer <- setMincAttributes(buffer, updatedAttrs) + } + } + + if (is.null(columns)) { + model_call <- attr(buffer, "call") + model_call[[1]] <- quote(model.matrix) + names(model_call)[names(model_call) == "formula"] <- "" + mod_mat <- eval(model_call) + conts <- attr(mod_mat, "contrasts") + if (is.null(conts)) + stop("No categorical variables in model, cannot compute g statistics") + + cat_vars <- + names(conts)[vapply(conts, function(x) + all(x == "contr.treatment"), logical(1))] + columns <- lapply(updatedAttrs$dimnames, function(x) + grep(paste(cat_vars, collapse = "|"), x, value = TRUE))[[2]] + columns <- gsub("tvalue-", "", columns, fixed = TRUE) + } + + n.cols <- length(columns) + n.row <- 0 + if (is.matrix(buffer)) { + n.row <- nrow(buffer) + } + else { + n.row <- length(buffer) + } + output <- matrix(1, nrow = n.row, ncol = 2 * n.cols) + colnames(output) <- + c(paste0("hedgesg-", columns), + paste0("hedgesg_var-", columns)) + for (column in columns) { + n1 <- sum(updatedAttrs$model[, column]) + N <- length(updatedAttrs$model[, column]) + n2 <- N - n1 + NN <- n1 * n2 + df <- updatedAttrs$df[[1]][2] + output[, paste0("hedgesg-", column)] <- + buffer[, paste0("tvalue-", column)] * N / (sqrt(NN) * sqrt(df)) * J(N - + 2) + output[, paste0("hedgesg_var-", column)] <- + (N) / (NN) + output[, paste0("hedgesg-", column)] ** 2 / (2 * (N - 2)) + } + rownames(output) <- rownames(buffer) + attr(output, "likeVolume") <- attr(buffer, "likeVolume") + + # run the garbage collector... + gcout <- gc() + + return(output) +} + +#' @describeIn vertexEffectSize +#' @export +mincEffectSize <- function(buffer, columns = NULL) { + eff_call <- match.call() + eff_call[[1]] <- quote(vertexEffectSize) + eval(eff_call) +} + +#' @describeIn vertexEffectSize +#' @export +anatEffectSize <- function(buffer, columns = NULL) { + eff_call <- match.call() + eff_call[[1]] <- quote(vertexEffectSize) + eval(eff_call) +} \ No newline at end of file diff --git a/man/vertexEffectSize.Rd b/man/vertexEffectSize.Rd new file mode 100644 index 00000000..921b4eed --- /dev/null +++ b/man/vertexEffectSize.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/effectsize.R +\name{vertexEffectSize} +\alias{vertexEffectSize} +\title{False Discovery Rates} +\usage{ +vertexEffectSize(buffer, columns = NULL) +} +\arguments{ +\item{buffer}{The results of a vertex/anat/mincLm run} + +\item{columns}{A vector of column names. By default the threshold will +be computed for all factor columns.} +} +\value{ +A matrix with columns of hedgesg and hedgesg_var for each factor predictor in the GLM +or for each column supplied. +} +\description{ +Takes the output of a minc modelling function and computes the unbiased hedges g* +and variance of hedges g* +} +\details{ +This code implements the methods from Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x +for computing effect size of group comparisons from a GLM +} +\examples{ +\dontrun{ +getRMINCTestData() +# read the text file describing the dataset +gf <- read.csv("/tmp/rminctestdata/test_data_set.csv") +# run a linear model relating the data in all voxels to Genotype +vs <- mincLm(jacobians_fixed_2 ~ Sex, gf) +effectsize <- mincEffectSize(vs) +} +} From 66ca7715f9ad2ba5492f6205ba80eacd5692c479 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Fri, 12 Oct 2018 16:12:15 -0400 Subject: [PATCH 02/41] Generate documentation for effect size --- NAMESPACE | 3 +++ R/effectsize.R | 4 ++-- man/vertexEffectSize.Rd | 17 +++++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index af4f9e5a..271266e1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -66,6 +66,7 @@ export(anatAnova) export(anatApply) export(anatCombineStructures) export(anatCreateVolume) +export(anatEffectSize) export(anatFDR) export(anatGetAll) export(anatGetAll_old) @@ -151,6 +152,7 @@ export(mincConvertVoxelToWorld) export(mincConvertWorldMatrix) export(mincConvertWorldToVoxel) export(mincCorrelation) +export(mincEffectSize) export(mincFDR) export(mincFDRMask) export(mincFindPeaks) @@ -202,6 +204,7 @@ export(thresholds) export(verboseRun) export(vertexAnova) export(vertexApply) +export(vertexEffectSize) export(vertexFDR) export(vertexFindPeaks) export(vertexLm) diff --git a/R/effectsize.R b/R/effectsize.R index eef1ff2f..73ea2d3e 100644 --- a/R/effectsize.R +++ b/R/effectsize.R @@ -120,7 +120,7 @@ vertexEffectSize <- function(buffer, columns = NULL) return(output) } -#' @describeIn vertexEffectSize +#' @describeIn vertexEffectSize mincEffectSize #' @export mincEffectSize <- function(buffer, columns = NULL) { eff_call <- match.call() @@ -128,7 +128,7 @@ mincEffectSize <- function(buffer, columns = NULL) { eval(eff_call) } -#' @describeIn vertexEffectSize +#' @describeIn vertexEffectSize anatEffectSize #' @export anatEffectSize <- function(buffer, columns = NULL) { eff_call <- match.call() diff --git a/man/vertexEffectSize.Rd b/man/vertexEffectSize.Rd index 921b4eed..b0928e86 100644 --- a/man/vertexEffectSize.Rd +++ b/man/vertexEffectSize.Rd @@ -2,9 +2,15 @@ % Please edit documentation in R/effectsize.R \name{vertexEffectSize} \alias{vertexEffectSize} -\title{False Discovery Rates} +\alias{mincEffectSize} +\alias{anatEffectSize} +\title{Effect Sizes} \usage{ vertexEffectSize(buffer, columns = NULL) + +mincEffectSize(buffer, columns = NULL) + +anatEffectSize(buffer, columns = NULL) } \arguments{ \item{buffer}{The results of a vertex/anat/mincLm run} @@ -24,9 +30,16 @@ and variance of hedges g* This code implements the methods from Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x for computing effect size of group comparisons from a GLM } +\section{Functions}{ +\itemize{ +\item \code{mincEffectSize}: mincEffectSize + +\item \code{anatEffectSize}: anatEffectSize +}} + \examples{ \dontrun{ -getRMINCTestData() +getRMINCTestData() # read the text file describing the dataset gf <- read.csv("/tmp/rminctestdata/test_data_set.csv") # run a linear model relating the data in all voxels to Genotype From f4179ff202f57c42af1767ffb079ecbdc0984711 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Mon, 15 Oct 2018 13:18:35 -0400 Subject: [PATCH 03/41] Add proper error checking to effectsize --- R/effectsize.R | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/R/effectsize.R b/R/effectsize.R index 73ea2d3e..9010334a 100644 --- a/R/effectsize.R +++ b/R/effectsize.R @@ -70,15 +70,17 @@ vertexEffectSize <- function(buffer, columns = NULL) } } + model_call <- attr(buffer, "call") + model_call[[1]] <- quote(model.matrix) + names(model_call)[names(model_call) == "formula"] <- "" + mod_mat <- eval(model_call) + conts <- attr(mod_mat, "contrasts") + if (is.null(conts)) + stop("No categorical variables in model, cannot compute g* statistics") + if (!all(sapply(columns, function(x) any(grepl(x, updatedAttrs$dimnames[[2]]))))) + stop("Columns not found in model") + if (is.null(columns)) { - model_call <- attr(buffer, "call") - model_call[[1]] <- quote(model.matrix) - names(model_call)[names(model_call) == "formula"] <- "" - mod_mat <- eval(model_call) - conts <- attr(mod_mat, "contrasts") - if (is.null(conts)) - stop("No categorical variables in model, cannot compute g statistics") - cat_vars <- names(conts)[vapply(conts, function(x) all(x == "contr.treatment"), logical(1))] From db3662cf14f0f2f740f9fdf594b7cbae1155e401 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Mon, 15 Oct 2018 13:19:03 -0400 Subject: [PATCH 04/41] Update documentation for effectsize --- R/effectsize.R | 13 +++++++------ man/vertexEffectSize.Rd | 10 +++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/R/effectsize.R b/R/effectsize.R index 9010334a..a49111bf 100644 --- a/R/effectsize.R +++ b/R/effectsize.R @@ -1,13 +1,13 @@ #' Effect Sizes #' -#' Takes the output of a minc modelling function and computes the unbiased hedges g* -#' and variance of hedges g* +#' Takes the output of a minc modelling function and computes the unbiased +#' hedges g* and variance of hedges g* #' @param buffer The results of a vertex/anat/mincLm run -#' @param columns A vector of column names. By default the threshold will +#' @param columns A vector of factor predictor names. By default the threshold will #' be computed for all factor columns. #' @details This code implements the methods from Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x -#' for computing effect size of group comparisons from a GLM -#' @return A matrix with columns of hedgesg and hedgesg_var for each factor predictor in the GLM +#' for computing effect size of group comparisons from a GLM. +#' @return A matrix with columns of hedgesg- and hedgesg_var- for each factor predictor in the GLM #' or for each column supplied. #' @examples #' \dontrun{ @@ -22,7 +22,8 @@ vertexEffectSize <- function(buffer, columns = NULL) { #Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x - #Unbiased corrector function J from https://en.wikipedia.org/wiki/Effect_size#Hedges'_g + #Original unbiased corrector from paper replaced with + #unbiased corrector function J from https://en.wikipedia.org/wiki/Effect_size#Hedges'_g #Watch out for exploding gamma function J <- function(a) { out <- tryCatch({ diff --git a/man/vertexEffectSize.Rd b/man/vertexEffectSize.Rd index b0928e86..b5a63e1f 100644 --- a/man/vertexEffectSize.Rd +++ b/man/vertexEffectSize.Rd @@ -15,20 +15,20 @@ anatEffectSize(buffer, columns = NULL) \arguments{ \item{buffer}{The results of a vertex/anat/mincLm run} -\item{columns}{A vector of column names. By default the threshold will +\item{columns}{A vector of factor predictor names. By default the threshold will be computed for all factor columns.} } \value{ -A matrix with columns of hedgesg and hedgesg_var for each factor predictor in the GLM +A matrix with columns of hedgesg- and hedgesg_var- for each factor predictor in the GLM or for each column supplied. } \description{ -Takes the output of a minc modelling function and computes the unbiased hedges g* -and variance of hedges g* +Takes the output of a minc modelling function and computes the unbiased +hedges g* and variance of hedges g* } \details{ This code implements the methods from Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x -for computing effect size of group comparisons from a GLM +for computing effect size of group comparisons from a GLM. } \section{Functions}{ \itemize{ From 212b267711cdeeefb0d162cf3c96fe5e748f3b02 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Tue, 16 Oct 2018 11:35:37 -0400 Subject: [PATCH 05/41] Make mincFDR.mincSingleDim use fdr method by default, fixes #189 --- R/minc_FDR.R | 3 ++- man/mincFDR.Rd | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/R/minc_FDR.R b/R/minc_FDR.R index 34a5d87c..c2094bab 100644 --- a/R/minc_FDR.R +++ b/R/minc_FDR.R @@ -58,10 +58,11 @@ mincFDR <- function(buffer, ...) { } #' @describeIn mincFDR mincSingleDim #' @export -mincFDR.mincSingleDim <- function(buffer, df, mask = NULL, method = "qvalue", ...) { +mincFDR.mincSingleDim <- function(buffer, df, mask = NULL, method = "fdr", ...) { if (is.null(df)) { stop("Error: need to specify the degrees of freedom") } + warning('default method has changed, specify method = "qvalue" to retain old implementation') # if (length(df) == 1) { # df <- c(1,df) # } diff --git a/man/mincFDR.Rd b/man/mincFDR.Rd index eb709d33..4114bbee 100644 --- a/man/mincFDR.Rd +++ b/man/mincFDR.Rd @@ -10,7 +10,7 @@ \usage{ mincFDR(buffer, ...) -\method{mincFDR}{mincSingleDim}(buffer, df, mask = NULL, method = "qvalue", +\method{mincFDR}{mincSingleDim}(buffer, df, mask = NULL, method = "fdr", ...) \method{mincFDR}{mincLogLikRatio}(buffer, mask = NULL, ...) From 58dbddd961d519c86000ce0383ce51553a5a42b6 Mon Sep 17 00:00:00 2001 From: Chris Hammill Date: Tue, 23 Oct 2018 13:54:12 -0400 Subject: [PATCH 06/41] Convert warning to message Co-Authored-By: gdevenyi --- R/minc_FDR.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/minc_FDR.R b/R/minc_FDR.R index c2094bab..151a4a6d 100644 --- a/R/minc_FDR.R +++ b/R/minc_FDR.R @@ -62,7 +62,7 @@ mincFDR.mincSingleDim <- function(buffer, df, mask = NULL, method = "fdr", ...) if (is.null(df)) { stop("Error: need to specify the degrees of freedom") } - warning('default method has changed, specify method = "qvalue" to retain old implementation') + message('default method has changed, specify method = "qvalue" to retain old implementation') # if (length(df) == 1) { # df <- c(1,df) # } From 9b9fef13bd8a63f15206f91282168ad805e69639 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Mon, 29 Oct 2018 10:52:58 -0400 Subject: [PATCH 07/41] Fix detection of reference group for mutilevel factors, adjust docs --- R/effectsize.R | 70 ++++++++++++++++++++++++++--------------- man/vertexEffectSize.Rd | 8 ++--- 2 files changed, 49 insertions(+), 29 deletions(-) diff --git a/R/effectsize.R b/R/effectsize.R index a49111bf..7a949145 100644 --- a/R/effectsize.R +++ b/R/effectsize.R @@ -3,7 +3,7 @@ #' Takes the output of a minc modelling function and computes the unbiased #' hedges g* and variance of hedges g* #' @param buffer The results of a vertex/anat/mincLm run -#' @param columns A vector of factor predictor names. By default the threshold will +#' @param predictors A vector of factor predictor names. By default the effect size #' be computed for all factor columns. #' @details This code implements the methods from Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x #' for computing effect size of group comparisons from a GLM. @@ -19,7 +19,7 @@ #' effectsize <- mincEffectSize(vs) #' } #' @export -vertexEffectSize <- function(buffer, columns = NULL) +vertexEffectSize <- function(buffer, predictors = NULL) { #Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x #Original unbiased corrector from paper replaced with @@ -40,9 +40,11 @@ vertexEffectSize <- function(buffer, columns = NULL) # g_biased = t ( n1 + n2 ) / sqrt(n1*n2)*sqrt(df) # g_unbiased = g_biased * J(n1 + n2 - 2) # g_variance_unbiased = (n1 + n2) / (n1*n2) + g_unbiased**2 / (2 * (n1 + n2 - 2)) + # n1 study group + # n2 reference group # N = n1+n2 # NN = n1*n2 - + originalMincAttrs <- mincAttributes(buffer) stattype <- originalMincAttrs$`stat-type` # Remove coefficients from buffer @@ -65,32 +67,50 @@ vertexEffectSize <- function(buffer, columns = NULL) updatedAttrs$`stat-type`[-indicesToRemove] updatedAttrs$dimnames[[2]] <- updatedAttrs$dimnames[[2]][-indicesToRemove] - + buffer <- buffer[, -indicesToRemove] buffer <- setMincAttributes(buffer, updatedAttrs) } } - + model_call <- attr(buffer, "call") model_call[[1]] <- quote(model.matrix) names(model_call)[names(model_call) == "formula"] <- "" mod_mat <- eval(model_call) conts <- attr(mod_mat, "contrasts") + cat_vars <- + names(conts)[vapply(conts, function(x) + all(x == "contr.treatment"), logical(1))] if (is.null(conts)) stop("No categorical variables in model, cannot compute g* statistics") - if (!all(sapply(columns, function(x) any(grepl(x, updatedAttrs$dimnames[[2]]))))) - stop("Columns not found in model") + if (!all(sapply(predictors, function(x) + any(grepl( + x, updatedAttrs$dimnames[[2]] + ))))) + stop("Supplied predictors not found in model") + if (!all(conts == "contr.treatment")) + stop( + "Non-treatment factors present in model, effect size is not meaningful + for this configuration" + ) - if (is.null(columns)) { - cat_vars <- - names(conts)[vapply(conts, function(x) - all(x == "contr.treatment"), logical(1))] - columns <- lapply(updatedAttrs$dimnames, function(x) + if (is.null(predictors)) { + predictors <- lapply(updatedAttrs$dimnames, function(x) grep(paste(cat_vars, collapse = "|"), x, value = TRUE))[[2]] - columns <- gsub("tvalue-", "", columns, fixed = TRUE) + predictors <- gsub("tvalue-", "", predictors, fixed = TRUE) + } + + referencegroupsize <- + matrix(1, nrow = 1, ncol = length(predictors)) + colnames(referencegroupsize) <- predictors + + for (var in cat_vars) { + referencegroupsize[, grep(var, predictors, value = TRUE)] <- + NROW(updatedAttrs$model[, grep(var, colnames(updatedAttrs$model))]) - + sum(updatedAttrs$model[, grep(var, colnames(updatedAttrs$model))]) } - - n.cols <- length(columns) + + n.cols <- length(predictors) n.row <- 0 if (is.matrix(buffer)) { n.row <- nrow(buffer) @@ -100,12 +120,12 @@ vertexEffectSize <- function(buffer, columns = NULL) } output <- matrix(1, nrow = n.row, ncol = 2 * n.cols) colnames(output) <- - c(paste0("hedgesg-", columns), - paste0("hedgesg_var-", columns)) - for (column in columns) { + c(paste0("hedgesg-", predictors), + paste0("hedgesg_var-", predictors)) + for (column in predictors) { n1 <- sum(updatedAttrs$model[, column]) - N <- length(updatedAttrs$model[, column]) - n2 <- N - n1 + n2 <- referencegroupsize[, column] + N <- n1 + n2 NN <- n1 * n2 df <- updatedAttrs$df[[1]][2] output[, paste0("hedgesg-", column)] <- @@ -116,16 +136,16 @@ vertexEffectSize <- function(buffer, columns = NULL) } rownames(output) <- rownames(buffer) attr(output, "likeVolume") <- attr(buffer, "likeVolume") - + # run the garbage collector... gcout <- gc() - + return(output) } #' @describeIn vertexEffectSize mincEffectSize #' @export -mincEffectSize <- function(buffer, columns = NULL) { +mincEffectSize <- function(buffer, predictors = NULL) { eff_call <- match.call() eff_call[[1]] <- quote(vertexEffectSize) eval(eff_call) @@ -133,8 +153,8 @@ mincEffectSize <- function(buffer, columns = NULL) { #' @describeIn vertexEffectSize anatEffectSize #' @export -anatEffectSize <- function(buffer, columns = NULL) { +anatEffectSize <- function(buffer, predictors = NULL) { eff_call <- match.call() eff_call[[1]] <- quote(vertexEffectSize) eval(eff_call) -} \ No newline at end of file +} diff --git a/man/vertexEffectSize.Rd b/man/vertexEffectSize.Rd index b5a63e1f..68b171c2 100644 --- a/man/vertexEffectSize.Rd +++ b/man/vertexEffectSize.Rd @@ -6,16 +6,16 @@ \alias{anatEffectSize} \title{Effect Sizes} \usage{ -vertexEffectSize(buffer, columns = NULL) +vertexEffectSize(buffer, predictors = NULL) -mincEffectSize(buffer, columns = NULL) +mincEffectSize(buffer, predictors = NULL) -anatEffectSize(buffer, columns = NULL) +anatEffectSize(buffer, predictors = NULL) } \arguments{ \item{buffer}{The results of a vertex/anat/mincLm run} -\item{columns}{A vector of factor predictor names. By default the threshold will +\item{predictors}{A vector of factor predictor names. By default the effect size be computed for all factor columns.} } \value{ From 91f2dd06115f51a873310f0baeec07f8b8e2bd0e Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Mon, 29 Oct 2018 13:12:27 -0400 Subject: [PATCH 08/41] Update effectsize documentation details --- R/effectsize.R | 2 +- man/vertexEffectSize.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/effectsize.R b/R/effectsize.R index 7a949145..e67c5b6a 100644 --- a/R/effectsize.R +++ b/R/effectsize.R @@ -4,7 +4,7 @@ #' hedges g* and variance of hedges g* #' @param buffer The results of a vertex/anat/mincLm run #' @param predictors A vector of factor predictor names. By default the effect size -#' be computed for all factor columns. +#' be computed for all treatment-coded factor columns. #' @details This code implements the methods from Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x #' for computing effect size of group comparisons from a GLM. #' @return A matrix with columns of hedgesg- and hedgesg_var- for each factor predictor in the GLM diff --git a/man/vertexEffectSize.Rd b/man/vertexEffectSize.Rd index 68b171c2..cd345e16 100644 --- a/man/vertexEffectSize.Rd +++ b/man/vertexEffectSize.Rd @@ -16,7 +16,7 @@ anatEffectSize(buffer, predictors = NULL) \item{buffer}{The results of a vertex/anat/mincLm run} \item{predictors}{A vector of factor predictor names. By default the effect size -be computed for all factor columns.} +be computed for all treatment-coded factor columns.} } \value{ A matrix with columns of hedgesg- and hedgesg_var- for each factor predictor in the GLM From c88df8aff69c126d04bdb28dcc1061b0c0fb0d21 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Mon, 29 Oct 2018 13:12:46 -0400 Subject: [PATCH 09/41] Simplify effectsize predictor grep --- R/effectsize.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/effectsize.R b/R/effectsize.R index e67c5b6a..92dd0570 100644 --- a/R/effectsize.R +++ b/R/effectsize.R @@ -95,8 +95,7 @@ vertexEffectSize <- function(buffer, predictors = NULL) ) if (is.null(predictors)) { - predictors <- lapply(updatedAttrs$dimnames, function(x) - grep(paste(cat_vars, collapse = "|"), x, value = TRUE))[[2]] + predictors <- grep(paste(cat_vars, collapse = "|"), updatedAttrs$dimnames[[2]], value = TRUE) predictors <- gsub("tvalue-", "", predictors, fixed = TRUE) } From 0d3c4b57ac03927b4a888798f39828fdf9f5a355 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Mon, 29 Oct 2018 13:19:40 -0400 Subject: [PATCH 10/41] Cleanup check for all predictors in effectsize passed model --- R/effectsize.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/R/effectsize.R b/R/effectsize.R index 92dd0570..c79e88f7 100644 --- a/R/effectsize.R +++ b/R/effectsize.R @@ -81,13 +81,14 @@ vertexEffectSize <- function(buffer, predictors = NULL) cat_vars <- names(conts)[vapply(conts, function(x) all(x == "contr.treatment"), logical(1))] + if (is.null(conts)) stop("No categorical variables in model, cannot compute g* statistics") - if (!all(sapply(predictors, function(x) - any(grepl( - x, updatedAttrs$dimnames[[2]] - ))))) + + if (!is.null(predictors) && + !all(predictors %in% colnames(updatedAttrs$model))) stop("Supplied predictors not found in model") + if (!all(conts == "contr.treatment")) stop( "Non-treatment factors present in model, effect size is not meaningful From 065bc525bfb846f15a4c3ea8d35db47ce952b0b5 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Mon, 29 Oct 2018 13:56:40 -0400 Subject: [PATCH 11/41] Ignore interaction terms and reject them from predictors input --- R/effectsize.R | 14 +++++++++++--- man/vertexEffectSize.Rd | 4 ++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/R/effectsize.R b/R/effectsize.R index c79e88f7..b1b6c91b 100644 --- a/R/effectsize.R +++ b/R/effectsize.R @@ -7,6 +7,10 @@ #' be computed for all treatment-coded factor columns. #' @details This code implements the methods from Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x #' for computing effect size of group comparisons from a GLM. +#' +#' For now, interactions are explicitly excluded from being predictors. To get +#' effect size for interactions, use the interaction() function to create a new +#' treatment coded factor to use as a predictor. #' @return A matrix with columns of hedgesg- and hedgesg_var- for each factor predictor in the GLM #' or for each column supplied. #' @examples @@ -94,9 +98,13 @@ vertexEffectSize <- function(buffer, predictors = NULL) "Non-treatment factors present in model, effect size is not meaningful for this configuration" ) + + if (!is.null(predictors) && any(grepl(":", predictors))) + stop("Interactions in predictors are not currently supported, + generate treatment contrasts using interaction()") if (is.null(predictors)) { - predictors <- grep(paste(cat_vars, collapse = "|"), updatedAttrs$dimnames[[2]], value = TRUE) + predictors <- grep(":", grep(paste(cat_vars, collapse = "|"), updatedAttrs$dimnames[[2]], value = TRUE), invert = TRUE, value = TRUE) predictors <- gsub("tvalue-", "", predictors, fixed = TRUE) } @@ -106,8 +114,8 @@ vertexEffectSize <- function(buffer, predictors = NULL) for (var in cat_vars) { referencegroupsize[, grep(var, predictors, value = TRUE)] <- - NROW(updatedAttrs$model[, grep(var, colnames(updatedAttrs$model))]) - - sum(updatedAttrs$model[, grep(var, colnames(updatedAttrs$model))]) + NROW(updatedAttrs$model[, grep(":", grep(var, colnames(updatedAttrs$model), value = TRUE), invert = TRUE, value = TRUE)]) - + sum(updatedAttrs$model[, grep(":", grep(var, colnames(updatedAttrs$model), value = TRUE), invert = TRUE, value = TRUE)]) } n.cols <- length(predictors) diff --git a/man/vertexEffectSize.Rd b/man/vertexEffectSize.Rd index cd345e16..dce2f7b1 100644 --- a/man/vertexEffectSize.Rd +++ b/man/vertexEffectSize.Rd @@ -29,6 +29,10 @@ hedges g* and variance of hedges g* \details{ This code implements the methods from Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x for computing effect size of group comparisons from a GLM. + +For now, interactions are explicitly excluded from being predictors. To get +effect size for interactions, use the interaction() function to create a new +treatment coded factor to use as a predictor. } \section{Functions}{ \itemize{ From 40dae604d80c2412bd63428b26141418063e5ad0 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Mon, 29 Oct 2018 14:45:58 -0400 Subject: [PATCH 12/41] Add comments to effectsize code --- R/effectsize.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/R/effectsize.R b/R/effectsize.R index b1b6c91b..f80d87d3 100644 --- a/R/effectsize.R +++ b/R/effectsize.R @@ -49,6 +49,7 @@ vertexEffectSize <- function(buffer, predictors = NULL) # N = n1+n2 # NN = n1*n2 + #Scrub columns not needed originalMincAttrs <- mincAttributes(buffer) stattype <- originalMincAttrs$`stat-type` # Remove coefficients from buffer @@ -77,6 +78,7 @@ vertexEffectSize <- function(buffer, predictors = NULL) } } + #Extract model, contrasts from model call model_call <- attr(buffer, "call") model_call[[1]] <- quote(model.matrix) names(model_call)[names(model_call) == "formula"] <- "" @@ -86,6 +88,7 @@ vertexEffectSize <- function(buffer, predictors = NULL) names(conts)[vapply(conts, function(x) all(x == "contr.treatment"), logical(1))] + #Checking for assumptions regarding computing if (is.null(conts)) stop("No categorical variables in model, cannot compute g* statistics") @@ -103,11 +106,15 @@ vertexEffectSize <- function(buffer, predictors = NULL) stop("Interactions in predictors are not currently supported, generate treatment contrasts using interaction()") + #If predictors aren't provided, ennumerate factors from the model if (is.null(predictors)) { predictors <- grep(":", grep(paste(cat_vars, collapse = "|"), updatedAttrs$dimnames[[2]], value = TRUE), invert = TRUE, value = TRUE) predictors <- gsub("tvalue-", "", predictors, fixed = TRUE) } + + #Compute reference group size, find number of total subjects, subtract all + #instaces of the treatment-coded factor, remaining number is reference group referencegroupsize <- matrix(1, nrow = 1, ncol = length(predictors)) colnames(referencegroupsize) <- predictors From c6a2c0e4bb7c5fbbdaa0cea9c51205ebffb9012e Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Mon, 29 Oct 2018 14:46:41 -0400 Subject: [PATCH 13/41] Adjust sanity checks for effectsize code --- R/effectsize.R | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/R/effectsize.R b/R/effectsize.R index f80d87d3..47bc820a 100644 --- a/R/effectsize.R +++ b/R/effectsize.R @@ -90,18 +90,15 @@ vertexEffectSize <- function(buffer, predictors = NULL) #Checking for assumptions regarding computing if (is.null(conts)) - stop("No categorical variables in model, cannot compute g* statistics") + stop("No factors in model, cannot compute g* statistics") + + if (is.null(cat_vars)) + stop("No treatment-coded factors in model, cannot compute g* statistics") if (!is.null(predictors) && !all(predictors %in% colnames(updatedAttrs$model))) stop("Supplied predictors not found in model") - if (!all(conts == "contr.treatment")) - stop( - "Non-treatment factors present in model, effect size is not meaningful - for this configuration" - ) - if (!is.null(predictors) && any(grepl(":", predictors))) stop("Interactions in predictors are not currently supported, generate treatment contrasts using interaction()") From 77cb5bd72628f4546c53b26b9d78f83ba128d028 Mon Sep 17 00:00:00 2001 From: nzxwang Date: Mon, 29 Oct 2018 16:30:56 -0400 Subject: [PATCH 14/41] mincLm subset --- R/minc_lmer.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/R/minc_lmer.R b/R/minc_lmer.R index cc8a24e4..d99991bb 100644 --- a/R/minc_lmer.R +++ b/R/minc_lmer.R @@ -668,3 +668,10 @@ mincLogLikRatioParametricBootstrap <- function(logLikOutput, selection="random", attr(logLikOutput, "parametricBootstrapModel") <- lmodel return(logLikOutput) } + +#' @export +`[.mincLm` <- function(x,i,j, drop = TRUE){ + mc <- match.call() + mc[[1]] <- quote(`[.anatModel`) + eval.parent(mc) +} From 6d805c998cc0f93a19e0a9c27df1591433f69e85 Mon Sep 17 00:00:00 2001 From: nzxwang Date: Mon, 29 Oct 2018 17:08:30 -0400 Subject: [PATCH 15/41] move to voxel_statistics; use sys.call() match.call bound named arguments dropping empty args which confused nargs. sys.call does no name binding and so preservs empty arguments --- R/minc_lmer.R | 7 ------- R/minc_voxel_statistics.R | 10 ++++++---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/R/minc_lmer.R b/R/minc_lmer.R index d99991bb..cc8a24e4 100644 --- a/R/minc_lmer.R +++ b/R/minc_lmer.R @@ -668,10 +668,3 @@ mincLogLikRatioParametricBootstrap <- function(logLikOutput, selection="random", attr(logLikOutput, "parametricBootstrapModel") <- lmodel return(logLikOutput) } - -#' @export -`[.mincLm` <- function(x,i,j, drop = TRUE){ - mc <- match.call() - mc[[1]] <- quote(`[.anatModel`) - eval.parent(mc) -} diff --git a/R/minc_voxel_statistics.R b/R/minc_voxel_statistics.R index 500c4c20..7479b646 100644 --- a/R/minc_voxel_statistics.R +++ b/R/minc_voxel_statistics.R @@ -1256,7 +1256,9 @@ thresholds.minc_randomization <- `rownames<-`(paste0(probs * 100, "%")) } - - - - +#' @export +`[.mincLm` <- function(x,i,j, drop = TRUE){ + mc <- sys.call() + mc[[1]] <- quote(`[.anatModel`) + eval.parent(mc) +} From 6bc32eb747d93538587b852a2cc92d05cc243224 Mon Sep 17 00:00:00 2001 From: nzxwang Date: Tue, 30 Oct 2018 13:10:32 -0400 Subject: [PATCH 16/41] drop = FALSE to imitate list subsetting behaviour fixes a bug where subsetting mincLm with one column drops all other attributes. Also set anatLm subsetting drop=FALSE by default --- R/minc_anatomy.R | 2 +- R/minc_voxel_statistics.R | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/R/minc_anatomy.R b/R/minc_anatomy.R index 8a3f49f8..17048454 100644 --- a/R/minc_anatomy.R +++ b/R/minc_anatomy.R @@ -416,7 +416,7 @@ print.anatModel <- function(x, n = min(6, nrow(x)), width = min(6, ncol(x)), ... } #' @export -`[.anatModel` <- function(x, i, j, drop = TRUE){ +`[.anatModel` <- function(x, i, j, drop = FALSE){ orig_x <- x mdrop <- missing(drop) n_args <- nargs() - !mdrop diff --git a/R/minc_voxel_statistics.R b/R/minc_voxel_statistics.R index 7479b646..d6375130 100644 --- a/R/minc_voxel_statistics.R +++ b/R/minc_voxel_statistics.R @@ -1257,8 +1257,6 @@ thresholds.minc_randomization <- } #' @export -`[.mincLm` <- function(x,i,j, drop = TRUE){ - mc <- sys.call() - mc[[1]] <- quote(`[.anatModel`) - eval.parent(mc) +`[.mincLm` <- function(x,i,j, drop = FALSE){ + `[.anatModel`(x,i,j, drop) } From aaecd34f541bef54d171c5e097ff4fa909c51efd Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Wed, 31 Oct 2018 15:19:31 -0400 Subject: [PATCH 17/41] Add check for supplied predictors being treatment contrasts in effectsize calculation --- R/effectsize.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/effectsize.R b/R/effectsize.R index 47bc820a..b57ad6b8 100644 --- a/R/effectsize.R +++ b/R/effectsize.R @@ -99,6 +99,10 @@ vertexEffectSize <- function(buffer, predictors = NULL) !all(predictors %in% colnames(updatedAttrs$model))) stop("Supplied predictors not found in model") + if (!is.null(predictors) && + !all(grepl(paste(cat_vars, collapse = "|"), predictors))) + stop("Supplied predictors are not treatment contrasts") + if (!is.null(predictors) && any(grepl(":", predictors))) stop("Interactions in predictors are not currently supported, generate treatment contrasts using interaction()") From 2977231ce0a24a5f520bb6cf75a9789048446640 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Wed, 31 Oct 2018 15:19:43 -0400 Subject: [PATCH 18/41] Automatic code reformat --- R/effectsize.R | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/R/effectsize.R b/R/effectsize.R index b57ad6b8..2494253e 100644 --- a/R/effectsize.R +++ b/R/effectsize.R @@ -7,7 +7,7 @@ #' be computed for all treatment-coded factor columns. #' @details This code implements the methods from Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x #' for computing effect size of group comparisons from a GLM. -#' +#' #' For now, interactions are explicitly excluded from being predictors. To get #' effect size for interactions, use the interaction() function to create a new #' treatment coded factor to use as a predictor. @@ -48,7 +48,7 @@ vertexEffectSize <- function(buffer, predictors = NULL) # n2 reference group # N = n1+n2 # NN = n1*n2 - + #Scrub columns not needed originalMincAttrs <- mincAttributes(buffer) stattype <- originalMincAttrs$`stat-type` @@ -72,12 +72,12 @@ vertexEffectSize <- function(buffer, predictors = NULL) updatedAttrs$`stat-type`[-indicesToRemove] updatedAttrs$dimnames[[2]] <- updatedAttrs$dimnames[[2]][-indicesToRemove] - + buffer <- buffer[, -indicesToRemove] buffer <- setMincAttributes(buffer, updatedAttrs) } } - + #Extract model, contrasts from model call model_call <- attr(buffer, "call") model_call[[1]] <- quote(model.matrix) @@ -104,28 +104,46 @@ vertexEffectSize <- function(buffer, predictors = NULL) stop("Supplied predictors are not treatment contrasts") if (!is.null(predictors) && any(grepl(":", predictors))) - stop("Interactions in predictors are not currently supported, - generate treatment contrasts using interaction()") - + stop( + "Interactions in predictors are not currently supported, + generate treatment contrasts using interaction()" + ) + #If predictors aren't provided, ennumerate factors from the model if (is.null(predictors)) { - predictors <- grep(":", grep(paste(cat_vars, collapse = "|"), updatedAttrs$dimnames[[2]], value = TRUE), invert = TRUE, value = TRUE) + predictors <- + grep( + ":", + grep( + paste(cat_vars, collapse = "|"), + updatedAttrs$dimnames[[2]], + value = TRUE + ), + invert = TRUE, + value = TRUE + ) predictors <- gsub("tvalue-", "", predictors, fixed = TRUE) } - + #Compute reference group size, find number of total subjects, subtract all #instaces of the treatment-coded factor, remaining number is reference group referencegroupsize <- matrix(1, nrow = 1, ncol = length(predictors)) colnames(referencegroupsize) <- predictors - + for (var in cat_vars) { referencegroupsize[, grep(var, predictors, value = TRUE)] <- - NROW(updatedAttrs$model[, grep(":", grep(var, colnames(updatedAttrs$model), value = TRUE), invert = TRUE, value = TRUE)]) - - sum(updatedAttrs$model[, grep(":", grep(var, colnames(updatedAttrs$model), value = TRUE), invert = TRUE, value = TRUE)]) + NROW(updatedAttrs$model[, grep(":", + grep(var, colnames(updatedAttrs$model), value = TRUE), + invert = TRUE, + value = TRUE)]) - + sum(updatedAttrs$model[, grep(":", + grep(var, colnames(updatedAttrs$model), value = TRUE), + invert = TRUE, + value = TRUE)]) } - + n.cols <- length(predictors) n.row <- 0 if (is.matrix(buffer)) { @@ -152,10 +170,10 @@ vertexEffectSize <- function(buffer, predictors = NULL) } rownames(output) <- rownames(buffer) attr(output, "likeVolume") <- attr(buffer, "likeVolume") - + # run the garbage collector... gcout <- gc() - + return(output) } From 4320818493b4666d1329bc0214277e214846e814 Mon Sep 17 00:00:00 2001 From: nzxwang Date: Fri, 7 Dec 2018 14:58:34 -0500 Subject: [PATCH 19/41] the "Structure" column had "/" replaced by " and ". the JSON file needs to match it --- R/minc_hierarchical_anatomy.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/minc_hierarchical_anatomy.R b/R/minc_hierarchical_anatomy.R index 4d6419c6..c6e420ea 100644 --- a/R/minc_hierarchical_anatomy.R +++ b/R/minc_hierarchical_anatomy.R @@ -437,6 +437,7 @@ makeMICeDefsHierachical <- function(defs, abijson) { # split the definitions into one per line (i.e. left and right separate) ldefs <- lateralizeDefs(defs) + tree$Do(function(n){ n$name <- gsub("/", " and ", n$name)}) # create the first version of the anatomical hierarchy mh <- addHierarchyToDefs(ldefs, tree) treeMH <- as.Node(mh) From eb17457ed49ffd48d1f949f4b6acfff2a34cb8c0 Mon Sep 17 00:00:00 2001 From: nzxwang Date: Mon, 10 Dec 2018 17:22:10 -0500 Subject: [PATCH 20/41] check if the leaf is present in anat; if leaf has no volume, still calc meanVolume in Aggregate --- R/minc_hierarchical_anatomy.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/minc_hierarchical_anatomy.R b/R/minc_hierarchical_anatomy.R index c6e420ea..551678e4 100644 --- a/R/minc_hierarchical_anatomy.R +++ b/R/minc_hierarchical_anatomy.R @@ -273,13 +273,15 @@ addVolumesToHierarchy <- function(hdefs, volumes){ volLabels <- as.integer(attributes(volumes)$anatIDs) hanat$Do(function(x) { if (isLeaf(x)) { - whichIndex <- which(volLabels == x$label) - x$volumes <- volumes[,whichIndex] - x$meanVolume <- mean(x$volumes) + if (x$label %in% volLabels) { + whichIndex <- which(volLabels == x$label) + x$volumes <- volumes[, whichIndex] + x$meanVolume <- mean(x$volumes) + } } }) - hanat$Do(function(x) x$meanVolume <- Aggregate(x, "meanVolume", sum), traversal="post-order") + hanat$Do(function(x) x$meanVolume <- Aggregate(x, "meanVolume", function(x) sum(x,na.rm=TRUE)), traversal="post-order") hanat$Do(function(x) x$volumes <- Aggregate(x, "volumes", rowSums), traversal="post-order", filterFun = isNotLeaf) return(hanat) From 441da03c6cb388128c259e253f3f5b1a67a15942 Mon Sep 17 00:00:00 2001 From: nzxwang Date: Mon, 17 Dec 2018 12:48:55 -0500 Subject: [PATCH 21/41] undo na.rm=TRUE for summing mean Volume; undo x volLabels as that is the user's responsibility to Prune the tree --- R/minc_hierarchical_anatomy.R | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/R/minc_hierarchical_anatomy.R b/R/minc_hierarchical_anatomy.R index 551678e4..5d71e09a 100644 --- a/R/minc_hierarchical_anatomy.R +++ b/R/minc_hierarchical_anatomy.R @@ -273,15 +273,13 @@ addVolumesToHierarchy <- function(hdefs, volumes){ volLabels <- as.integer(attributes(volumes)$anatIDs) hanat$Do(function(x) { if (isLeaf(x)) { - if (x$label %in% volLabels) { - whichIndex <- which(volLabels == x$label) - x$volumes <- volumes[, whichIndex] - x$meanVolume <- mean(x$volumes) - } + whichIndex <- which(volLabels == x$label) + x$volumes <- volumes[, whichIndex] + x$meanVolume <- mean(x$volumes) } }) - hanat$Do(function(x) x$meanVolume <- Aggregate(x, "meanVolume", function(x) sum(x,na.rm=TRUE)), traversal="post-order") + hanat$Do(function(x) x$meanVolume <- Aggregate(x, "meanVolume", sum), traversal="post-order") hanat$Do(function(x) x$volumes <- Aggregate(x, "volumes", rowSums), traversal="post-order", filterFun = isNotLeaf) return(hanat) From a345fdfbf6c34bb059f07180663008eaf6733a48 Mon Sep 17 00:00:00 2001 From: nzxwang Date: Mon, 17 Dec 2018 13:13:43 -0500 Subject: [PATCH 22/41] if volumes has only one row, do the correct thing when aggregating volumes --- R/minc_hierarchical_anatomy.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/minc_hierarchical_anatomy.R b/R/minc_hierarchical_anatomy.R index 5d71e09a..89aa81fc 100644 --- a/R/minc_hierarchical_anatomy.R +++ b/R/minc_hierarchical_anatomy.R @@ -280,8 +280,13 @@ addVolumesToHierarchy <- function(hdefs, volumes){ }) hanat$Do(function(x) x$meanVolume <- Aggregate(x, "meanVolume", sum), traversal="post-order") - hanat$Do(function(x) x$volumes <- Aggregate(x, "volumes", rowSums), + if (dim(volumes)[[1]]==1){ + hanat$Do(function(x) x$volumes <- Aggregate(x, "volumes", sum), + traversal="post-order", filterFun = isNotLeaf) + } else { + hanat$Do(function(x) x$volumes <- Aggregate(x, "volumes", rowSums), traversal="post-order", filterFun = isNotLeaf) + } return(hanat) } From 9bffd6458b4b04979ec062beb70fa88c160d8432 Mon Sep 17 00:00:00 2001 From: "Vladimir S. FONOV" Date: Wed, 16 Jan 2019 18:36:15 -0500 Subject: [PATCH 23/41] WIP: switching to readr for vertex input --- R/minc_interface.R | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/R/minc_interface.R b/R/minc_interface.R index 709d8e12..ce299c1f 100644 --- a/R/minc_interface.R +++ b/R/minc_interface.R @@ -900,15 +900,30 @@ minc.get.volumes <- function(filenames) { return(output) } + +extract_column<-function(filename, column=NULL) { + # determine file type and treat accordingly + ext=tools::file_ext(filename) + if(ext %in% c('gz','xz','bz2','GZ','XZ','BZ2')) # it's compressed file, but we don't care since it can be read + { + filename_=tools::file_path_sans_ext(filename) + ext=tools::file_ext(filename_) + } + if(ext %in% c('csv','CSV') ) +} + #' Create a table of vertex values #' #' Read files containing vertex data into a matrix #' #' @param filenames paths to the vertex data files +#' suported extensions: .csv/.csv.gz - will assume it's a comma-separated file with a header +#' everything else , assume a space separated file, possibly gzipped +#' @param column -specify the column id (name or number) if input files have multiple columns #' @return a matrix where each `column` is a matrix of vertex #' data corresponding to a single file #' @export -vertexTable <- function(filenames) { +vertexTable <- function(filenames,column=NULL) { if(is.factor(filenames)) filenames <- as.character(filenames) From c2c705ce7ef64a6223debbb07df3737844a5b887 Mon Sep 17 00:00:00 2001 From: nzxwang Date: Thu, 17 Jan 2019 12:32:33 -0500 Subject: [PATCH 24/41] roxygen2 generated NAMESPACe change that 6d805c998cc0f93a19e0a9c27df1591433f69e85 should have done --- NAMESPACE | 1 + 1 file changed, 1 insertion(+) diff --git a/NAMESPACE b/NAMESPACE index 271266e1..3a42d465 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand S3method("[",anatModel) +S3method("[",mincLm) S3method(AIC,anatModel) S3method(AIC,mincLm) S3method(AIC,vertexLm) From 0698a62dbc987fd3bdd1c2afca165813cec95ac4 Mon Sep 17 00:00:00 2001 From: "Vladimir S. FONOV" Date: Thu, 17 Jan 2019 17:04:01 -0500 Subject: [PATCH 25/41] Made configuration script recognize MINC_TOOLKIT environment variable --- configure | 247 +++++++++++++++++++--------------- configure.ac | 3 + inst/tools/ch_minc_depends.m4 | 16 ++- 3 files changed, 156 insertions(+), 110 deletions(-) diff --git a/configure b/configure index c9143214..477cf65b 100755 --- a/configure +++ b/configure @@ -639,6 +639,8 @@ GREP CPP MINC_BUILD_PATH MINC_TOOLKIT_BUILD_DIR +MINC_PATH +MINC_TOOLKIT ac_ct_CXX CXXFLAGS CXX @@ -668,6 +670,7 @@ infodir docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir @@ -705,6 +708,8 @@ CPPFLAGS CXX CXXFLAGS CCC +MINC_TOOLKIT +MINC_PATH MINC_TOOLKIT_BUILD_DIR MINC_BUILD_PATH CPP' @@ -746,6 +751,7 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -998,6 +1004,15 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1135,7 +1150,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1288,6 +1303,7 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -1336,6 +1352,9 @@ Some influential environment variables: you have headers in a nonstandard directory CXX C++ compiler command CXXFLAGS C++ compiler flags + MINC_TOOLKIT + where to find minc-toolkit, default /opt/minc-itk4/ + MINC_PATH where to find libminc, default /opt/minc-itk4/ MINC_TOOLKIT_BUILD_DIR where to build minctoolkit, default $HOME/local/minc-itk4/ MINC_BUILD_PATH @@ -3303,6 +3322,9 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu MINC_FOUND="" + + + # Check whether --with-build-path was given. if test "${with_build_path+set}" = set; then : withval=$with_build_path; @@ -3838,6 +3860,124 @@ fi done + + { $as_echo "$as_me:${as_lineno-$LINENO}: Searching for libminc" >&5 +$as_echo "$as_me: Searching for libminc" >&6;} + + if test "x$MINC_FOUND" != "xyes"; then : + + if test x$MINC_TOOLKIT != "x"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: MINC_TOOLKIT was specified" >&5 +$as_echo "$as_me: MINC_TOOLKIT was specified" >&6;} + MINC_PATH="$MINC_TOOLKIT" + MINC_FOUND="yes" + +fi + +fi + + if test "x$MINC_FOUND" != "xyes"; then : + + if test x$MINC_PATH != "x"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: MINC_PATH was specified" >&5 +$as_echo "$as_me: MINC_PATH was specified" >&6;} + MINC_FOUND="yes" + +fi + +fi + + if test "x$MINC_FOUND" != "xyes"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking \"Checking for $MINC_BUILD_PATH (MINC_BUILD_PATH)\"" >&5 +$as_echo_n "checking \"Checking for $MINC_BUILD_PATH (MINC_BUILD_PATH)\"... " >&6; } + if test "x$MINC_BUILD_PATH" != "x" && test -d "$MINC_BUILD_PATH"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + MINC_PATH="$MINC_BUILD_PATH" + MINC_FOUND="yes" + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + +fi + + if test "x$MINC_FOUND" != "xyes"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking Checking for /opt/minc-itk4/" >&5 +$as_echo_n "checking Checking for /opt/minc-itk4/... " >&6; } + if test -d "/opt/minc-itk4"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + MINC_FOUND="yes" + MINC_PATH="/opt/minc-itk4" + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + +fi + + if test "x$MINC_FOUND" != "xyes"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking Checking for /opt/minc/" >&5 +$as_echo_n "checking Checking for /opt/minc/... " >&6; } + if test -d "/opt/minc/"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + MINC_FOUND="yes" + MINC_PATH="/opt/minc" + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + +fi + + if test x$MINC_FOUND != "xyes"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking Can we find a minc tool (mincinfo) on the search path" >&5 +$as_echo_n "checking Can we find a minc tool (mincinfo) on the search path... " >&6; } + MINC_INFO_PATH=$(which mincinfo) + if test x$MINC_INFO_PATH == "x"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + MINC_FOUND="yes" + MINC_PATH=${MINC_INFO_PATH%/bin*} + +fi + +fi + + if test "x$MINC_FOUND" == "xyes"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: MINC_PATH set to $MINC_PATH" >&5 +$as_echo "$as_me: MINC_PATH set to $MINC_PATH" >&6;} + { $as_echo "$as_me:${as_lineno-$LINENO}: override by setting the environment variable MINC_PATH" >&5 +$as_echo "$as_me: override by setting the environment variable MINC_PATH" >&6;} + { $as_echo "$as_me:${as_lineno-$LINENO}: or by setting --with-build-path as a configure argument" >&5 +$as_echo "$as_me: or by setting --with-build-path as a configure argument" >&6;} + + LDFLAGS="$LDFLAGS -L${MINC_PATH}/lib -Wl,-rpath,${MINC_PATH}/lib" + CPPFLAGS="$CPPFLAGS -I${MINC_PATH}/include" + +fi + + ac_fn_c_check_header_mongrel "$LINENO" "zlib.h" "ac_cv_header_zlib_h" "$ac_includes_default" if test "x$ac_cv_header_zlib_h" = xyes; then : @@ -4178,111 +4318,6 @@ fi CPPFLAGS="$CPPFLAGS $HDF5_CPPFLAGS" LIBS="$LIBS $HDF5_LIBS" - - { $as_echo "$as_me:${as_lineno-$LINENO}: Searching for libminc" >&5 -$as_echo "$as_me: Searching for libminc" >&6;} - - if test "x$MINC_FOUND" != "xyes"; then : - - if test x$MINC_PATH != "x"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: MINC_PATH was specified" >&5 -$as_echo "$as_me: MINC_PATH was specified" >&6;} - MINC_FOUND="yes" - -fi - -fi - - if test "x$MINC_FOUND" != "xyes"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking \"Checking for $MINC_BUILD_PATH (MINC_BUILD_PATH)\"" >&5 -$as_echo_n "checking \"Checking for $MINC_BUILD_PATH (MINC_BUILD_PATH)\"... " >&6; } - if test "x$MINC_BUILD_PATH" != "x" && test -d "$MINC_BUILD_PATH"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - MINC_PATH="$MINC_BUILD_PATH" - MINC_FOUND="yes" - -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - -fi - - if test "x$MINC_FOUND" != "xyes"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking Checking for /opt/minc-itk4/" >&5 -$as_echo_n "checking Checking for /opt/minc-itk4/... " >&6; } - if test -d "/opt/minc-itk4"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - MINC_FOUND="yes" - MINC_PATH="/opt/minc-itk4" - -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - -fi - - if test "x$MINC_FOUND" != "xyes"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking Checking for /opt/minc/" >&5 -$as_echo_n "checking Checking for /opt/minc/... " >&6; } - if test -d "/opt/minc/"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - MINC_FOUND="yes" - MINC_PATH="/opt/minc" - -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - -fi - - if test x$MINC_FOUND != "xyes"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking Can we find a minc tool (mincinfo) on the search path" >&5 -$as_echo_n "checking Can we find a minc tool (mincinfo) on the search path... " >&6; } - MINC_INFO_PATH=$(which mincinfo) - if test x$MINC_INFO_PATH == "x"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -else - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - MINC_FOUND="yes" - MINC_PATH=${MINC_INFO_PATH%/bin*} - -fi - -fi - - if test "x$MINC_FOUND" == "xyes"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: MINC_PATH set to $MINC_PATH" >&5 -$as_echo "$as_me: MINC_PATH set to $MINC_PATH" >&6;} - { $as_echo "$as_me:${as_lineno-$LINENO}: override by setting the environment variable MINC_PATH" >&5 -$as_echo "$as_me: override by setting the environment variable MINC_PATH" >&6;} - { $as_echo "$as_me:${as_lineno-$LINENO}: or by setting --with-build-path as a configure argument" >&5 -$as_echo "$as_me: or by setting --with-build-path as a configure argument" >&6;} - - LDFLAGS="$LDFLAGS -L${MINC_PATH}/lib -Wl,-rpath,${MINC_PATH}/lib" - CPPFLAGS="$CPPFLAGS -I${MINC_PATH}/include" - -fi - - if test x$MINC_FOUND != "xyes"; then : diff --git a/configure.ac b/configure.ac index 1550a47c..20fe2eb8 100644 --- a/configure.ac +++ b/configure.ac @@ -8,6 +8,9 @@ m4_include([inst/tools/ch_minc_depends.m4]) MINC_FOUND="" +AC_ARG_VAR([MINC_TOOLKIT],[where to find minc-toolkit, default /opt/minc-itk4/]) +AC_ARG_VAR([MINC_PATH],[where to find libminc, default /opt/minc-itk4/]) + dnl This adds a --with-build-path option, adding the directories' dnl include to CPPFLAGS -I, lib to LDFLAGS and the rpath AC_ARG_WITH([build-path], diff --git a/inst/tools/ch_minc_depends.m4 b/inst/tools/ch_minc_depends.m4 index e3a80e11..d8dbc073 100644 --- a/inst/tools/ch_minc_depends.m4 +++ b/inst/tools/ch_minc_depends.m4 @@ -2,6 +2,14 @@ dnl Search for the minc-toolkit AC_DEFUN([MINC_SEARCH], [ AC_MSG_NOTICE([Searching for libminc]) + AS_IF([test "x$MINC_FOUND" != "xyes"], [ + AS_IF([test x$MINC_TOOLKIT != "x"], [ + AC_MSG_NOTICE(MINC_TOOLKIT was specified) + MINC_PATH="$MINC_TOOLKIT" + MINC_FOUND="yes" + ]) + ]) + AS_IF([test "x$MINC_FOUND" != "xyes"], [ AS_IF([test x$MINC_PATH != "x"], [ AC_MSG_NOTICE(MINC_PATH was specified) @@ -115,16 +123,16 @@ AC_DEFUN([INSTALL_LIBMINC], [ dnl This checks for the minc dependencies, called after minc2 is located or installed AC_DEFUN([CHECK_MINC_DEPENDS], [ + MINC_SEARCH + AC_CHECK_HEADER(zlib.h, , [AC_MSG_ERROR([zlib not found])]) - AX_LIB_HDF5 + AX_LIB_HDF5 CFLAGS="$CFLAGS $HDF5_CFLAGS" LDFLAGS="$LDFLAGS $HDF5_LDFLAGS" CPPFLAGS="$CPPFLAGS $HDF5_CPPFLAGS" LIBS="$LIBS $HDF5_LIBS" - MINC_SEARCH - AS_IF([test x$MINC_FOUND != "xyes"], [ INSTALL_LIBMINC ]) @@ -177,7 +185,7 @@ AC_DEFUN([INSTALL_MINC_TOOLKIT], -DMT_BUILD_LITE:BOOL=ON \ -DMT_BUILD_SHARED_LIBS:BOOL=ON \ -DMT_USE_OPENMP:BOOL=$USE_OMP \ - -DCPACK_BINARY_DEB:BOOL=ON \ + -DCPACK_BINARY_DEB:BOOL=ON \ -DCPACK_BINARY_NSIS:BOOL=OFF \ -DCPACK_BINARY_RPM:BOOL=OFF \ -DCPACK_BINARY_STGZ:BOOL=OFF \ From 0305899d99f538006b717b37bec280484148b375 Mon Sep 17 00:00:00 2001 From: "Vladimir S. FONOV" Date: Thu, 17 Jan 2019 17:06:48 -0500 Subject: [PATCH 26/41] Switched from lsof to analyzing /proc/pid/fd replaced read.table and write.table with functions from readr added ability to specify column for vertex stats run roxygen to regenrate documentation added tests to test that new reader works as expected --- DESCRIPTION | 5 ++- NAMESPACE | 1 + R/minc_interface.R | 54 ++++++++++++++++------- R/minc_vertex_statistics.R | 59 +++++++++++++------------ man/add_colour_bar.Rd | 4 +- man/civet.CreateBrainViewFile.Rd | 4 +- man/civet.getFilename.Rd | 20 ++++----- man/colour_mesh.Rd | 5 ++- man/extract_column.Rd | 23 ++++++++++ man/hanatToVisGraph.Rd | 4 +- man/launch_shinyRMINC.Rd | 7 +-- man/lut_to_palette.Rd | 4 +- man/map_to_colours.Rd | 5 ++- man/mcMincApply.Rd | 7 +-- man/minc.ray.trace.Rd | 5 ++- man/mincApplyRCPP.Rd | 4 +- man/mincFDR.Rd | 4 +- man/mincImage.Rd | 4 +- man/mincLm.Rd | 4 +- man/mincPlotAnatAndStatsSlice.Rd | 11 ++--- man/mincRandomize.Rd | 4 +- man/mincRayTraceStats.Rd | 6 +-- man/mincSelectRandomVoxels.Rd | 3 +- man/mincTFCE.Rd | 12 ++--- man/mincWriteVolume.Rd | 4 +- man/obj_montage.Rd | 5 ++- man/pMincApply.Rd | 3 +- man/plot.bic_obj.Rd | 5 ++- man/qMincApply.Rd | 12 ++--- man/thresholds.Rd | 4 +- man/vertexAnova.Rd | 2 +- man/vertexApply.Rd | 2 +- man/vertexFindPeaks.Rd | 3 +- man/vertexLm.Rd | 2 +- man/vertexLmer.Rd | 4 +- man/vertexLmerEstimateDF.Rd | 2 +- man/vertexSummaries.Rd | 8 ++-- man/vertexTFCE.Rd | 16 ++++--- man/vertexTable.Rd | 8 +++- man/writeVertex.Rd | 2 +- tests/testthat/test_vertexFDR.R | 4 +- tests/testthat/test_vertexLm.R | 40 +++++++++++++++++ tests/testthat/test_vertexSummary.R | 68 +++++++++++++++++++++++++++++ 43 files changed, 317 insertions(+), 136 deletions(-) create mode 100644 man/extract_column.Rd diff --git a/DESCRIPTION b/DESCRIPTION index b44d5a1a..ed533a96 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: RMINC -Version: 1.5.2.1 +Version: 1.5.2.2 Date: 2017-05-31 Title: Statistical Tools for Medical Imaging NetCDF (MINC) Files Authors@R: c(person("Jason", "Lerch", role = "aut", email = "jason.lerch@sickkids.ca"), @@ -18,6 +18,7 @@ Imports: batchtools, dplyr (>= 0.7.6), tidyr (>= 0.8.1), + readr , lme4 (>= 1.1-13), purrr (>= 0.2.5), shiny (>= 1.1.0), @@ -59,4 +60,4 @@ OS_type: unix BugReports: https://github.com/Mouse-Imaging-Centre/RMINC/issues URL: https://github.com/Mouse-Imaging-Centre/RMINC, https://wiki.mouseimaging.ca/display/MICePub/RMINC -RoxygenNote: 6.0.1 +RoxygenNote: 6.1.0 diff --git a/NAMESPACE b/NAMESPACE index 271266e1..3a42d465 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand S3method("[",anatModel) +S3method("[",mincLm) S3method(AIC,anatModel) S3method(AIC,mincLm) S3method(AIC,vertexLm) diff --git a/R/minc_interface.R b/R/minc_interface.R index ce299c1f..a1627d74 100644 --- a/R/minc_interface.R +++ b/R/minc_interface.R @@ -900,8 +900,14 @@ minc.get.volumes <- function(filenames) { return(output) } +#' Internal function to read in a table or csv file +#' potentially with many columns +#' and extract just the one we need +#' @param filename path to the vertex data file +#' @param column -specify the column id (name or number) if input files have multiple columns +#' @return a vector of vertex data corresponding to the file -extract_column<-function(filename, column=NULL) { +extract_column<-function(filename, column=1) { # determine file type and treat accordingly ext=tools::file_ext(filename) if(ext %in% c('gz','xz','bz2','GZ','XZ','BZ2')) # it's compressed file, but we don't care since it can be read @@ -909,7 +915,14 @@ extract_column<-function(filename, column=NULL) { filename_=tools::file_path_sans_ext(filename) ext=tools::file_ext(filename_) } - if(ext %in% c('csv','CSV') ) + if(ext %in% c('csv','CSV') ) # assume there will be a column + { + # trat all columns as double + data_=readr::read_csv(filename,col_names=T,col_types = readr::cols(.default = readr::col_double())) + } else { + data_=readr::read_table(filename,col_names=F,col_types = readr::cols(.default = readr::col_double())) + } + return(as.matrix(data_[,column])) } #' Create a table of vertex values @@ -923,7 +936,7 @@ extract_column<-function(filename, column=NULL) { #' @return a matrix where each `column` is a matrix of vertex #' data corresponding to a single file #' @export -vertexTable <- function(filenames,column=NULL) { +vertexTable <- function(filenames, column=1) { if(is.factor(filenames)) filenames <- as.character(filenames) @@ -931,10 +944,10 @@ vertexTable <- function(filenames,column=NULL) { stop("filenames must be either a character or factor vector") nSubjects <- length(filenames) - nvertices <- nrow(read.table(filenames[1])) + nvertices <- nrow(extract_column(filenames[1],column=column)) output <- matrix(nrow=nvertices, ncol=nSubjects) for (i in 1:nSubjects) { - output[,i] <- as.matrix(read.table(filenames[i])) + output[,i] <- as.matrix(extract_column(filenames[i],column=column)) } return(output) } @@ -957,10 +970,11 @@ vertexTable <- function(filenames,column=NULL) { #' } #' @export writeVertex <- function (vertexData, filename, headers = TRUE, mean.stats = NULL, - gf = NULL) + gf = NULL, col.names=FALSE) { append.file = TRUE if (headers == TRUE) { + col.names=TRUE # get rid of parentheses, as they can cause trouble colnames(vertexData) <- gsub('[\\(\\)]', '', colnames(vertexData), perl=T) @@ -988,8 +1002,8 @@ writeVertex <- function (vertexData, filename, headers = TRUE, mean.stats = NULL else { append.file = FALSE } - write.table(vertexData, file = filename, append = append.file, - quote = FALSE, row.names = FALSE, col.names = headers) + readrd::write_delim(vertexData, path = filename, append = append.file, + quote = FALSE, row.names = FALSE, col.names = col.names) } @@ -1160,15 +1174,26 @@ tableOpenFiles <- function(){ table(lsof_results) } +tableOpenFiles_proc <- function () { + # analyze /proc//fd and potentially /proc//map_files + table(list.files(file.path("/proc",Sys.getpid(),"fd"))) + # map_files contains multiple references to the same file, + # not sure how many file discriptors it correpsonds to + #list.files(file.path("/proc",Sys.getpid(),"map_files")) ) +} + enoughAvailableFileDescriptors <- function(n, error = TRUE){ - open_files <- - tryCatch(tableOpenFiles() - , error = function(e) - message("lsof timed out, continuing without " - , "file descriptor checking")) + open_limit=checkCurrentUlimit() + if(open_limit==Inf) return(TRUE) + + open_files <-tableOpenFiles_proc() # why do we need table? + # tryCatch(tableOpenFiles() + # , error = function(e) + # message("lsof timed out, continuing without " + # , "file descriptor checking")) - available_fds <- checkCurrentUlimit() - sum(open_files) + available_fds <- open_limit - sum(open_files) enough_avail <- (n <= available_fds) if(error & !enough_avail) @@ -1282,7 +1307,6 @@ getRMINCTestData <- function(dataPath = tempdir(), method = "libcurl") { #' to the calling environment #' @export verboseRun <- function(expr,verbose = getOption("verbose", FALSE),env = parent.frame()) { - if(!verbose) { sink("/dev/null") on.exit(sink()) diff --git a/R/minc_vertex_statistics.R b/R/minc_vertex_statistics.R index c6ce41d4..f166adbc 100644 --- a/R/minc_vertex_statistics.R +++ b/R/minc_vertex_statistics.R @@ -22,36 +22,36 @@ NULL #' @describeIn vertexSummaries mean #' @export -vertexMean <- function(filenames) +vertexMean <- function(filenames, column=1) { - vertexData = vertexTable(filenames) + vertexData = vertexTable(filenames, column=column) return(rowMeans(vertexData)) } #' @describeIn vertexSummaries sum #' @export -vertexSum <- function(filenames) +vertexSum <- function(filenames, column=1) { - vertexData = vertexTable(filenames) + vertexData = vertexTable(filenames,column=column) return(rowSums(vertexData)) } #' @describeIn vertexSummaries var #' @export -vertexVar <- function(filenames) +vertexVar <- function(filenames, column=1) { - vertexData = vertexTable(filenames) + vertexData = vertexTable(filenames,column=column) return(apply(vertexData,1,var)) } #' @describeIn vertexSummaries standard deviation #' @export -vertexSd<- function(filenames) +vertexSd<- function(filenames,column=1) { - vertexData = vertexTable(filenames) + vertexData = vertexTable(filenames,column=column) return(apply(vertexData,1,sd)) } @@ -150,10 +150,10 @@ matrixApply <- function(mat, fun, ..., mask = NULL, parallel = NULL #' } #' @export vertexApply <- function(filenames, fun, ..., mask = NULL, parallel = NULL - , collate = simplify_masked, transpose = FALSE) + , collate = simplify_masked, transpose = FALSE, column=1) { # Load the data - vertexData <- vertexTable(filenames) + vertexData <- vertexTable(filenames, column=column) if(transpose) vertexData <- t(vertexData) @@ -187,7 +187,7 @@ vertexApply <- function(filenames, fun, ..., mask = NULL, parallel = NULL #' result = vertexAnova(CIVETFILES$nativeRMStlink20mmleft~Primary.Diagnosis,gf) #' } #' @export -vertexAnova <- function(formula, data, subset=NULL) { +vertexAnova <- function(formula, data, subset=NULL, column=1) { # Create Model mf <- match.call(expand.dots=FALSE) m <- match(c("formula", "data", "subset"), names(mf), 0) @@ -199,7 +199,7 @@ vertexAnova <- function(formula, data, subset=NULL) { # Load Vertex Data from Files filenames <- as.character(mf[,1]) - data.matrix <- vertexTable(filenames) + data.matrix <- vertexTable(filenames, column=column) result <- .Call("vertex_anova_loop", data.matrix, mmatrix,attr(mmatrix, "assign"), PACKAGE="RMINC"); attr(result, "model") <- as.matrix(mmatrix) @@ -244,18 +244,21 @@ vertexAnova <- function(formula, data, subset=NULL) { #' result = vertexLm(CIVETFILES$nativeRMStlink20mmleft~Primary.Diagnosis,gf) #' } #' @export -vertexLm <- function(formula, data, subset=NULL) { +vertexLm <- function(formula, data, subset=NULL, column=1 ) { # Build model.frame m <- m_orig <- match.call() mf <- match.call(expand.dots=FALSE) m <- match(c("formula", "data", "subset"), names(mf), 0) + mf <- mf[c(1, m)] + mf$drop.unused.levels <- TRUE mf[[1]] <- as.name("model.frame") + mf <- eval(mf, parent.frame()) + mincFileCheck(as.character(mf[,1])) - - + if(length(grep("\\$",formula[[3]])) > 0) { stop("$ Not Permitted in Formula") } @@ -267,31 +270,33 @@ vertexLm <- function(formula, data, subset=NULL) { # rows = rows, # matrixFound = matrixFound, # mmatrix = mmatrix) - parseLmOutput <- parseLmFormula(formula,data,mf) - + parseLmOutput <- parseLmFormula(formula,data,mf) + if(parseLmOutput$matrixFound) { - parseLmOutput$data.matrix.left <- vertexTable(parseLmOutput$data.matrix.left) - parseLmOutput$data.matrix.right <- vertexTable(parseLmOutput$data.matrix.right) + + parseLmOutput$data.matrix.left <- vertexTable(parseLmOutput$data.matrix.left, column=column) + parseLmOutput$data.matrix.right <- vertexTable(parseLmOutput$data.matrix.right, column=column) } else { + filenames <- as.character(mf[,1]) parseLmOutput$mmatrix <- model.matrix(formula, mf) - parseLmOutput$data.matrix.left <- vertexTable(filenames) + parseLmOutput$data.matrix.left <- vertexTable(filenames, column=column) parseLmOutput$rows = colnames(parseLmOutput$mmatrix) - } - + } result <- .Call("vertex_lm_loop", parseLmOutput$data.matrix.left, parseLmOutput$data.matrix.right, parseLmOutput$mmatrix, PACKAGE="RMINC") - + attr(result, "likeVolume") <- as.character(mf[,1])[1] attr(result, "model") <- as.matrix(parseLmOutput$mmatrix) attr(result, "filenames") <- as.character(mf[,1]) attr(result, "stat-type") <- c("F", "R-squared", rep("beta",(ncol(result)-2)/2), rep("t",(ncol(result)-2)/2), "logLik") attr(result, "data") <- data attr(result, "call") <- m_orig + Fdf1 <- ncol(attr(result, "model")) -1 Fdf2 <- nrow(attr(result, "model")) - ncol(attr(result, "model")) @@ -309,7 +314,6 @@ vertexLm <- function(formula, data, subset=NULL) { # run the garbage collector... gcout <- gc() - return(result) } @@ -440,7 +444,7 @@ vertexLmer <- #' } #' @export vertexLmerEstimateDF <- - function(model){ + function(model, column=1){ # set the DF based on the Satterthwaite approximation mincLmerList <- attr(model, "mincLmerList") mask <- attr(model, "mask") @@ -456,7 +460,7 @@ vertexLmerEstimateDF <- initial_frame <- #unpack the lmerList object to get the raw data attr(model, "mincLmerList")[[1]]$fr - vertex_data <- vertexTable(initial_frame[,1]) + vertex_data <- vertexTable(initial_frame[,1], column=column) # estimated DF depends on the input data. Rather than estimate separately at every structure, # instead select a small number of structures and estimate DF for those structures, then keep the @@ -720,12 +724,13 @@ vertexTFCE.character <- , nsteps = 100 , side = c("both", "positive", "negative") , weights = NULL + , column=1 , ...){ if(length(x) == 1){ x <- as.numeric(readLines(x)) vertexTFCE.numeric(x, surface, E = E, H = H, nsteps = nsteps, side = side, weights = weights, ...) } else { - x <- vertexTable(x) + x <- vertexTable(x,column=column) vertexTFCE.matrix(x, surface, E = E, H = H, nsteps = nsteps, side = side, weights = weights, ...) } } diff --git a/man/add_colour_bar.Rd b/man/add_colour_bar.Rd index 8dad60f4..bf032515 100644 --- a/man/add_colour_bar.Rd +++ b/man/add_colour_bar.Rd @@ -4,8 +4,8 @@ \alias{add_colour_bar} \title{Add a colour bar for a mesh} \usage{ -add_colour_bar(mesh, title = "", lpos = 0.97, rpos = 0.99, bpos = NULL, - tpos = NULL, bpos2 = NULL, tpos2 = NULL) +add_colour_bar(mesh, title = "", lpos = 0.97, rpos = 0.99, + bpos = NULL, tpos = NULL, bpos2 = NULL, tpos2 = NULL) } \arguments{ \item{mesh}{A \code{obj_mesh} object created with \link{colour_mesh}} diff --git a/man/civet.CreateBrainViewFile.Rd b/man/civet.CreateBrainViewFile.Rd index 60bcbe5f..e8d722b7 100644 --- a/man/civet.CreateBrainViewFile.Rd +++ b/man/civet.CreateBrainViewFile.Rd @@ -4,8 +4,8 @@ \alias{civet.CreateBrainViewFile} \title{Create a brain view file} \usage{ -civet.CreateBrainViewFile(dataFile, atlasFile, atlasVertices, outputFileName, - civetVersion = "1.1.12") +civet.CreateBrainViewFile(dataFile, atlasFile, atlasVertices, + outputFileName, civetVersion = "1.1.12") } \arguments{ \item{dataFile}{Either the name of a file with atlas labeling or an R array with atlas labeling} diff --git a/man/civet.getFilename.Rd b/man/civet.getFilename.Rd index 3f1741bd..68009468 100644 --- a/man/civet.getFilename.Rd +++ b/man/civet.getFilename.Rd @@ -41,17 +41,17 @@ civet.getFilenameCerebrumMask(scanID, baseDir, civetVersion = "1.1.9", civet.getFilenameSkullMask(scanID, baseDir, civetVersion = "1.1.9", fullPath = TRUE) -civet.getFilenameGrayMatterSurfaces(scanID, baseDir, civetVersion = "1.1.9", - fullPath = TRUE) +civet.getFilenameGrayMatterSurfaces(scanID, baseDir, + civetVersion = "1.1.9", fullPath = TRUE) -civet.getFilenameWhiteMatterSurfaces(scanID, baseDir, civetVersion = "1.1.9", - fullPath = TRUE) +civet.getFilenameWhiteMatterSurfaces(scanID, baseDir, + civetVersion = "1.1.9", fullPath = TRUE) civet.getFilenameMidSurfaces(scanID, baseDir, civetVersion = "1.1.9", fullPath = TRUE) -civet.getFilenamesCorticalThickness(scanID, baseDir, civetVersion = "1.1.9", - smoothing = "20mm", fullPath = TRUE) +civet.getFilenamesCorticalThickness(scanID, baseDir, + civetVersion = "1.1.9", smoothing = "20mm", fullPath = TRUE) civet.getFilenamesCorticalArea(scanID, baseDir, civetVersion = "1.1.9", smoothing = "40mm", fullPath = TRUE) @@ -59,14 +59,14 @@ civet.getFilenamesCorticalArea(scanID, baseDir, civetVersion = "1.1.9", civet.getFilenamesCorticalVolume(scanID, baseDir, civetVersion = "1.1.9", smoothing = "40mm", fullPath = TRUE) -civet.getFilenameMeanSurfaceCurvature(scanID, baseDir, civetVersion = "1.1.9", - fullPath = TRUE) +civet.getFilenameMeanSurfaceCurvature(scanID, baseDir, + civetVersion = "1.1.9", fullPath = TRUE) civet.getFilenameLinearTransform(scanID, baseDir, civetVersion = "1.1.9", fullPath = TRUE) -civet.getFilenameNonlinearTransform(scanID, baseDir, civetVersion = "1.1.9", - fullPath = TRUE) +civet.getFilenameNonlinearTransform(scanID, baseDir, + civetVersion = "1.1.9", fullPath = TRUE) } \arguments{ \item{scanID}{A string specifying the unique scan-id (and thus diff --git a/man/colour_mesh.Rd b/man/colour_mesh.Rd index 05c3648c..05344130 100644 --- a/man/colour_mesh.Rd +++ b/man/colour_mesh.Rd @@ -4,8 +4,9 @@ \alias{colour_mesh} \title{Colourize a mesh} \usage{ -colour_mesh(mesh, colour_map, colour_range = NULL, colour_default = "grey", - symmetric = NULL, labels = FALSE, palette = heat.colors(255)) +colour_mesh(mesh, colour_map, colour_range = NULL, + colour_default = "grey", symmetric = NULL, labels = FALSE, + palette = heat.colors(255)) } \arguments{ \item{mesh}{\link[rgl]{mesh3d} object ideally produced by \link{create_mesh}} diff --git a/man/extract_column.Rd b/man/extract_column.Rd new file mode 100644 index 00000000..01a2a333 --- /dev/null +++ b/man/extract_column.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/minc_interface.R +\name{extract_column} +\alias{extract_column} +\title{Internal function to read in a table or csv file +potentially with many columns +and extract just the one we need} +\usage{ +extract_column(filename, column = 1) +} +\arguments{ +\item{filename}{path to the vertex data file} + +\item{column}{-specify the column id (name or number) if input files have multiple columns} +} +\value{ +a vector of vertex data corresponding to the file +} +\description{ +Internal function to read in a table or csv file +potentially with many columns +and extract just the one we need +} diff --git a/man/hanatToVisGraph.Rd b/man/hanatToVisGraph.Rd index 912491cd..6d41b0f8 100644 --- a/man/hanatToVisGraph.Rd +++ b/man/hanatToVisGraph.Rd @@ -7,8 +7,8 @@ \usage{ hanatToVisGraph(hanatTree, colourVariable = "color_hex_triplet", colourScale = colorRampPalette(c("red", "yellow"))(255), - rColourScale = colorRampPalette(c("blue", "turquoise1"))(255), low = NULL, - high = NULL, symmetric = F, transparent = "#FDFDFD", + rColourScale = colorRampPalette(c("blue", "turquoise1"))(255), + low = NULL, high = NULL, symmetric = F, transparent = "#FDFDFD", edgeColourFromABI = F) hanatView(..., fontsize = 14, levelSeparation = 500) diff --git a/man/launch_shinyRMINC.Rd b/man/launch_shinyRMINC.Rd index 47a611ce..0669e45e 100644 --- a/man/launch_shinyRMINC.Rd +++ b/man/launch_shinyRMINC.Rd @@ -4,9 +4,10 @@ \alias{launch_shinyRMINC} \title{launch a shiny based inspector} \usage{ -launch_shinyRMINC(statsoutput, anatVol, volumes = NULL, keepBetas = FALSE, - plotcolumns = NULL, modelfunc = NULL, singleStatType = NULL, - fdr = NULL, anatLow = 700, anatHigh = 1400) +launch_shinyRMINC(statsoutput, anatVol, volumes = NULL, + keepBetas = FALSE, plotcolumns = NULL, modelfunc = NULL, + singleStatType = NULL, fdr = NULL, anatLow = 700, + anatHigh = 1400) } \arguments{ \item{statsoutput}{the output of mincLm, mincAnova, or mincLmer. Alternatively diff --git a/man/lut_to_palette.Rd b/man/lut_to_palette.Rd index 83e223c1..e52f46ed 100644 --- a/man/lut_to_palette.Rd +++ b/man/lut_to_palette.Rd @@ -4,8 +4,8 @@ \alias{lut_to_palette} \title{A tool that returns a color function/palette from color lookup files} \usage{ -lut_to_palette(lookup_table = system.file("luts/spectral", package = "RMINC"), - alpha = 1) +lut_to_palette(lookup_table = system.file("luts/spectral", package = + "RMINC"), alpha = 1) } \arguments{ \item{lookup_table}{Either a path to the lookup table file, or the table itself} diff --git a/man/map_to_colours.Rd b/man/map_to_colours.Rd index c5680144..15914233 100644 --- a/man/map_to_colours.Rd +++ b/man/map_to_colours.Rd @@ -4,8 +4,9 @@ \alias{map_to_colours} \title{Generate a vector of colours from a map} \usage{ -map_to_colours(colour_map, colour_range = NULL, colour_default = "grey", - symmetric = NULL, labels = FALSE, palette = heat.colors(255)) +map_to_colours(colour_map, colour_range = NULL, + colour_default = "grey", symmetric = NULL, labels = FALSE, + palette = heat.colors(255)) } \arguments{ \item{colour_map}{either a vector with a label/measure/statistic for every vertex diff --git a/man/mcMincApply.Rd b/man/mcMincApply.Rd index ecbff18a..c270890e 100644 --- a/man/mcMincApply.Rd +++ b/man/mcMincApply.Rd @@ -5,9 +5,10 @@ \title{Local multicore mincApply} \usage{ mcMincApply(filenames, fun, ..., mask = NULL, tinyMask = FALSE, - slab_sizes = NULL, temp_dir = getwd(), cores = getOption("mc.cores", - parallel::detectCores() - 1), return_raw = FALSE, cleanup = TRUE, - mask_vals = NULL, collate = simplify2minc) + slab_sizes = NULL, temp_dir = getwd(), + cores = getOption("mc.cores", parallel::detectCores() - 1), + return_raw = FALSE, cleanup = TRUE, mask_vals = NULL, + collate = simplify2minc) } \arguments{ \item{filenames}{Paths to the minc files to apply accross} diff --git a/man/minc.ray.trace.Rd b/man/minc.ray.trace.Rd index 54c75d30..973315f6 100644 --- a/man/minc.ray.trace.Rd +++ b/man/minc.ray.trace.Rd @@ -6,8 +6,9 @@ \usage{ minc.ray.trace(volume, output = "slice.rgb", size = c(400, 400), slice = list(pos = 0, wv = "w", axis = "z"), threshold = NULL, - colourmap = "-spectral", background = NULL, background.threshold = NULL, - background.colourmap = "-gray", display = TRUE) + colourmap = "-spectral", background = NULL, + background.threshold = NULL, background.colourmap = "-gray", + display = TRUE) } \arguments{ \item{volume}{The filename of a volume to render.} diff --git a/man/mincApplyRCPP.Rd b/man/mincApplyRCPP.Rd index 07d28a01..06b726d7 100644 --- a/man/mincApplyRCPP.Rd +++ b/man/mincApplyRCPP.Rd @@ -5,8 +5,8 @@ \title{Perform Arbitrary calculations on a collection of mincVolumes} \usage{ mincApplyRCPP(filenames, fun, ..., mask = NULL, maskval = NULL, - filter_masked = FALSE, slab_sizes = c(1, 1, 1), return_indices = FALSE, - collate = simplify2minc) + filter_masked = FALSE, slab_sizes = c(1, 1, 1), + return_indices = FALSE, collate = simplify2minc) } \arguments{ \item{filenames}{The name of the files to apply over} diff --git a/man/mincFDR.Rd b/man/mincFDR.Rd index 4114bbee..dc0d31cd 100644 --- a/man/mincFDR.Rd +++ b/man/mincFDR.Rd @@ -10,8 +10,8 @@ \usage{ mincFDR(buffer, ...) -\method{mincFDR}{mincSingleDim}(buffer, df, mask = NULL, method = "fdr", - ...) +\method{mincFDR}{mincSingleDim}(buffer, df, mask = NULL, + method = "fdr", ...) \method{mincFDR}{mincLogLikRatio}(buffer, mask = NULL, ...) diff --git a/man/mincImage.Rd b/man/mincImage.Rd index af89ca2e..77d33818 100644 --- a/man/mincImage.Rd +++ b/man/mincImage.Rd @@ -4,8 +4,8 @@ \alias{mincImage} \title{Plot a slice from a MINC volume} \usage{ -mincImage(volume, dimension = 2, slice = NULL, low = min(volume, na.rm = - TRUE), high = max(volume, na.rm = TRUE), reverse = FALSE, +mincImage(volume, dimension = 2, slice = NULL, low = min(volume, + na.rm = TRUE), high = max(volume, na.rm = TRUE), reverse = FALSE, underTransparent = FALSE, col = gray.colors(255), add = FALSE, ...) } \arguments{ diff --git a/man/mincLm.Rd b/man/mincLm.Rd index aba38fea..ca81c530 100644 --- a/man/mincLm.Rd +++ b/man/mincLm.Rd @@ -4,8 +4,8 @@ \alias{mincLm} \title{Linear model at Every Voxel} \usage{ -mincLm(formula, data = NULL, subset = NULL, mask = NULL, maskval = NULL, - parallel = NULL, cleanup = TRUE, +mincLm(formula, data = NULL, subset = NULL, mask = NULL, + maskval = NULL, parallel = NULL, cleanup = TRUE, conf_file = getOption("RMINC_BATCH_CONF")) } \arguments{ diff --git a/man/mincPlotAnatAndStatsSlice.Rd b/man/mincPlotAnatAndStatsSlice.Rd index 92b28bcc..6b8d7d29 100644 --- a/man/mincPlotAnatAndStatsSlice.Rd +++ b/man/mincPlotAnatAndStatsSlice.Rd @@ -4,11 +4,12 @@ \alias{mincPlotAnatAndStatsSlice} \title{Anatomy and Statistics Slice} \usage{ -mincPlotAnatAndStatsSlice(anatomy, statistics, slice = NULL, dimension = 2, - low = min(statistics, na.rm = TRUE), high = max(statistics, na.rm = TRUE), - anatLow = min(anatomy, na.rm = TRUE), anatHigh = max(anatomy, na.rm = - TRUE), symmetric = FALSE, col = NULL, rcol = NULL, legend = NULL, - acol = gray.colors(255, start = 0), legendTextColour = "black") +mincPlotAnatAndStatsSlice(anatomy, statistics, slice = NULL, + dimension = 2, low = min(statistics, na.rm = TRUE), + high = max(statistics, na.rm = TRUE), anatLow = min(anatomy, na.rm = + TRUE), anatHigh = max(anatomy, na.rm = TRUE), symmetric = FALSE, + col = NULL, rcol = NULL, legend = NULL, acol = gray.colors(255, + start = 0), legendTextColour = "black") } \arguments{ \item{anatomy}{A minc array of the anatomy volume to plot} diff --git a/man/mincRandomize.Rd b/man/mincRandomize.Rd index 63385893..bf741656 100644 --- a/man/mincRandomize.Rd +++ b/man/mincRandomize.Rd @@ -11,8 +11,8 @@ mincRandomize(x, R = 500, alternative = c("two.sided", "greater"), conf_file = getOption("RMINC_BATCH_CONF")) \method{mincRandomize}{mincLm}(x, R = 500, alternative = c("two.sided", - "greater"), replace = FALSE, parallel = NULL, columns = grep("tvalue-", - colnames(x)), resources = list(), + "greater"), replace = FALSE, parallel = NULL, + columns = grep("tvalue-", colnames(x)), resources = list(), conf_file = getOption("RMINC_BATCH_CONF")) } \arguments{ diff --git a/man/mincRayTraceStats.Rd b/man/mincRayTraceStats.Rd index 6924f2b2..4820d2d2 100644 --- a/man/mincRayTraceStats.Rd +++ b/man/mincRayTraceStats.Rd @@ -9,9 +9,9 @@ mincRayTraceStats(v, anatomy.volume, statsbuffer, column = 1, image.max = 4000, output.width = 800, output.height = 800, place.inset = FALSE, inset = NULL, stats.largest.pos = NULL, stats.largest.neg = NULL, caption = "t-statistic", fdr = NULL, - slice.direction = "transverse", outputfile = "ray_trace_crosshair.png", - show.pos.and.neg = FALSE, display = TRUE, clobber = NULL, - tmpdir = "/tmp") + slice.direction = "transverse", + outputfile = "ray_trace_crosshair.png", show.pos.and.neg = FALSE, + display = TRUE, clobber = NULL, tmpdir = "/tmp") } \arguments{ \item{v}{A mincVoxel indicating the voxel of interest.} diff --git a/man/mincSelectRandomVoxels.Rd b/man/mincSelectRandomVoxels.Rd index ae68d4b8..5d04ab44 100644 --- a/man/mincSelectRandomVoxels.Rd +++ b/man/mincSelectRandomVoxels.Rd @@ -4,7 +4,8 @@ \alias{mincSelectRandomVoxels} \title{selects a few random indices from a volume} \usage{ -mincSelectRandomVoxels(volumeFileName, nvoxels = 50, convert = TRUE, ...) +mincSelectRandomVoxels(volumeFileName, nvoxels = 50, convert = TRUE, + ...) } \arguments{ \item{volumeFileName}{the filename for a MINC volume} diff --git a/man/mincTFCE.Rd b/man/mincTFCE.Rd index ebd67452..bd5ecc27 100644 --- a/man/mincTFCE.Rd +++ b/man/mincTFCE.Rd @@ -12,15 +12,15 @@ mincTFCE(x, ...) \method{mincTFCE}{mincSingleDim}(x, d = 0.1, E = 0.5, H = 2, side = c("both", "positive", "negative"), output_file = NULL, - keep = is.null(output_file), conf_file = getOption("RMINC_BATCH_CONF"), - ...) + keep = is.null(output_file), + conf_file = getOption("RMINC_BATCH_CONF"), ...) -\method{mincTFCE}{matrix}(x, d = 0.1, E = 0.5, H = 2, side = c("both", - "positive", "negative"), like_volume, ...) +\method{mincTFCE}{matrix}(x, d = 0.1, E = 0.5, H = 2, + side = c("both", "positive", "negative"), like_volume, ...) \method{mincTFCE}{mincMultiDim}(x, d = 0.1, E = 0.5, H = 2, - side = c("both", "positive", "negative"), like_volume = likeVolume(x), - ...) + side = c("both", "positive", "negative"), + like_volume = likeVolume(x), ...) \method{mincTFCE}{mincLm}(x, R = 500, alternative = c("two.sided", "greater"), d = 0.1, E = 0.5, H = 2, side = c("both", "positive", diff --git a/man/mincWriteVolume.Rd b/man/mincWriteVolume.Rd index 8d482e4f..493b3a50 100644 --- a/man/mincWriteVolume.Rd +++ b/man/mincWriteVolume.Rd @@ -12,8 +12,8 @@ mincWriteVolume(buffer, ...) \method{mincWriteVolume}{mincSingleDim}(buffer, output.filename, clobber = NULL, ...) -\method{mincWriteVolume}{mincMultiDim}(buffer, output.filename, column = 1, - like.filename = NULL, clobber = NULL, ...) +\method{mincWriteVolume}{mincMultiDim}(buffer, output.filename, + column = 1, like.filename = NULL, clobber = NULL, ...) \method{mincWriteVolume}{default}(buffer, output.filename, like.filename, clobber = NULL, ...) diff --git a/man/obj_montage.Rd b/man/obj_montage.Rd index 82b44748..8173d04a 100644 --- a/man/obj_montage.Rd +++ b/man/obj_montage.Rd @@ -7,8 +7,9 @@ obj_montage(left_obj, right_obj, left_map, right_map, output = NULL, colour_map, colour_range = NULL, colour_default = "grey", colour_bar = TRUE, labels = FALSE, palette = heat.colors(255), - symmetric = FALSE, ..., plot_corners = c(100, 100, 900, 900), zoom = 1, - add_normals = TRUE, colour_title = "", close_on_output = TRUE) + symmetric = FALSE, ..., plot_corners = c(100, 100, 900, 900), + zoom = 1, add_normals = TRUE, colour_title = "", + close_on_output = TRUE) } \arguments{ \item{left_obj}{A \code{bic_obj} probably created by \link{read_obj} with the left hemisphere diff --git a/man/pMincApply.Rd b/man/pMincApply.Rd index fc490117..98a63eb2 100644 --- a/man/pMincApply.Rd +++ b/man/pMincApply.Rd @@ -10,7 +10,8 @@ pMincApply(filenames, fun, ..., mask = NULL, tinyMask = FALSE, walltime = NULL, workers = batches, temp_dir = getwd(), cleanup = TRUE, collate = simplify2minc, conf_file = getOption("RMINC_BATCH_CONF"), - registry_name = new_file("pMincApply_registry"), registry_dir = getwd()) + registry_name = new_file("pMincApply_registry"), + registry_dir = getwd()) } \arguments{ \item{filenames}{Paths to the minc files to be applied accross} diff --git a/man/plot.bic_obj.Rd b/man/plot.bic_obj.Rd index b226d3fe..a80a66e5 100644 --- a/man/plot.bic_obj.Rd +++ b/man/plot.bic_obj.Rd @@ -5,8 +5,9 @@ \title{Plot a BIC obj} \usage{ \method{plot}{bic_obj}(x, colour_map = NULL, colour_range = NULL, - colour_default = "grey", symmetric = FALSE, palette = heat.colors(255), - labels = FALSE, colour_bar = TRUE, add = FALSE, ...) + colour_default = "grey", symmetric = FALSE, + palette = heat.colors(255), labels = FALSE, colour_bar = TRUE, + add = FALSE, ...) } \arguments{ \item{x}{A \code{bic_obj} probably created by \link{read_obj}} diff --git a/man/qMincApply.Rd b/man/qMincApply.Rd index 4bb87433..747685f1 100644 --- a/man/qMincApply.Rd +++ b/man/qMincApply.Rd @@ -10,13 +10,13 @@ qMincApply(filenames, fun, ..., mask = NULL, batches = 4, tinyMask = FALSE, slab_sizes = NULL, resources = list(), packages = c("RMINC"), registry_dir = getwd(), - registry_name = "qMincApply_registry", temp_dir = getwd(), cores = 1, - wait = TRUE, cleanup = TRUE, clobber = FALSE, collate = simplify2minc, - conf_file = getOption("RMINC_BATCH_CONF")) + registry_name = "qMincApply_registry", temp_dir = getwd(), + cores = 1, wait = TRUE, cleanup = TRUE, clobber = FALSE, + collate = simplify2minc, conf_file = getOption("RMINC_BATCH_CONF")) -qMincRegistry(registry_name = "qMincApply_registry", packages = c("RMINC"), - registry_dir = getwd(), clobber = FALSE, resources = list(), - conf_file = getOption("RMINC_BATCH_CONF")) +qMincRegistry(registry_name = "qMincApply_registry", + packages = c("RMINC"), registry_dir = getwd(), clobber = FALSE, + resources = list(), conf_file = getOption("RMINC_BATCH_CONF")) qMincMap(registry, filenames, fun, ..., mask = NULL, slab_sizes = NULL, batches = 4, tinyMask = FALSE, temp_dir = getwd(), cores = 1) diff --git a/man/thresholds.Rd b/man/thresholds.Rd index 836a72fc..4523b193 100644 --- a/man/thresholds.Rd +++ b/man/thresholds.Rd @@ -10,8 +10,8 @@ thresholds(x, ...) \method{thresholds}{mincQvals}(x, ...) -\method{thresholds}{minc_randomization}(x, probs = c(0.01, 0.05, 0.1, 0.2), - ...) +\method{thresholds}{minc_randomization}(x, probs = c(0.01, 0.05, 0.1, + 0.2), ...) } \arguments{ \item{x}{A \code{mincQvals} object, typically computed with \code{mincFDR} or a diff --git a/man/vertexAnova.Rd b/man/vertexAnova.Rd index f6a99e3c..8003684e 100644 --- a/man/vertexAnova.Rd +++ b/man/vertexAnova.Rd @@ -4,7 +4,7 @@ \alias{vertexAnova} \title{Performs ANOVA on each vertex point specified} \usage{ -vertexAnova(formula, data, subset = NULL) +vertexAnova(formula, data, subset = NULL, column = 1) } \arguments{ \item{formula}{a model formula} diff --git a/man/vertexApply.Rd b/man/vertexApply.Rd index b3ddd1bb..8544cf2d 100644 --- a/man/vertexApply.Rd +++ b/man/vertexApply.Rd @@ -5,7 +5,7 @@ \title{Apply function over vertex Files} \usage{ vertexApply(filenames, fun, ..., mask = NULL, parallel = NULL, - collate = simplify_masked, transpose = FALSE) + collate = simplify_masked, transpose = FALSE, column = 1) } \arguments{ \item{filenames}{vertex file names} diff --git a/man/vertexFindPeaks.Rd b/man/vertexFindPeaks.Rd index 064e2184..22c865a3 100644 --- a/man/vertexFindPeaks.Rd +++ b/man/vertexFindPeaks.Rd @@ -5,7 +5,8 @@ \title{Vertex find peaks} \usage{ vertexFindPeaks(data_map, graph, mindist = 1, direction = c("both", - "positive", "negative"), threshold = 0, output = c("mask", "indices")) + "positive", "negative"), threshold = 0, output = c("mask", + "indices")) } \arguments{ \item{data_map}{A vector or text file of values to search for peaks} diff --git a/man/vertexLm.Rd b/man/vertexLm.Rd index d2e036aa..110075e7 100644 --- a/man/vertexLm.Rd +++ b/man/vertexLm.Rd @@ -4,7 +4,7 @@ \alias{vertexLm} \title{Calculates statistics and coefficients for linear model of specified vertex files} \usage{ -vertexLm(formula, data, subset = NULL) +vertexLm(formula, data, subset = NULL, column = 1) } \arguments{ \item{formula}{a model formula. The RHS of the formula may contain one term with filenames. If diff --git a/man/vertexLmer.Rd b/man/vertexLmer.Rd index 9afe7b76..d3792c41 100644 --- a/man/vertexLmer.Rd +++ b/man/vertexLmer.Rd @@ -5,8 +5,8 @@ \title{Vertex Mixed Effects Models} \usage{ vertexLmer(formula, data, mask = NULL, parallel = NULL, REML = TRUE, - control = lmerControl(), start = NULL, verbose = 0L, safely = FALSE, - summary_type = "fixef") + control = lmerControl(), start = NULL, verbose = 0L, + safely = FALSE, summary_type = "fixef") } \arguments{ \item{formula}{the lmer formula, filenames go on left hand side} diff --git a/man/vertexLmerEstimateDF.Rd b/man/vertexLmerEstimateDF.Rd index 2f691202..a8895c17 100644 --- a/man/vertexLmerEstimateDF.Rd +++ b/man/vertexLmerEstimateDF.Rd @@ -4,7 +4,7 @@ \alias{vertexLmerEstimateDF} \title{Estimate the degrees of freedom for parameters in a vertexLmer model} \usage{ -vertexLmerEstimateDF(model) +vertexLmerEstimateDF(model, column = 1) } \arguments{ \item{model}{the output of mincLmer} diff --git a/man/vertexSummaries.Rd b/man/vertexSummaries.Rd index a21abba9..4d77f268 100644 --- a/man/vertexSummaries.Rd +++ b/man/vertexSummaries.Rd @@ -8,13 +8,13 @@ \alias{vertexSd} \title{Create descriptive statistics across a series of vertex files} \usage{ -vertexMean(filenames) +vertexMean(filenames, column = 1) -vertexSum(filenames) +vertexSum(filenames, column = 1) -vertexVar(filenames) +vertexVar(filenames, column = 1) -vertexSd(filenames) +vertexSd(filenames, column = 1) } \arguments{ \item{filenames}{Filenames of the vertex volumes across which to create the diff --git a/man/vertexTFCE.Rd b/man/vertexTFCE.Rd index 7aca7afd..271ce9e5 100644 --- a/man/vertexTFCE.Rd +++ b/man/vertexTFCE.Rd @@ -10,19 +10,21 @@ \usage{ vertexTFCE(x, ...) -\method{vertexTFCE}{numeric}(x, surface, E = 0.5, H = 2, nsteps = 100, - side = c("both", "positive", "negative"), weights = NULL, ...) +\method{vertexTFCE}{numeric}(x, surface, E = 0.5, H = 2, + nsteps = 100, side = c("both", "positive", "negative"), + weights = NULL, ...) \method{vertexTFCE}{matrix}(x, surface, E = 0.5, H = 2, nsteps = 100, side = c("both", "positive", "negative"), weights = NULL, ...) \method{vertexTFCE}{vertexLm}(x, surface, R = 500, - alternative = c("two.sided", "greater"), E = 0.5, H = 2, nsteps = 100, - weights = NULL, side = c("both", "positive", "negative"), - replace = FALSE, parallel = NULL, ...) + alternative = c("two.sided", "greater"), E = 0.5, H = 2, + nsteps = 100, weights = NULL, side = c("both", "positive", + "negative"), replace = FALSE, parallel = NULL, ...) -\method{vertexTFCE}{character}(x, surface, E = 0.5, H = 2, nsteps = 100, - side = c("both", "positive", "negative"), weights = NULL, ...) +\method{vertexTFCE}{character}(x, surface, E = 0.5, H = 2, + nsteps = 100, side = c("both", "positive", "negative"), + weights = NULL, column = 1, ...) } \arguments{ \item{x}{A numeric vector, a filepath to a set of values, diff --git a/man/vertexTable.Rd b/man/vertexTable.Rd index ec82474e..d594bbfe 100644 --- a/man/vertexTable.Rd +++ b/man/vertexTable.Rd @@ -4,10 +4,14 @@ \alias{vertexTable} \title{Create a table of vertex values} \usage{ -vertexTable(filenames) +vertexTable(filenames, column = 1) } \arguments{ -\item{filenames}{paths to the vertex data files} +\item{filenames}{paths to the vertex data files +suported extensions: .csv/.csv.gz - will assume it's a comma-separated file with a header +everything else , assume a space separated file, possibly gzipped} + +\item{column}{-specify the column id (name or number) if input files have multiple columns} } \value{ a matrix where each `column` is a matrix of vertex diff --git a/man/writeVertex.Rd b/man/writeVertex.Rd index c3dd7605..d22ce6a4 100644 --- a/man/writeVertex.Rd +++ b/man/writeVertex.Rd @@ -5,7 +5,7 @@ \title{Writes vertex data to a file with an optional header} \usage{ writeVertex(vertexData, filename, headers = TRUE, mean.stats = NULL, - gf = NULL) + gf = NULL, col.names = FALSE) } \arguments{ \item{vertexData}{vertex data to be written} diff --git a/tests/testthat/test_vertexFDR.R b/tests/testthat/test_vertexFDR.R index e9de3155..24ea6ec4 100644 --- a/tests/testthat/test_vertexFDR.R +++ b/tests/testthat/test_vertexFDR.R @@ -21,7 +21,9 @@ subjectFile[8,1] = file.path(dataPath, "vertex2.txt") subjectFile[9,1] = file.path(dataPath, "vertex3.txt") subjectFile[10,1] = file.path(dataPath, "vertex1.txt") gftest$testFilesLeft <- (subjectFile) -rmincLm <- verboseRun("vertexLm(testFilesLeft ~ Sex,gftest) ",getOption("verbose")) + +#rmincLm <- verboseRun("vertexLm(testFilesLeft ~ Sex,gftest) ",getOption("verbose")) +rmincLm <- vertexLm(testFilesLeft ~ Sex,gftest, column=1) gftest$testLeft = t(vertexTable(gftest$testFilesLeft)) rLm = summary(lm(testLeft[,1]~Sex,gftest)) diff --git a/tests/testthat/test_vertexLm.R b/tests/testthat/test_vertexLm.R index 72c9c0ad..9bb5ac7a 100644 --- a/tests/testthat/test_vertexLm.R +++ b/tests/testthat/test_vertexLm.R @@ -22,10 +22,37 @@ subjectFile[9,1] = file.path(dataPath, "vertex3.txt") subjectFile[10,1] = file.path(dataPath, "vertex1.txt") gftest$testFilesLeft <- (subjectFile) +# test ability to work with .csv.gz files +# convert txt file into a .csv file with a column thk, and a dummy column 'dummy' +for(i in c("vertex1.txt","vertex2.txt","vertex3.txt","vertex4.txt")) { + o<-sub('.txt','.csv.gz',i) + dummy_data<-read.table(file.path(dataPath, i)) + colnames(dummy_data)<-'thk' + dummy_data$dummy<-100 + readr::write_csv(dummy_data,file.path(dataPath, o)) +} + +gftest2 <- read.csv(file.path(dataPath, "subject.csv")) +subjectFile2 = matrix(data=NA,nrow=10,1) +subjectFile2[1,1] = file.path(dataPath, "vertex2.csv.gz") +subjectFile2[2,1] = file.path(dataPath, "vertex3.csv.gz") +subjectFile2[3,1] = file.path(dataPath, "vertex4.csv.gz") +subjectFile2[4,1] = file.path(dataPath, "vertex3.csv.gz") +subjectFile2[5,1] = file.path(dataPath, "vertex1.csv.gz") +subjectFile2[6,1] = file.path(dataPath, "vertex2.csv.gz") +subjectFile2[7,1] = file.path(dataPath, "vertex4.csv.gz") +subjectFile2[8,1] = file.path(dataPath, "vertex2.csv.gz") +subjectFile2[9,1] = file.path(dataPath, "vertex3.csv.gz") +subjectFile2[10,1] = file.path(dataPath, "vertex1.csv.gz") +gftest2$testFilesLeft <- (subjectFile2) + rmincLm <- verboseRun("vertexLm(testFilesLeft ~ Age,gftest)",getOption("verbose")) +rmincLm2 <- verboseRun("vertexLm(testFilesLeft ~ Age,gftest2,column='thk')",getOption("verbose")) gftest$testLeft = t(vertexTable(gftest$testFilesLeft)) +gftest2$testLeft = t(vertexTable(gftest2$testFilesLeft)) + rmod <- lm(testLeft[,1]~Age,gftest) rLm = summary(rmod) @@ -39,6 +66,19 @@ test_that("vertexLm Two Factors",{ expect_that(attr(rmincLm,"df")[[2]],is_equivalent_to(rLm$df[2])) }) + +test_that("vertexLm Two Factors for .csv.gz file",{ + expect_that(rmincLm[1,1],is_equivalent_to(rmincLm2[1,1])) + expect_that(rmincLm[1,2],is_equivalent_to(rmincLm2[1,2])) + expect_that(rmincLm[1,3],is_equivalent_to(rmincLm2[1,3])) + expect_that(rmincLm[1,4],is_equivalent_to(rmincLm2[1,4])) + expect_that(rmincLm[1,5],is_equivalent_to(rmincLm2[1,5])) + expect_that(rmincLm[1,6],is_equivalent_to(rmincLm2[1,6])) + expect_that(attr(rmincLm,"df")[[2]],is_equivalent_to(attr(rmincLm2,"df")[[2]])) +}) + + + test_that("Likelihood and information criteria are computed correctly", { expect_equal(as.numeric(rmincLm[1,"logLik"]), as.numeric(logLik(rmod))) expect_equal(as.numeric(AIC(rmincLm)[1]), as.numeric(AIC(rmod))) diff --git a/tests/testthat/test_vertexSummary.R b/tests/testthat/test_vertexSummary.R index d6825067..862b13ae 100644 --- a/tests/testthat/test_vertexSummary.R +++ b/tests/testthat/test_vertexSummary.R @@ -5,6 +5,7 @@ library(testthat) if(!exists("dataPath")) dataPath <- tempdir() + getRMINCTestData(dataPath) dataPath <- file.path(dataPath, "rminctestdata/") @@ -24,9 +25,44 @@ subjectFile[10,1] = file.path(dataPath, "vertex1.txt") gftest$testFilesLeft <- (subjectFile) gftest$testLeft <- t(vertexTable(gftest$testFilesLeft)) +# test ability to work with .csv.gz files +# convert txt file into a .csv file with a column thk, and a dummy column 'dummy' +for(i in c("vertex1.txt","vertex2.txt","vertex3.txt","vertex4.txt")) { + o<-sub('.txt','.csv.gz',i) + dummy_data<-read.table(file.path(dataPath, i)) + colnames(dummy_data)<-'thk' + dummy_data$dummy<-100 + readr::write_csv(dummy_data,file.path(dataPath, o)) +} + +gftest2 <- read.csv(file.path(dataPath, "subject.csv")) +subjectFile2 = matrix(data=NA,nrow=10,1) +subjectFile2[1,1] = file.path(dataPath, "vertex2.csv.gz") +subjectFile2[2,1] = file.path(dataPath, "vertex3.csv.gz") +subjectFile2[3,1] = file.path(dataPath, "vertex4.csv.gz") +subjectFile2[4,1] = file.path(dataPath, "vertex3.csv.gz") +subjectFile2[5,1] = file.path(dataPath, "vertex1.csv.gz") +subjectFile2[6,1] = file.path(dataPath, "vertex2.csv.gz") +subjectFile2[7,1] = file.path(dataPath, "vertex4.csv.gz") +subjectFile2[8,1] = file.path(dataPath, "vertex2.csv.gz") +subjectFile2[9,1] = file.path(dataPath, "vertex3.csv.gz") +subjectFile2[10,1] = file.path(dataPath, "vertex1.csv.gz") +gftest2$testFilesLeft <- (subjectFile2) +gftest2$testLeft <- t(vertexTable(gftest2$testFilesLeft)) + +context("vertexTable") + +table1<-vertexTable(gftest$testFilesLeft ,column=1) +table2<-vertexTable(gftest2$testFilesLeft ,column=1) +test_that("vertexTable", { + expect_equal(table1,table2) +}) + + context("vertexMean") #Calculate mean + vm <- verboseRun("vertexMean(gftest$testFilesLeft)",getOption("verbose")) test_that("vertexMean", { @@ -35,6 +71,14 @@ test_that("vertexMean", { expect_equal(mean(gftest$testLeft[,3]), vm[3]) }) +vm2 <- verboseRun("vertexMean(gftest2$testFilesLeft)",getOption("verbose")) +test_that("vertexMean.csv", { + expect_equal(mean(gftest$testLeft[,1]), vm2[1]) + expect_equal(mean(gftest$testLeft[,2]), vm2[2]) + expect_equal(mean(gftest$testLeft[,3]), vm2[3]) +}) + + context("vertexSum") #Calculate sum @@ -47,6 +91,13 @@ test_that("vertexSum", { expect_equal(sum(gftest$testLeft[,3]), vs[3]) }) +vs2 <- verboseRun("vertexSum(gftest2$testFilesLeft)",getOption("verbose")) +test_that("vertexSum.csv", { + expect_equal(sum(gftest$testLeft[,1]), vs2[1]) + expect_equal(sum(gftest$testLeft[,2]), vs2[2]) + expect_equal(sum(gftest$testLeft[,3]), vs2[3]) +}) + context("vertexVar") #Calculate variance @@ -57,6 +108,14 @@ test_that("vertexVar", { expect_equal(var(gftest$testLeft[,2]), vv[2]) expect_equal(var(gftest$testLeft[,3]), vv[3]) }) +vv2 <- verboseRun("vertexVar(gftest2$testFilesLeft)",getOption("verbose")) + +test_that("vertexVar", { + expect_equal(var(gftest$testLeft[,1]), vv2[1]) + expect_equal(var(gftest$testLeft[,2]), vv2[2]) + expect_equal(var(gftest$testLeft[,3]), vv2[3]) +}) + context("vertexSd") @@ -68,3 +127,12 @@ test_that("vertexSd", { expect_equal(sd(gftest$testLeft[,2]), vsd[2]) expect_equal(sd(gftest$testLeft[,3]), vsd[3]) }) +#Calculate standard deviation + +vsd2 <- verboseRun("vertexSd(gftest2$testFilesLeft)",getOption("verbose")) + +test_that("vertexSd", { + expect_equal(sd(gftest$testLeft[,1]), vsd2[1]) + expect_equal(sd(gftest$testLeft[,2]), vsd2[2]) + expect_equal(sd(gftest$testLeft[,3]), vsd2[3]) +}) From b9a3bc726f295eab122d168904a2fe6533f0473d Mon Sep 17 00:00:00 2001 From: "Vladimir S. FONOV" Date: Thu, 17 Jan 2019 17:37:36 -0500 Subject: [PATCH 27/41] Fixed writeVertex, and updated documentation. Shows that there is no test for writeVertex --- R/minc_interface.R | 28 +++++++++++++++++++++++----- man/writeVertex.Rd | 4 +++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/R/minc_interface.R b/R/minc_interface.R index a1627d74..b61407ec 100644 --- a/R/minc_interface.R +++ b/R/minc_interface.R @@ -956,7 +956,8 @@ vertexTable <- function(filenames, column=1) { #' Writes vertex data to a file with an optional header #' @param vertexData vertex data to be written #' @param filename full path to file where data shall be written -#' @param headers Whether or not to write header information +#' @param headers Whether or not to write header information (implies col.names=TRUE) +#' @param col.names if column names should be written #' @param mean.stats mean vertex data that may also be written #' @param gf glim matrix that can be written to the header #' @return A file is generated with the vertex data and optional headers @@ -973,11 +974,16 @@ writeVertex <- function (vertexData, filename, headers = TRUE, mean.stats = NULL gf = NULL, col.names=FALSE) { append.file = TRUE - if (headers == TRUE) { - col.names=TRUE + + if(headers == TRUE || col.names == TRUE) + { # get rid of parentheses, as they can cause trouble colnames(vertexData) <- gsub('[\\(\\)]', '', colnames(vertexData), perl=T) + } + + if (headers == TRUE) { + col.names = TRUE write("
", file = filename) if (is.object(mean.stats)) { write("", file = filename, append = TRUE) @@ -1002,8 +1008,20 @@ writeVertex <- function (vertexData, filename, headers = TRUE, mean.stats = NULL else { append.file = FALSE } - readrd::write_delim(vertexData, path = filename, append = append.file, - quote = FALSE, row.names = FALSE, col.names = col.names) + ext=tools::file_ext(filename) + if(ext %in% c('gz','xz','bz2','GZ','XZ','BZ2')) # it's compressed file, but we don't care since it can be read + { + filename_=tools::file_path_sans_ext(filename) + ext=tools::file_ext(filename_) + } + if(ext %in% c('csv','CSV') ) # assume there will be a column + { + readr::write_csv(tibble::as_data_frame(vertexData), path = filename, append = append.file, + col_names = col.names) + } else { + readr::write_delim(tibble::as_data_frame(vertexData), path = filename, append = append.file, + col_names = col.names) + } } diff --git a/man/writeVertex.Rd b/man/writeVertex.Rd index d22ce6a4..26f252fb 100644 --- a/man/writeVertex.Rd +++ b/man/writeVertex.Rd @@ -12,11 +12,13 @@ writeVertex(vertexData, filename, headers = TRUE, mean.stats = NULL, \item{filename}{full path to file where data shall be written} -\item{headers}{Whether or not to write header information} +\item{headers}{Whether or not to write header information (implies col.names=TRUE)} \item{mean.stats}{mean vertex data that may also be written} \item{gf}{glim matrix that can be written to the header} + +\item{col.names}{if column names should be written} } \value{ A file is generated with the vertex data and optional headers From 41069ebbfbc91a53aea412edbb5d7940483045fd Mon Sep 17 00:00:00 2001 From: nzxwang Date: Mon, 28 Jan 2019 13:28:17 -0500 Subject: [PATCH 28/41] if there are extra structures in files and not in labels, or extra structures in labls but not in filse, tell me how many --- R/minc_anatomy.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/minc_anatomy.R b/R/minc_anatomy.R index 17048454..e85aa4e8 100644 --- a/R/minc_anatomy.R +++ b/R/minc_anatomy.R @@ -358,13 +358,15 @@ create_anat_results <- extra_structures <- results %>% filter_(~ is.na(Structure)) %>% .$indices if(length(extra_structures) != 0) - message("Extra Structures found in files but not in labels: " + message(length(extra_structures), + " extra Structures found in files but not in labels: " , paste0(extra_structures, collapse = ", ")) missing_structures <- with(label_frame, Structure[! label %in% results$indices]) if(length(missing_structures) != 0) - message("Missing Structures found in labels but not in any files: " + message(length(missing_structures), + " missing Structures found in labels but not in any files: " , paste0(missing_structures, collapse = ", ")) results <- From 2b5f15bddec1628c55d63ebc40a22c2c9a01151a Mon Sep 17 00:00:00 2001 From: nzxwang Date: Mon, 28 Jan 2019 16:36:26 -0500 Subject: [PATCH 29/41] give error message if hdefs$leafCount > regions in volumes if it is, tell the user to prune the tree instead of giving arcane `stop("'x' must be an array of at least two dimensions")` message --- R/minc_hierarchical_anatomy.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/minc_hierarchical_anatomy.R b/R/minc_hierarchical_anatomy.R index 89aa81fc..f1b745d2 100644 --- a/R/minc_hierarchical_anatomy.R +++ b/R/minc_hierarchical_anatomy.R @@ -269,6 +269,11 @@ hanatLmerEstimateDF <- function(buffer, n=50) { #' hanat <- addVolumesToHierarchy(hdefs, allvols) #' } addVolumesToHierarchy <- function(hdefs, volumes){ + #If hdefs$leafCount > regions in volumes, aggregation will fail as rowSums() is called on NULL volumes + if (hdefs$leafCount > dim(volumes)[[2]]){ + stop("Your hierarchical definitions contain more leaves than regions in your volumes.\n", + "Consider pruning your hierarchy of subtrees that do not exist in your volumes.") + } hanat <- Clone(hdefs) volLabels <- as.integer(attributes(volumes)$anatIDs) hanat$Do(function(x) { From af64522ba0d128af5dd647950dd7eca4b86c41d4 Mon Sep 17 00:00:00 2001 From: nzxwang Date: Mon, 28 Jan 2019 17:00:02 -0500 Subject: [PATCH 30/41] give error message if hdefs < regions in volumes --- R/minc_hierarchical_anatomy.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/minc_hierarchical_anatomy.R b/R/minc_hierarchical_anatomy.R index f1b745d2..b6b7250b 100644 --- a/R/minc_hierarchical_anatomy.R +++ b/R/minc_hierarchical_anatomy.R @@ -274,6 +274,10 @@ addVolumesToHierarchy <- function(hdefs, volumes){ stop("Your hierarchical definitions contain more leaves than regions in your volumes.\n", "Consider pruning your hierarchy of subtrees that do not exist in your volumes.") } + if (hdefs$leafCount < dim(volumes)[[2]]){ + stop("Your hierarchical definitions contain fewer leaves than regions in your volumes.\n", + "Are you using the correct atlas labels?") + } hanat <- Clone(hdefs) volLabels <- as.integer(attributes(volumes)$anatIDs) hanat$Do(function(x) { From ec4be390d1769f7d5cf8170f4666332bf3845b98 Mon Sep 17 00:00:00 2001 From: nzxwang Date: Mon, 28 Jan 2019 17:00:27 -0500 Subject: [PATCH 31/41] warn the user of hierarhically processing NA volumes --- R/minc_hierarchical_anatomy.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/minc_hierarchical_anatomy.R b/R/minc_hierarchical_anatomy.R index b6b7250b..d711fd62 100644 --- a/R/minc_hierarchical_anatomy.R +++ b/R/minc_hierarchical_anatomy.R @@ -278,6 +278,10 @@ addVolumesToHierarchy <- function(hdefs, volumes){ stop("Your hierarchical definitions contain fewer leaves than regions in your volumes.\n", "Are you using the correct atlas labels?") } + if (any(is.na(volumes))) { + warning("At least one anatomical region has a value of NA.\n", + "That region's mean volume will be NA, and all of its parents too.") + } hanat <- Clone(hdefs) volLabels <- as.integer(attributes(volumes)$anatIDs) hanat$Do(function(x) { From 5aa1c6f5ac3c0f95388168002161734ac17095b4 Mon Sep 17 00:00:00 2001 From: nzxwang Date: Thu, 31 Jan 2019 14:40:20 -0500 Subject: [PATCH 32/41] revert the mincLm subsetting related changes as they belong in mincLm_subset brancH --- NAMESPACE | 1 - R/minc_anatomy.R | 2 +- R/minc_voxel_statistics.R | 8 ++++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 3a42d465..271266e1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,7 +1,6 @@ # Generated by roxygen2: do not edit by hand S3method("[",anatModel) -S3method("[",mincLm) S3method(AIC,anatModel) S3method(AIC,mincLm) S3method(AIC,vertexLm) diff --git a/R/minc_anatomy.R b/R/minc_anatomy.R index e85aa4e8..2960382a 100644 --- a/R/minc_anatomy.R +++ b/R/minc_anatomy.R @@ -418,7 +418,7 @@ print.anatModel <- function(x, n = min(6, nrow(x)), width = min(6, ncol(x)), ... } #' @export -`[.anatModel` <- function(x, i, j, drop = FALSE){ +`[.anatModel` <- function(x, i, j, drop = TRUE){ orig_x <- x mdrop <- missing(drop) n_args <- nargs() - !mdrop diff --git a/R/minc_voxel_statistics.R b/R/minc_voxel_statistics.R index d6375130..500c4c20 100644 --- a/R/minc_voxel_statistics.R +++ b/R/minc_voxel_statistics.R @@ -1256,7 +1256,7 @@ thresholds.minc_randomization <- `rownames<-`(paste0(probs * 100, "%")) } -#' @export -`[.mincLm` <- function(x,i,j, drop = FALSE){ - `[.anatModel`(x,i,j, drop) -} + + + + From 5f1f5f5429336eba3e412f318f5a9315e3a08a21 Mon Sep 17 00:00:00 2001 From: cfhammill Date: Thu, 7 Feb 2019 14:28:21 -0500 Subject: [PATCH 33/41] Improve parameter setting in 3D plots - Allows colour bar to be nudged - Allows plot pars to be passed down through 3D plot commands --- R/minc_vis3D.R | 50 ++++++++++++++++++++++++++++++------------- man/add_colour_bar.Rd | 13 +++++++++-- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/R/minc_vis3D.R b/R/minc_vis3D.R index 43e53564..6c0c1d95 100644 --- a/R/minc_vis3D.R +++ b/R/minc_vis3D.R @@ -273,6 +273,7 @@ add_opacity <- function(mesh, a_map, a_range = c(.5,1), a_default = 1){ #' @param colour_bar whether to draw a colour bar #' @param add whether or not to add this object to the current rgl device (if possible) #' defaults to opening a new device +#' @param par A list of plot parameters to pass to \link{add_colour_bar} #' @param ... additional arguments to \link{create_mesh} including but not limited #' to colour, specular, and add_normals #' @return invisibly returns the mesh object @@ -288,6 +289,7 @@ plot.bic_obj <- labels = FALSE, colour_bar = TRUE, add = FALSE, + par = list(), ...){ if(!add) rgl::open3d() @@ -318,7 +320,8 @@ plot.bic_obj <- palette = palette) mesh %>% rgl::shade3d(override = FALSE) - if(colour_bar && !is.null(colour_map)) mesh %>% add_colour_bar + if(colour_bar && !is.null(colour_map)) + do.call("add_colour_bar", c(list(mesh = mesh), par)) invisible(mesh) } @@ -366,6 +369,11 @@ plot.obj_mesh <- #' @param tpos2 the position for the top edge of the colour bar in fraction #' of the plot area. Only used in the symmetric case for the positive scale, #' defaults to .95 +#' @param nudge_title_y Offset text from the bottom of a colour bar by y, units are +#' in proportions of the colour bar length +#' @param nudge_title_x Offset text from the bottom of a colour bar by x, units are +#' in proportions of the colour bar width +#' @param ... extra parameters to pass to \code{plotrix::color.legend} and \code{text} #' @export add_colour_bar <- function(mesh , title = "" @@ -374,47 +382,54 @@ add_colour_bar <- function(mesh , bpos = NULL , tpos = NULL , bpos2 = NULL - , tpos2 = NULL){ + , tpos2 = NULL + , nudge_title_y = 0.5 + , nudge_title_x = 0.82 + , ... + ){ if(is.null(mesh$legend)) stop("Your mesh has no colour information") with(mesh$legend, { rgl::bgplot3d({ par(mar = c(4,8,4,2)) - + plot.new() if(!symmetric){ if(is.null(bpos)) bpos <- .25 if(is.null(tpos)) tpos <- .75 - text_h <- bpos + (tpos - bpos) * .5 - text_w <- rpos + (rpos - lpos) * .2 + text_h <- bpos + (tpos - bpos) * nudge_title_y + text_w <- rpos + (rpos - lpos) * nudge_title_x plotrix::color.legend(lpos, bpos, rpos, tpos, - colour_range, palette, gradient="y", align="rb") + colour_range, palette, gradient="y", align="rb", + ...) - text(text_w, text_h, labels=title, srt=-90) + text(text_w, text_h, labels=title, srt=-90, ...) } else { if(is.null(bpos)) bpos <- .05 if(is.null(tpos)) tpos <- .45 if(is.null(bpos2)) bpos2 <- .55 if(is.null(tpos2)) tpos2 <- .95 - text_h <- bpos + (tpos2 - bpos) * .5 - text_w <- rpos + (rpos - lpos) * .2 + text_h <- bpos + (tpos2 - bpos) * nudge_title_y + text_w <- rpos + (rpos - lpos) * nudge_title_x plotrix::color.legend(lpos, bpos, rpos, tpos, - -rev(colour_range), rev(palette$neg), gradient="y", align="rb") + -rev(colour_range), rev(palette$neg), gradient="y", align="rb", + ...) plotrix::color.legend(lpos, bpos2, rpos, tpos2, - colour_range, palette$pos, gradient="y", align="rb") - text(text_w, text_h, labels=title, srt=-90) + colour_range, palette$pos, gradient="y", align="rb", + ...) + text(text_w, text_h, labels=title, srt=-90, ...) } }) }) @@ -439,6 +454,7 @@ add_colour_bar <- function(mesh #' @param ... additonal parameters to be passed to \link{create_mesh} #' @param add_normals Whether or not to add normals to the surface objects, see \link{create_mesh} for #' details +#' @param par A list of plot parameters to pass to \link{add_colour_bar} #' @param plot_corners The coordinates in pixels for the top left and bottom right corners of the #' the rgl device. `c(lx, ly, rx, ry)` #' @param zoom A zoom factor to apply to each subplot. This is the inverse of what you might expect @@ -467,6 +483,7 @@ obj_montage <- function(left_obj, labels = FALSE, palette = heat.colors(255), symmetric = FALSE, + par = list(), ..., plot_corners = c(100, 100, 900, 900), zoom = 1, @@ -524,9 +541,12 @@ obj_montage <- function(left_obj, rgl::useSubscene3d(parent_scene) if(colour_bar){ - left_mesh %>% add_colour_bar(title = colour_title, - lpos = .40, - rpos = .46) + par$mesh <- left_mesh + par$title <- colour_title + par$lpos = .40 + par$rpos = .46 + + do.call("add_colour_bar", par) } if(!is.null(output)) rgl::snapshot3d(output) diff --git a/man/add_colour_bar.Rd b/man/add_colour_bar.Rd index bf032515..d0df78f5 100644 --- a/man/add_colour_bar.Rd +++ b/man/add_colour_bar.Rd @@ -4,8 +4,9 @@ \alias{add_colour_bar} \title{Add a colour bar for a mesh} \usage{ -add_colour_bar(mesh, title = "", lpos = 0.97, rpos = 0.99, - bpos = NULL, tpos = NULL, bpos2 = NULL, tpos2 = NULL) +add_colour_bar(mesh, title = "", lpos = 0.97, rpos = 0.99, bpos = NULL, + tpos = NULL, bpos2 = NULL, tpos2 = NULL, nudge_title_y = 0.5, + nudge_title_x = 0.82, ...) } \arguments{ \item{mesh}{A \code{obj_mesh} object created with \link{colour_mesh}} @@ -33,6 +34,14 @@ defaults to .55} \item{tpos2}{the position for the top edge of the colour bar in fraction of the plot area. Only used in the symmetric case for the positive scale, defaults to .95} + +\item{nudge_title_y}{Offset text from the bottom of a colour bar by y, units are +in proportions of the colour bar length} + +\item{nudge_title_x}{Offset text from the bottom of a colour bar by x, units are +in proportions of the colour bar width} + +\item{...}{extra parameters to pass to \code{plotrix::color.legend} and \code{text}} } \description{ Add a colour bar that corresponds to the colours in a given colourized mesh From 31275391539004f0249350d668a00492e176db4d Mon Sep 17 00:00:00 2001 From: cfhammill Date: Wed, 6 Mar 2019 14:08:45 -0500 Subject: [PATCH 34/41] Travis fix Bring in new versions of the minc-toolkit, the configs of these properly set MINC_PATH --- .travis.yml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7f926719..d205cc7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,9 +10,9 @@ sudo: required before_install: | if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then (cd ../ ; - wget http://packages.bic.mni.mcgill.ca/minc-toolkit/Debian/minc-toolkit-1.9.11-20160202-Ubuntu_14.04-x86_64.deb) - sudo dpkg -i ../minc-toolkit-1.9.11-20160202-Ubuntu_14.04-x86_64.deb - source /opt/minc-itk4/minc-toolkit-config.sh + wget http://packages.bic.mni.mcgill.ca/minc-toolkit/Debian/minc-toolkit-1.9.16-20180117-Ubuntu_14.04-x86_64.deb ) + sudo dpkg -i ../minc-toolkit-1.9.16-20180117-Ubuntu_14.04-x86_64.deb + source /opt/minc/1.9.16/minc-toolkit-config.sh fi if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then @@ -20,13 +20,11 @@ before_install: | ## mkdir $HOME/.R/; touch $HOME/.R/Makevars ## echo 'FLIBS=-L/usr/local/Cellar/gcc/5.3.0/lib/gcc/5' > $HOME/.R/Makevars (cd ../ ; - wget http://packages.bic.mni.mcgill.ca/minc-toolkit/MacOSX/minc-toolkit-1.9.11-20160202-Darwin-10.11-x86_64.dmg) - sudo hdiutil attach ../minc-toolkit-1.9.11-20160202-Darwin-10.11-x86_64.dmg - sudo installer -package /Volumes/minc-toolkit-1.9.11-20160202-Darwin-x86_64/minc-toolkit-1.9.11-20160202-Darwin-x86_64.pkg -target / - source /opt/minc-itk4/minc-toolkit-config.sh + wget http://packages.bic.mni.mcgill.ca/minc-toolkit/MacOSX/minc-toolkit-1.9.16-20180117-Darwin-10.8-x86_64.dmg) + sudo hdiutil attach ../minc-toolkit-1.9.16-20180117-Darwin-10.8-x86_64.dmg + sudo installer -package /Volumes/minc-toolkit-1.9.16-20180117-Darwin-x86_64/minc-toolkit-1.9.16-20180117-Darwin-x86_64.pkg -target / + source /opt/minc/1.9.16/minc-toolkit-config.sh fi repos: - bioCsoft: http://bioconductor.org/packages/3.5/bioc - - + bioCsoft: http://bioconductor.org/packages/3.8/bioc From 04287df4797d2cbb9a8da542db1555463fbc7efc Mon Sep 17 00:00:00 2001 From: cfhammill Date: Wed, 6 Mar 2019 15:02:48 -0500 Subject: [PATCH 35/41] Add documentation for column arguments and reroxygenize And fixes non-ascii characters in the effectsize code --- R/effectsize.R | 4 ++-- R/minc_vertex_statistics.R | 24 ++++++++++++++++-------- man/civet.CreateBrainViewFile.Rd | 4 ++-- man/civet.getFilename.Rd | 20 ++++++++++---------- man/colour_mesh.Rd | 5 ++--- man/hanatToVisGraph.Rd | 4 ++-- man/launch_shinyRMINC.Rd | 7 +++---- man/lut_to_palette.Rd | 4 ++-- man/map_to_colours.Rd | 5 ++--- man/mcMincApply.Rd | 7 +++---- man/minc.ray.trace.Rd | 5 ++--- man/mincApplyRCPP.Rd | 4 ++-- man/mincFDR.Rd | 4 ++-- man/mincImage.Rd | 4 ++-- man/mincLm.Rd | 4 ++-- man/mincPlotAnatAndStatsSlice.Rd | 11 +++++------ man/mincRandomize.Rd | 4 ++-- man/mincRayTraceStats.Rd | 6 +++--- man/mincSelectRandomVoxels.Rd | 3 +-- man/mincTFCE.Rd | 12 ++++++------ man/mincWriteVolume.Rd | 4 ++-- man/obj_montage.Rd | 6 ++++-- man/pMincApply.Rd | 3 +-- man/plot.bic_obj.Rd | 7 ++++--- man/qMincApply.Rd | 12 ++++++------ man/thresholds.Rd | 4 ++-- man/vertexAnova.Rd | 2 ++ man/vertexApply.Rd | 2 ++ man/vertexEffectSize.Rd | 2 +- man/vertexFindPeaks.Rd | 3 +-- man/vertexLm.Rd | 2 ++ man/vertexLmer.Rd | 4 +++- man/vertexLmerEstimateDF.Rd | 2 ++ man/vertexSummaries.Rd | 2 ++ man/vertexTFCE.Rd | 19 ++++++++++--------- 35 files changed, 115 insertions(+), 100 deletions(-) diff --git a/R/effectsize.R b/R/effectsize.R index 2494253e..fa84997b 100644 --- a/R/effectsize.R +++ b/R/effectsize.R @@ -5,7 +5,7 @@ #' @param buffer The results of a vertex/anat/mincLm run #' @param predictors A vector of factor predictor names. By default the effect size #' be computed for all treatment-coded factor columns. -#' @details This code implements the methods from Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x +#' @details This code implements the methods from Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591-05. https://doi.org/10.1111/j.1469-185X.2007.00027.x #' for computing effect size of group comparisons from a GLM. #' #' For now, interactions are explicitly excluded from being predictors. To get @@ -25,7 +25,7 @@ #' @export vertexEffectSize <- function(buffer, predictors = NULL) { - #Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x + #Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591-605. https://doi.org/10.1111/j.1469-185X.2007.00027.x #Original unbiased corrector from paper replaced with #unbiased corrector function J from https://en.wikipedia.org/wiki/Effect_size#Hedges'_g #Watch out for exploding gamma function diff --git a/R/minc_vertex_statistics.R b/R/minc_vertex_statistics.R index f166adbc..c5e2ea25 100644 --- a/R/minc_vertex_statistics.R +++ b/R/minc_vertex_statistics.R @@ -6,6 +6,7 @@ #' #' @param filenames Filenames of the vertex volumes across which to create the #' descriptive statistic. +#' @param column Which column to treat as the input from vertex files. #' @return \item{out}{The output will be a single vector containing as many #' elements as there are vertices in the input files.} #' @seealso vertexLm @@ -139,6 +140,7 @@ matrixApply <- function(mat, fun, ..., mask = NULL, parallel = NULL #' structure. Defaults to \link{simplify_masked} #' @param transpose Whether to alternatively transpose the vertex matrix and apply a function to #' each subject +#' @param column Which column to treat as the input from vertex files. #' @return The a matrix with a row of results for each vertex #' @examples #' \dontrun{ @@ -176,7 +178,8 @@ vertexApply <- function(filenames, fun, ..., mask = NULL, parallel = NULL #' \item{dimnames}{ names of the dimensions for the statistic matrix} #' \item{stat-type}{ types of statistic used} #' \item{df}{ degrees of freedom of each statistic} -#' } +#' } +#' @param column Which column to treat as the input from vertex files. #' @seealso mincAnova,anatAnova #' @examples #' \dontrun{ @@ -232,6 +235,7 @@ vertexAnova <- function(formula, data, subset=NULL, column=1) { #' so only the + operator may be used, and only two terms may appear on the RHS #' @param data a data.frame containing variables in formula #' @param subset rows to be used, by default all are used +#' @param column Which column to treat as the input from vertex files. #' @return Returns an object containing the R-Squared value,beta coefficients, F #' and t statistcs that can be passed directly into vertexFDR. #' @seealso mincLm,anatLm,vertexFDR @@ -325,6 +329,7 @@ vertexLm <- function(formula, data, subset=NULL, column=1 ) { #' an actual response variable. #' #' @inheritParams mincLmer +#' @param column Which column to treat as the input from vertex files. #' @details \code{vertexLmer}, like its relative \link{mincLmer} provides an interface to running #' linear mixed effects models at every vertex. Unlike standard linear models testing hypotheses #' in linear mixed effects models is more difficult, since the denominator degrees of freedom are @@ -338,7 +343,7 @@ vertexLm <- function(formula, data, subset=NULL, column=1 ) { #' @export vertexLmer <- function(formula, data, mask=NULL, parallel=NULL, - REML=TRUE, control=lmerControl(), start=NULL, + REML=TRUE, column = 1, control=lmerControl(), start=NULL, verbose=0L, safely = FALSE, summary_type = "fixef") { mc <- mcout <- match.call() @@ -389,11 +394,12 @@ vertexLmer <- out <- vertexApply(lmod$fr[,1] - , optimizer_fun - , mincLmerList = mincLmerList - , mask = mask - , summary_fun = summary_fun - , parallel = parallel) + , optimizer_fun + , mincLmerList = mincLmerList + , mask = mask + , column = column + , summary_fun = summary_fun + , parallel = parallel) ## Result post processing out[is.infinite(out)] <- 0 #zero out infinite values produced by vcov @@ -429,7 +435,8 @@ vertexLmer <- #' within the mask and the median DF returned for every variable. #' #' @param model the output of mincLmer -#' +#' @param column Which column to treat as the input from vertex files. +#' #' @return the same mincLmer model, now with degrees of freedom set #' #' @seealso \code{\link{mincLmer}} for mixed effects modelling, \code{\link{mincFDR}} @@ -526,6 +533,7 @@ vertexLmerEstimateDF <- #' an igraph graph object of surface created by \link{obj_to_graph}, or an adjacency list (see details). #' For the \code{matrix} and \link{vertexLm} cases, either a single surface object may be passed and #' used for each individual, or a vector of file names +#' @param column Which column to treat as the input from vertex files. #' @param nsteps The number of steps to discretize the TFCE computation over #' @inheritParams mincTFCE #' @param weights A weighting vector assigning area to vertices. The default varies by diff --git a/man/civet.CreateBrainViewFile.Rd b/man/civet.CreateBrainViewFile.Rd index e8d722b7..60bcbe5f 100644 --- a/man/civet.CreateBrainViewFile.Rd +++ b/man/civet.CreateBrainViewFile.Rd @@ -4,8 +4,8 @@ \alias{civet.CreateBrainViewFile} \title{Create a brain view file} \usage{ -civet.CreateBrainViewFile(dataFile, atlasFile, atlasVertices, - outputFileName, civetVersion = "1.1.12") +civet.CreateBrainViewFile(dataFile, atlasFile, atlasVertices, outputFileName, + civetVersion = "1.1.12") } \arguments{ \item{dataFile}{Either the name of a file with atlas labeling or an R array with atlas labeling} diff --git a/man/civet.getFilename.Rd b/man/civet.getFilename.Rd index 68009468..3f1741bd 100644 --- a/man/civet.getFilename.Rd +++ b/man/civet.getFilename.Rd @@ -41,17 +41,17 @@ civet.getFilenameCerebrumMask(scanID, baseDir, civetVersion = "1.1.9", civet.getFilenameSkullMask(scanID, baseDir, civetVersion = "1.1.9", fullPath = TRUE) -civet.getFilenameGrayMatterSurfaces(scanID, baseDir, - civetVersion = "1.1.9", fullPath = TRUE) +civet.getFilenameGrayMatterSurfaces(scanID, baseDir, civetVersion = "1.1.9", + fullPath = TRUE) -civet.getFilenameWhiteMatterSurfaces(scanID, baseDir, - civetVersion = "1.1.9", fullPath = TRUE) +civet.getFilenameWhiteMatterSurfaces(scanID, baseDir, civetVersion = "1.1.9", + fullPath = TRUE) civet.getFilenameMidSurfaces(scanID, baseDir, civetVersion = "1.1.9", fullPath = TRUE) -civet.getFilenamesCorticalThickness(scanID, baseDir, - civetVersion = "1.1.9", smoothing = "20mm", fullPath = TRUE) +civet.getFilenamesCorticalThickness(scanID, baseDir, civetVersion = "1.1.9", + smoothing = "20mm", fullPath = TRUE) civet.getFilenamesCorticalArea(scanID, baseDir, civetVersion = "1.1.9", smoothing = "40mm", fullPath = TRUE) @@ -59,14 +59,14 @@ civet.getFilenamesCorticalArea(scanID, baseDir, civetVersion = "1.1.9", civet.getFilenamesCorticalVolume(scanID, baseDir, civetVersion = "1.1.9", smoothing = "40mm", fullPath = TRUE) -civet.getFilenameMeanSurfaceCurvature(scanID, baseDir, - civetVersion = "1.1.9", fullPath = TRUE) +civet.getFilenameMeanSurfaceCurvature(scanID, baseDir, civetVersion = "1.1.9", + fullPath = TRUE) civet.getFilenameLinearTransform(scanID, baseDir, civetVersion = "1.1.9", fullPath = TRUE) -civet.getFilenameNonlinearTransform(scanID, baseDir, - civetVersion = "1.1.9", fullPath = TRUE) +civet.getFilenameNonlinearTransform(scanID, baseDir, civetVersion = "1.1.9", + fullPath = TRUE) } \arguments{ \item{scanID}{A string specifying the unique scan-id (and thus diff --git a/man/colour_mesh.Rd b/man/colour_mesh.Rd index 05344130..05c3648c 100644 --- a/man/colour_mesh.Rd +++ b/man/colour_mesh.Rd @@ -4,9 +4,8 @@ \alias{colour_mesh} \title{Colourize a mesh} \usage{ -colour_mesh(mesh, colour_map, colour_range = NULL, - colour_default = "grey", symmetric = NULL, labels = FALSE, - palette = heat.colors(255)) +colour_mesh(mesh, colour_map, colour_range = NULL, colour_default = "grey", + symmetric = NULL, labels = FALSE, palette = heat.colors(255)) } \arguments{ \item{mesh}{\link[rgl]{mesh3d} object ideally produced by \link{create_mesh}} diff --git a/man/hanatToVisGraph.Rd b/man/hanatToVisGraph.Rd index 6d41b0f8..912491cd 100644 --- a/man/hanatToVisGraph.Rd +++ b/man/hanatToVisGraph.Rd @@ -7,8 +7,8 @@ \usage{ hanatToVisGraph(hanatTree, colourVariable = "color_hex_triplet", colourScale = colorRampPalette(c("red", "yellow"))(255), - rColourScale = colorRampPalette(c("blue", "turquoise1"))(255), - low = NULL, high = NULL, symmetric = F, transparent = "#FDFDFD", + rColourScale = colorRampPalette(c("blue", "turquoise1"))(255), low = NULL, + high = NULL, symmetric = F, transparent = "#FDFDFD", edgeColourFromABI = F) hanatView(..., fontsize = 14, levelSeparation = 500) diff --git a/man/launch_shinyRMINC.Rd b/man/launch_shinyRMINC.Rd index 0669e45e..47a611ce 100644 --- a/man/launch_shinyRMINC.Rd +++ b/man/launch_shinyRMINC.Rd @@ -4,10 +4,9 @@ \alias{launch_shinyRMINC} \title{launch a shiny based inspector} \usage{ -launch_shinyRMINC(statsoutput, anatVol, volumes = NULL, - keepBetas = FALSE, plotcolumns = NULL, modelfunc = NULL, - singleStatType = NULL, fdr = NULL, anatLow = 700, - anatHigh = 1400) +launch_shinyRMINC(statsoutput, anatVol, volumes = NULL, keepBetas = FALSE, + plotcolumns = NULL, modelfunc = NULL, singleStatType = NULL, + fdr = NULL, anatLow = 700, anatHigh = 1400) } \arguments{ \item{statsoutput}{the output of mincLm, mincAnova, or mincLmer. Alternatively diff --git a/man/lut_to_palette.Rd b/man/lut_to_palette.Rd index e52f46ed..83e223c1 100644 --- a/man/lut_to_palette.Rd +++ b/man/lut_to_palette.Rd @@ -4,8 +4,8 @@ \alias{lut_to_palette} \title{A tool that returns a color function/palette from color lookup files} \usage{ -lut_to_palette(lookup_table = system.file("luts/spectral", package = - "RMINC"), alpha = 1) +lut_to_palette(lookup_table = system.file("luts/spectral", package = "RMINC"), + alpha = 1) } \arguments{ \item{lookup_table}{Either a path to the lookup table file, or the table itself} diff --git a/man/map_to_colours.Rd b/man/map_to_colours.Rd index 15914233..c5680144 100644 --- a/man/map_to_colours.Rd +++ b/man/map_to_colours.Rd @@ -4,9 +4,8 @@ \alias{map_to_colours} \title{Generate a vector of colours from a map} \usage{ -map_to_colours(colour_map, colour_range = NULL, - colour_default = "grey", symmetric = NULL, labels = FALSE, - palette = heat.colors(255)) +map_to_colours(colour_map, colour_range = NULL, colour_default = "grey", + symmetric = NULL, labels = FALSE, palette = heat.colors(255)) } \arguments{ \item{colour_map}{either a vector with a label/measure/statistic for every vertex diff --git a/man/mcMincApply.Rd b/man/mcMincApply.Rd index c270890e..ecbff18a 100644 --- a/man/mcMincApply.Rd +++ b/man/mcMincApply.Rd @@ -5,10 +5,9 @@ \title{Local multicore mincApply} \usage{ mcMincApply(filenames, fun, ..., mask = NULL, tinyMask = FALSE, - slab_sizes = NULL, temp_dir = getwd(), - cores = getOption("mc.cores", parallel::detectCores() - 1), - return_raw = FALSE, cleanup = TRUE, mask_vals = NULL, - collate = simplify2minc) + slab_sizes = NULL, temp_dir = getwd(), cores = getOption("mc.cores", + parallel::detectCores() - 1), return_raw = FALSE, cleanup = TRUE, + mask_vals = NULL, collate = simplify2minc) } \arguments{ \item{filenames}{Paths to the minc files to apply accross} diff --git a/man/minc.ray.trace.Rd b/man/minc.ray.trace.Rd index 973315f6..54c75d30 100644 --- a/man/minc.ray.trace.Rd +++ b/man/minc.ray.trace.Rd @@ -6,9 +6,8 @@ \usage{ minc.ray.trace(volume, output = "slice.rgb", size = c(400, 400), slice = list(pos = 0, wv = "w", axis = "z"), threshold = NULL, - colourmap = "-spectral", background = NULL, - background.threshold = NULL, background.colourmap = "-gray", - display = TRUE) + colourmap = "-spectral", background = NULL, background.threshold = NULL, + background.colourmap = "-gray", display = TRUE) } \arguments{ \item{volume}{The filename of a volume to render.} diff --git a/man/mincApplyRCPP.Rd b/man/mincApplyRCPP.Rd index 06b726d7..07d28a01 100644 --- a/man/mincApplyRCPP.Rd +++ b/man/mincApplyRCPP.Rd @@ -5,8 +5,8 @@ \title{Perform Arbitrary calculations on a collection of mincVolumes} \usage{ mincApplyRCPP(filenames, fun, ..., mask = NULL, maskval = NULL, - filter_masked = FALSE, slab_sizes = c(1, 1, 1), - return_indices = FALSE, collate = simplify2minc) + filter_masked = FALSE, slab_sizes = c(1, 1, 1), return_indices = FALSE, + collate = simplify2minc) } \arguments{ \item{filenames}{The name of the files to apply over} diff --git a/man/mincFDR.Rd b/man/mincFDR.Rd index dc0d31cd..4114bbee 100644 --- a/man/mincFDR.Rd +++ b/man/mincFDR.Rd @@ -10,8 +10,8 @@ \usage{ mincFDR(buffer, ...) -\method{mincFDR}{mincSingleDim}(buffer, df, mask = NULL, - method = "fdr", ...) +\method{mincFDR}{mincSingleDim}(buffer, df, mask = NULL, method = "fdr", + ...) \method{mincFDR}{mincLogLikRatio}(buffer, mask = NULL, ...) diff --git a/man/mincImage.Rd b/man/mincImage.Rd index 77d33818..af89ca2e 100644 --- a/man/mincImage.Rd +++ b/man/mincImage.Rd @@ -4,8 +4,8 @@ \alias{mincImage} \title{Plot a slice from a MINC volume} \usage{ -mincImage(volume, dimension = 2, slice = NULL, low = min(volume, - na.rm = TRUE), high = max(volume, na.rm = TRUE), reverse = FALSE, +mincImage(volume, dimension = 2, slice = NULL, low = min(volume, na.rm = + TRUE), high = max(volume, na.rm = TRUE), reverse = FALSE, underTransparent = FALSE, col = gray.colors(255), add = FALSE, ...) } \arguments{ diff --git a/man/mincLm.Rd b/man/mincLm.Rd index ca81c530..aba38fea 100644 --- a/man/mincLm.Rd +++ b/man/mincLm.Rd @@ -4,8 +4,8 @@ \alias{mincLm} \title{Linear model at Every Voxel} \usage{ -mincLm(formula, data = NULL, subset = NULL, mask = NULL, - maskval = NULL, parallel = NULL, cleanup = TRUE, +mincLm(formula, data = NULL, subset = NULL, mask = NULL, maskval = NULL, + parallel = NULL, cleanup = TRUE, conf_file = getOption("RMINC_BATCH_CONF")) } \arguments{ diff --git a/man/mincPlotAnatAndStatsSlice.Rd b/man/mincPlotAnatAndStatsSlice.Rd index 6b8d7d29..92b28bcc 100644 --- a/man/mincPlotAnatAndStatsSlice.Rd +++ b/man/mincPlotAnatAndStatsSlice.Rd @@ -4,12 +4,11 @@ \alias{mincPlotAnatAndStatsSlice} \title{Anatomy and Statistics Slice} \usage{ -mincPlotAnatAndStatsSlice(anatomy, statistics, slice = NULL, - dimension = 2, low = min(statistics, na.rm = TRUE), - high = max(statistics, na.rm = TRUE), anatLow = min(anatomy, na.rm = - TRUE), anatHigh = max(anatomy, na.rm = TRUE), symmetric = FALSE, - col = NULL, rcol = NULL, legend = NULL, acol = gray.colors(255, - start = 0), legendTextColour = "black") +mincPlotAnatAndStatsSlice(anatomy, statistics, slice = NULL, dimension = 2, + low = min(statistics, na.rm = TRUE), high = max(statistics, na.rm = TRUE), + anatLow = min(anatomy, na.rm = TRUE), anatHigh = max(anatomy, na.rm = + TRUE), symmetric = FALSE, col = NULL, rcol = NULL, legend = NULL, + acol = gray.colors(255, start = 0), legendTextColour = "black") } \arguments{ \item{anatomy}{A minc array of the anatomy volume to plot} diff --git a/man/mincRandomize.Rd b/man/mincRandomize.Rd index bf741656..63385893 100644 --- a/man/mincRandomize.Rd +++ b/man/mincRandomize.Rd @@ -11,8 +11,8 @@ mincRandomize(x, R = 500, alternative = c("two.sided", "greater"), conf_file = getOption("RMINC_BATCH_CONF")) \method{mincRandomize}{mincLm}(x, R = 500, alternative = c("two.sided", - "greater"), replace = FALSE, parallel = NULL, - columns = grep("tvalue-", colnames(x)), resources = list(), + "greater"), replace = FALSE, parallel = NULL, columns = grep("tvalue-", + colnames(x)), resources = list(), conf_file = getOption("RMINC_BATCH_CONF")) } \arguments{ diff --git a/man/mincRayTraceStats.Rd b/man/mincRayTraceStats.Rd index 4820d2d2..6924f2b2 100644 --- a/man/mincRayTraceStats.Rd +++ b/man/mincRayTraceStats.Rd @@ -9,9 +9,9 @@ mincRayTraceStats(v, anatomy.volume, statsbuffer, column = 1, image.max = 4000, output.width = 800, output.height = 800, place.inset = FALSE, inset = NULL, stats.largest.pos = NULL, stats.largest.neg = NULL, caption = "t-statistic", fdr = NULL, - slice.direction = "transverse", - outputfile = "ray_trace_crosshair.png", show.pos.and.neg = FALSE, - display = TRUE, clobber = NULL, tmpdir = "/tmp") + slice.direction = "transverse", outputfile = "ray_trace_crosshair.png", + show.pos.and.neg = FALSE, display = TRUE, clobber = NULL, + tmpdir = "/tmp") } \arguments{ \item{v}{A mincVoxel indicating the voxel of interest.} diff --git a/man/mincSelectRandomVoxels.Rd b/man/mincSelectRandomVoxels.Rd index 5d04ab44..ae68d4b8 100644 --- a/man/mincSelectRandomVoxels.Rd +++ b/man/mincSelectRandomVoxels.Rd @@ -4,8 +4,7 @@ \alias{mincSelectRandomVoxels} \title{selects a few random indices from a volume} \usage{ -mincSelectRandomVoxels(volumeFileName, nvoxels = 50, convert = TRUE, - ...) +mincSelectRandomVoxels(volumeFileName, nvoxels = 50, convert = TRUE, ...) } \arguments{ \item{volumeFileName}{the filename for a MINC volume} diff --git a/man/mincTFCE.Rd b/man/mincTFCE.Rd index bd5ecc27..ebd67452 100644 --- a/man/mincTFCE.Rd +++ b/man/mincTFCE.Rd @@ -12,15 +12,15 @@ mincTFCE(x, ...) \method{mincTFCE}{mincSingleDim}(x, d = 0.1, E = 0.5, H = 2, side = c("both", "positive", "negative"), output_file = NULL, - keep = is.null(output_file), - conf_file = getOption("RMINC_BATCH_CONF"), ...) + keep = is.null(output_file), conf_file = getOption("RMINC_BATCH_CONF"), + ...) -\method{mincTFCE}{matrix}(x, d = 0.1, E = 0.5, H = 2, - side = c("both", "positive", "negative"), like_volume, ...) +\method{mincTFCE}{matrix}(x, d = 0.1, E = 0.5, H = 2, side = c("both", + "positive", "negative"), like_volume, ...) \method{mincTFCE}{mincMultiDim}(x, d = 0.1, E = 0.5, H = 2, - side = c("both", "positive", "negative"), - like_volume = likeVolume(x), ...) + side = c("both", "positive", "negative"), like_volume = likeVolume(x), + ...) \method{mincTFCE}{mincLm}(x, R = 500, alternative = c("two.sided", "greater"), d = 0.1, E = 0.5, H = 2, side = c("both", "positive", diff --git a/man/mincWriteVolume.Rd b/man/mincWriteVolume.Rd index 493b3a50..8d482e4f 100644 --- a/man/mincWriteVolume.Rd +++ b/man/mincWriteVolume.Rd @@ -12,8 +12,8 @@ mincWriteVolume(buffer, ...) \method{mincWriteVolume}{mincSingleDim}(buffer, output.filename, clobber = NULL, ...) -\method{mincWriteVolume}{mincMultiDim}(buffer, output.filename, - column = 1, like.filename = NULL, clobber = NULL, ...) +\method{mincWriteVolume}{mincMultiDim}(buffer, output.filename, column = 1, + like.filename = NULL, clobber = NULL, ...) \method{mincWriteVolume}{default}(buffer, output.filename, like.filename, clobber = NULL, ...) diff --git a/man/obj_montage.Rd b/man/obj_montage.Rd index 8173d04a..058613bf 100644 --- a/man/obj_montage.Rd +++ b/man/obj_montage.Rd @@ -7,8 +7,8 @@ obj_montage(left_obj, right_obj, left_map, right_map, output = NULL, colour_map, colour_range = NULL, colour_default = "grey", colour_bar = TRUE, labels = FALSE, palette = heat.colors(255), - symmetric = FALSE, ..., plot_corners = c(100, 100, 900, 900), - zoom = 1, add_normals = TRUE, colour_title = "", + symmetric = FALSE, par = list(), ..., plot_corners = c(100, 100, 900, + 900), zoom = 1, add_normals = TRUE, colour_title = "", close_on_output = TRUE) } \arguments{ @@ -41,6 +41,8 @@ allowable labels/measures/statistics to be includedon the surface} \item{symmetric}{Whether to have a positive and negative colour scale (not yet implemented)} +\item{par}{A list of plot parameters to pass to \link{add_colour_bar}} + \item{...}{additonal parameters to be passed to \link{create_mesh}} \item{plot_corners}{The coordinates in pixels for the top left and bottom right corners of the diff --git a/man/pMincApply.Rd b/man/pMincApply.Rd index 98a63eb2..fc490117 100644 --- a/man/pMincApply.Rd +++ b/man/pMincApply.Rd @@ -10,8 +10,7 @@ pMincApply(filenames, fun, ..., mask = NULL, tinyMask = FALSE, walltime = NULL, workers = batches, temp_dir = getwd(), cleanup = TRUE, collate = simplify2minc, conf_file = getOption("RMINC_BATCH_CONF"), - registry_name = new_file("pMincApply_registry"), - registry_dir = getwd()) + registry_name = new_file("pMincApply_registry"), registry_dir = getwd()) } \arguments{ \item{filenames}{Paths to the minc files to be applied accross} diff --git a/man/plot.bic_obj.Rd b/man/plot.bic_obj.Rd index a80a66e5..b034ca6a 100644 --- a/man/plot.bic_obj.Rd +++ b/man/plot.bic_obj.Rd @@ -5,9 +5,8 @@ \title{Plot a BIC obj} \usage{ \method{plot}{bic_obj}(x, colour_map = NULL, colour_range = NULL, - colour_default = "grey", symmetric = FALSE, - palette = heat.colors(255), labels = FALSE, colour_bar = TRUE, - add = FALSE, ...) + colour_default = "grey", symmetric = FALSE, palette = heat.colors(255), + labels = FALSE, colour_bar = TRUE, add = FALSE, par = list(), ...) } \arguments{ \item{x}{A \code{bic_obj} probably created by \link{read_obj}} @@ -33,6 +32,8 @@ allowable labels/measures/statistics to be includedon the surface} \item{add}{whether or not to add this object to the current rgl device (if possible) defaults to opening a new device} +\item{par}{A list of plot parameters to pass to \link{add_colour_bar}} + \item{...}{additional arguments to \link{create_mesh} including but not limited to colour, specular, and add_normals} } diff --git a/man/qMincApply.Rd b/man/qMincApply.Rd index 747685f1..4bb87433 100644 --- a/man/qMincApply.Rd +++ b/man/qMincApply.Rd @@ -10,13 +10,13 @@ qMincApply(filenames, fun, ..., mask = NULL, batches = 4, tinyMask = FALSE, slab_sizes = NULL, resources = list(), packages = c("RMINC"), registry_dir = getwd(), - registry_name = "qMincApply_registry", temp_dir = getwd(), - cores = 1, wait = TRUE, cleanup = TRUE, clobber = FALSE, - collate = simplify2minc, conf_file = getOption("RMINC_BATCH_CONF")) + registry_name = "qMincApply_registry", temp_dir = getwd(), cores = 1, + wait = TRUE, cleanup = TRUE, clobber = FALSE, collate = simplify2minc, + conf_file = getOption("RMINC_BATCH_CONF")) -qMincRegistry(registry_name = "qMincApply_registry", - packages = c("RMINC"), registry_dir = getwd(), clobber = FALSE, - resources = list(), conf_file = getOption("RMINC_BATCH_CONF")) +qMincRegistry(registry_name = "qMincApply_registry", packages = c("RMINC"), + registry_dir = getwd(), clobber = FALSE, resources = list(), + conf_file = getOption("RMINC_BATCH_CONF")) qMincMap(registry, filenames, fun, ..., mask = NULL, slab_sizes = NULL, batches = 4, tinyMask = FALSE, temp_dir = getwd(), cores = 1) diff --git a/man/thresholds.Rd b/man/thresholds.Rd index 4523b193..836a72fc 100644 --- a/man/thresholds.Rd +++ b/man/thresholds.Rd @@ -10,8 +10,8 @@ thresholds(x, ...) \method{thresholds}{mincQvals}(x, ...) -\method{thresholds}{minc_randomization}(x, probs = c(0.01, 0.05, 0.1, - 0.2), ...) +\method{thresholds}{minc_randomization}(x, probs = c(0.01, 0.05, 0.1, 0.2), + ...) } \arguments{ \item{x}{A \code{mincQvals} object, typically computed with \code{mincFDR} or a diff --git a/man/vertexAnova.Rd b/man/vertexAnova.Rd index 8003684e..d98a1b40 100644 --- a/man/vertexAnova.Rd +++ b/man/vertexAnova.Rd @@ -12,6 +12,8 @@ vertexAnova(formula, data, subset = NULL, column = 1) \item{data}{a data.frame containing variables in formula} \item{subset}{rows to be used, by default all are used} + +\item{column}{Which column to treat as the input from vertex files.} } \value{ Returns an array with the F-statistic for each model specified by formula with the following attributes: diff --git a/man/vertexApply.Rd b/man/vertexApply.Rd index 8544cf2d..52f20178 100644 --- a/man/vertexApply.Rd +++ b/man/vertexApply.Rd @@ -27,6 +27,8 @@ structure. Defaults to \link{simplify_masked}} \item{transpose}{Whether to alternatively transpose the vertex matrix and apply a function to each subject} + +\item{column}{Which column to treat as the input from vertex files.} } \value{ The a matrix with a row of results for each vertex diff --git a/man/vertexEffectSize.Rd b/man/vertexEffectSize.Rd index dce2f7b1..10ca80d5 100644 --- a/man/vertexEffectSize.Rd +++ b/man/vertexEffectSize.Rd @@ -27,7 +27,7 @@ Takes the output of a minc modelling function and computes the unbiased hedges g* and variance of hedges g* } \details{ -This code implements the methods from Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591–605. https://doi.org/10.1111/j.1469-185X.2007.00027.x +This code implements the methods from Nakagawa, S., Cuthill, I.C., 2007. Effect size, confidence interval and statistical significance: a practical guide for biologists. Biol. Rev. Camb. Philos. Soc. 82, 591-05. https://doi.org/10.1111/j.1469-185X.2007.00027.x for computing effect size of group comparisons from a GLM. For now, interactions are explicitly excluded from being predictors. To get diff --git a/man/vertexFindPeaks.Rd b/man/vertexFindPeaks.Rd index 22c865a3..064e2184 100644 --- a/man/vertexFindPeaks.Rd +++ b/man/vertexFindPeaks.Rd @@ -5,8 +5,7 @@ \title{Vertex find peaks} \usage{ vertexFindPeaks(data_map, graph, mindist = 1, direction = c("both", - "positive", "negative"), threshold = 0, output = c("mask", - "indices")) + "positive", "negative"), threshold = 0, output = c("mask", "indices")) } \arguments{ \item{data_map}{A vector or text file of values to search for peaks} diff --git a/man/vertexLm.Rd b/man/vertexLm.Rd index 110075e7..465f7e1f 100644 --- a/man/vertexLm.Rd +++ b/man/vertexLm.Rd @@ -13,6 +13,8 @@ so only the + operator may be used, and only two terms may appear on the RHS} \item{data}{a data.frame containing variables in formula} \item{subset}{rows to be used, by default all are used} + +\item{column}{Which column to treat as the input from vertex files.} } \value{ Returns an object containing the R-Squared value,beta coefficients, F diff --git a/man/vertexLmer.Rd b/man/vertexLmer.Rd index d3792c41..68cf15c2 100644 --- a/man/vertexLmer.Rd +++ b/man/vertexLmer.Rd @@ -5,7 +5,7 @@ \title{Vertex Mixed Effects Models} \usage{ vertexLmer(formula, data, mask = NULL, parallel = NULL, REML = TRUE, - control = lmerControl(), start = NULL, verbose = 0L, + column = 1, control = lmerControl(), start = NULL, verbose = 0L, safely = FALSE, summary_type = "fixef") } \arguments{ @@ -24,6 +24,8 @@ Leaving this argument NULL runs sequentially and may take a long time.} \item{REML}{whether to use use Restricted Maximum Likelihood or Maximum Likelihood} +\item{column}{Which column to treat as the input from vertex files.} + \item{control}{lmer control function} \item{start}{lmer start function} diff --git a/man/vertexLmerEstimateDF.Rd b/man/vertexLmerEstimateDF.Rd index a8895c17..4adb2e27 100644 --- a/man/vertexLmerEstimateDF.Rd +++ b/man/vertexLmerEstimateDF.Rd @@ -8,6 +8,8 @@ vertexLmerEstimateDF(model, column = 1) } \arguments{ \item{model}{the output of mincLmer} + +\item{column}{Which column to treat as the input from vertex files.} } \value{ the same mincLmer model, now with degrees of freedom set diff --git a/man/vertexSummaries.Rd b/man/vertexSummaries.Rd index 4d77f268..245f0893 100644 --- a/man/vertexSummaries.Rd +++ b/man/vertexSummaries.Rd @@ -19,6 +19,8 @@ vertexSd(filenames, column = 1) \arguments{ \item{filenames}{Filenames of the vertex volumes across which to create the descriptive statistic.} + +\item{column}{Which column to treat as the input from vertex files.} } \value{ \item{out}{The output will be a single vector containing as many diff --git a/man/vertexTFCE.Rd b/man/vertexTFCE.Rd index 271ce9e5..55d6173c 100644 --- a/man/vertexTFCE.Rd +++ b/man/vertexTFCE.Rd @@ -10,21 +10,20 @@ \usage{ vertexTFCE(x, ...) -\method{vertexTFCE}{numeric}(x, surface, E = 0.5, H = 2, - nsteps = 100, side = c("both", "positive", "negative"), - weights = NULL, ...) +\method{vertexTFCE}{numeric}(x, surface, E = 0.5, H = 2, nsteps = 100, + side = c("both", "positive", "negative"), weights = NULL, ...) \method{vertexTFCE}{matrix}(x, surface, E = 0.5, H = 2, nsteps = 100, side = c("both", "positive", "negative"), weights = NULL, ...) \method{vertexTFCE}{vertexLm}(x, surface, R = 500, - alternative = c("two.sided", "greater"), E = 0.5, H = 2, - nsteps = 100, weights = NULL, side = c("both", "positive", - "negative"), replace = FALSE, parallel = NULL, ...) + alternative = c("two.sided", "greater"), E = 0.5, H = 2, nsteps = 100, + weights = NULL, side = c("both", "positive", "negative"), + replace = FALSE, parallel = NULL, ...) -\method{vertexTFCE}{character}(x, surface, E = 0.5, H = 2, - nsteps = 100, side = c("both", "positive", "negative"), - weights = NULL, column = 1, ...) +\method{vertexTFCE}{character}(x, surface, E = 0.5, H = 2, nsteps = 100, + side = c("both", "positive", "negative"), weights = NULL, column = 1, + ...) } \arguments{ \item{x}{A numeric vector, a filepath to a set of values, @@ -62,6 +61,8 @@ replacement)} first element is "local" the computation will be run via the parallel package, otherwise it will be computed using batchtools, see \link{pMincApply} for details. The element should be numeric indicating the number of jobs to split the computation into.} + +\item{column}{Which column to treat as the input from vertex files.} } \value{ The behaviour of \code{vertexTFCE} is to perform cluster free enhancement on a object, From 44d07d941fa6f68ef8b3d0152b09bdcce1662ddf Mon Sep 17 00:00:00 2001 From: cfhammill Date: Wed, 6 Mar 2019 16:22:47 -0500 Subject: [PATCH 36/41] Fix missing newline problem in read_obj --- R/minc_vis3D.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/minc_vis3D.R b/R/minc_vis3D.R index 6c0c1d95..d4d3da2b 100644 --- a/R/minc_vis3D.R +++ b/R/minc_vis3D.R @@ -18,7 +18,9 @@ #' @export read_obj <- function(bic_obj, use_civet_triangles = FALSE) { - lines <- readLines(bic_obj) + lines <- readLines(bic_obj) + if(lines[[length(lines)]] != "") + lines <- c(lines, "") general_info <- lines[1] From 0c6324b0ec9130744368fc2a04f40b282b11183b Mon Sep 17 00:00:00 2001 From: cfhammill Date: Wed, 6 Mar 2019 16:57:20 -0500 Subject: [PATCH 37/41] Add column check to hanatToVolume Fixes #242 --- R/minc_hierarchical_anatomy.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/minc_hierarchical_anatomy.R b/R/minc_hierarchical_anatomy.R index d711fd62..f96cbb36 100644 --- a/R/minc_hierarchical_anatomy.R +++ b/R/minc_hierarchical_anatomy.R @@ -15,6 +15,9 @@ #' low=1, high=10, symmetric = F, begin=50, end=-50) #' } hanatToVolume <- function(anatTree, labelVolume, column) { + if(is.null(getElement(anatTree, column))) + stop(column, " doesn't seem to be in your anatomy tree") + out <- array(0, dim=dim(labelVolume)) labels <- c() values <- c() From 8d9deb8865fd0b232e39582d843d1bbb1f0d6777 Mon Sep 17 00:00:00 2001 From: cfhammill Date: Wed, 13 Mar 2019 15:42:49 -0400 Subject: [PATCH 38/41] Better layouts for rgl figures --- R/minc_vis3D.R | 29 +++++++++++++++++++++-------- man/add_colour_bar.Rd | 4 +++- man/obj_montage.Rd | 9 ++++++++- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/R/minc_vis3D.R b/R/minc_vis3D.R index d4d3da2b..3c1ad6ff 100644 --- a/R/minc_vis3D.R +++ b/R/minc_vis3D.R @@ -375,6 +375,7 @@ plot.obj_mesh <- #' in proportions of the colour bar length #' @param nudge_title_x Offset text from the bottom of a colour bar by x, units are #' in proportions of the colour bar width +#' @param vertical whether to use a vertical or horizontal layout for the colour bar #' @param ... extra parameters to pass to \code{plotrix::color.legend} and \code{text} #' @export add_colour_bar <- function(mesh @@ -387,13 +388,15 @@ add_colour_bar <- function(mesh , tpos2 = NULL , nudge_title_y = 0.5 , nudge_title_x = 0.82 + , vertical = TRUE , ... ){ if(is.null(mesh$legend)) stop("Your mesh has no colour information") with(mesh$legend, { rgl::bgplot3d({ par(mar = c(4,8,4,2)) - + + bar_orientation <- `if`(vertical, "y", "x") plot.new() if(!symmetric){ if(is.null(bpos)) bpos <- .25 @@ -406,7 +409,7 @@ add_colour_bar <- function(mesh bpos, rpos, tpos, - colour_range, palette, gradient="y", align="rb", + colour_range, palette, gradient=bar_orientation, align="rb", ...) text(text_w, text_h, labels=title, srt=-90, ...) @@ -423,13 +426,13 @@ add_colour_bar <- function(mesh bpos, rpos, tpos, - -rev(colour_range), rev(palette$neg), gradient="y", align="rb", + -rev(colour_range), rev(palette$neg), gradient=bar_orientation, align="rb", ...) plotrix::color.legend(lpos, bpos2, rpos, tpos2, - colour_range, palette$pos, gradient="y", align="rb", + colour_range, palette$pos, gradient=bar_orientation, align="rb", ...) text(text_w, text_h, labels=title, srt=-90, ...) } @@ -459,11 +462,14 @@ add_colour_bar <- function(mesh #' @param par A list of plot parameters to pass to \link{add_colour_bar} #' @param plot_corners The coordinates in pixels for the top left and bottom right corners of the #' the rgl device. `c(lx, ly, rx, ry)` +#' @param vertical Whether to use a vertical (default) or horizontal colour bar. #' @param zoom A zoom factor to apply to each subplot. This is the inverse of what you might expect #' for consistency with rgl. zoom > 1 zooms out, zoom < zooms in. #' @param colour_title legend title for the colour bar if requested #' @param close_on_output Whether or not to close the output after taking a snapshot, defaults to #' TRUE +#' @param layout A function to generate an rgl subscene layout, generated with +#' mfrow3d or layout3d. The function should take no arguments (a thunk). #' @details #' This function is designed to do a simple 6 angle plot for statistic maps of the left and right #' hemispheres of subject's brain. It defaults to leaving the rgl device open so that you can @@ -486,6 +492,11 @@ obj_montage <- function(left_obj, palette = heat.colors(255), symmetric = FALSE, par = list(), + vertical = TRUE, + layout = + `if`(vertical, + function() rgl::mfrow3d(3,2, byrow = TRUE), + function() rgl::mfrow3d(2,3, byrow = FALSE)), ..., plot_corners = c(100, 100, 900, 900), zoom = 1, @@ -525,8 +536,9 @@ obj_montage <- function(left_obj, rgl::par3d(viewport = c(0,0,plot_corners[3] - plot_corners[1], plot_corners[4] - plot_corners[2])) parent_scene <- rgl::currentSubscene3d() + subscenes <- match.fun(layout)() - subscenes <- rgl::mfrow3d(3,2) + left_or_right <- rep(c("left", "right"), 3) mapply(function(subscene, view_matrix, hemisphere){ @@ -544,9 +556,10 @@ obj_montage <- function(left_obj, if(colour_bar){ par$mesh <- left_mesh - par$title <- colour_title - par$lpos = .40 - par$rpos = .46 + if(is.null(par$title)) par$title <- colour_title + if(is.null(par$lpos)) par$lpos = .40 + if(is.null(par$rpos)) par$lpos = .46 + par$vertical <- vertical do.call("add_colour_bar", par) } diff --git a/man/add_colour_bar.Rd b/man/add_colour_bar.Rd index d0df78f5..e0c37d55 100644 --- a/man/add_colour_bar.Rd +++ b/man/add_colour_bar.Rd @@ -6,7 +6,7 @@ \usage{ add_colour_bar(mesh, title = "", lpos = 0.97, rpos = 0.99, bpos = NULL, tpos = NULL, bpos2 = NULL, tpos2 = NULL, nudge_title_y = 0.5, - nudge_title_x = 0.82, ...) + nudge_title_x = 0.82, vertical = TRUE, ...) } \arguments{ \item{mesh}{A \code{obj_mesh} object created with \link{colour_mesh}} @@ -41,6 +41,8 @@ in proportions of the colour bar length} \item{nudge_title_x}{Offset text from the bottom of a colour bar by x, units are in proportions of the colour bar width} +\item{vertical}{whether to use a vertical or horizontal layout for the colour bar} + \item{...}{extra parameters to pass to \code{plotrix::color.legend} and \code{text}} } \description{ diff --git a/man/obj_montage.Rd b/man/obj_montage.Rd index 058613bf..33f65908 100644 --- a/man/obj_montage.Rd +++ b/man/obj_montage.Rd @@ -7,7 +7,9 @@ obj_montage(left_obj, right_obj, left_map, right_map, output = NULL, colour_map, colour_range = NULL, colour_default = "grey", colour_bar = TRUE, labels = FALSE, palette = heat.colors(255), - symmetric = FALSE, par = list(), ..., plot_corners = c(100, 100, 900, + symmetric = FALSE, par = list(), vertical = TRUE, layout = if + (vertical) function() rgl::mfrow3d(3, 2, byrow = TRUE) else function() + rgl::mfrow3d(2, 3, byrow = FALSE), ..., plot_corners = c(100, 100, 900, 900), zoom = 1, add_normals = TRUE, colour_title = "", close_on_output = TRUE) } @@ -43,6 +45,11 @@ allowable labels/measures/statistics to be includedon the surface} \item{par}{A list of plot parameters to pass to \link{add_colour_bar}} +\item{vertical}{Whether to use a vertical (default) or horizontal colour bar.} + +\item{layout}{A function to generate an rgl subscene layout, generated with +mfrow3d or layout3d. The function should take no arguments (a thunk).} + \item{...}{additonal parameters to be passed to \link{create_mesh}} \item{plot_corners}{The coordinates in pixels for the top left and bottom right corners of the From 097339ce11021edef99178c70ee39e6715ae010a Mon Sep 17 00:00:00 2001 From: cfhammill Date: Mon, 18 Mar 2019 16:56:59 -0400 Subject: [PATCH 39/41] Add vertexAtlasApply Addresses #163 --- NAMESPACE | 1 + R/minc_vertex_statistics.R | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 271266e1..01426338 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -204,6 +204,7 @@ export(thresholds) export(verboseRun) export(vertexAnova) export(vertexApply) +export(vertexAtlasApply) export(vertexEffectSize) export(vertexFDR) export(vertexFindPeaks) diff --git a/R/minc_vertex_statistics.R b/R/minc_vertex_statistics.R index c5e2ea25..4b3ec5a9 100644 --- a/R/minc_vertex_statistics.R +++ b/R/minc_vertex_statistics.R @@ -165,6 +165,33 @@ vertexApply <- function(filenames, fun, ..., mask = NULL, parallel = NULL results } +#' Apply a structure summary function across vertices +#' +#' This is a wrapper around vertexApply with `transpose` set to `TRUE` +#' and `fun` wrapped in with `tapply` over atlas. +#' +#' @inheritParams vertexApply +#' @param atlas The atlas to use to summarize vertices. +#' @return The a matrix with a row of results for each structure +#' @export +vertexAtlasApply <- function(filenames, atlas, fun, ..., mask = NULL + , parallel = NULL, collate = simplify_masked + , column = 1, atlas_column = 1){ + + if(is.character(atlas) && length(atlas) == 1) + atlas <- extract_column(atlas, atlas_column) + + fun <- match.fun(fun) + wrapped_fun <- function(x, atlas, ...){ + tapply(x, list(atlas), fun, ...) + } + + t( + vertexApply(filenames, wrapped_fun, atlas = atlas, ..., mask = mask + , transpose = TRUE, parallel = parallel, collate = collate + , column = column)) +} + #' Performs ANOVA on each vertex point specified #' @param formula a model formula From 51286301a10dfbb32bc3549eff1f8923d1ada4a0 Mon Sep 17 00:00:00 2001 From: cfhammill Date: Mon, 18 Mar 2019 17:01:01 -0400 Subject: [PATCH 40/41] Update news for release --- NEWS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/NEWS b/NEWS index 0accd3c4..fbfcad70 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,14 @@ New in Version 1.5.*.* ======================= +2.2 +-- +- Improvements to vertex code (thanks @vfonov), now can + read single columns from vertex data files +- Hedges G effect sizes (thanks @gdevenyi), currently + for (minc/vertex/anat)Lm +- Better cortical figure layouting +- vertexAtlasApply for wrapping a common `tapply` pattern. + 2.1 -- - Fix resource passing in mincLmer From 75bc2effd54bdd0e631a429218bbd25aa437f64b Mon Sep 17 00:00:00 2001 From: cfhammill Date: Tue, 19 Mar 2019 10:48:12 -0400 Subject: [PATCH 41/41] Add vertexAtlasApply documentation --- man/vertexAtlasApply.Rd | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 man/vertexAtlasApply.Rd diff --git a/man/vertexAtlasApply.Rd b/man/vertexAtlasApply.Rd new file mode 100644 index 00000000..f0a18e60 --- /dev/null +++ b/man/vertexAtlasApply.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/minc_vertex_statistics.R +\name{vertexAtlasApply} +\alias{vertexAtlasApply} +\title{Apply a structure summary function across vertices} +\usage{ +vertexAtlasApply(filenames, atlas, fun, ..., mask = NULL, parallel = NULL, + collate = simplify_masked, column = 1, atlas_column = 1) +} +\arguments{ +\item{filenames}{vertex file names} + +\item{atlas}{The atlas to use to summarize vertices.} + +\item{fun}{A function to be applied to each vertex} + +\item{...}{additional arguments to \code{fun}} + +\item{mask}{A vector of filename indicating a vertex mask (\code{fun} is applied to all vertices +where mask is greater than .5)} + +\item{parallel}{A two component vector indicating how to parallelize the computation. If the +first element is "local" the computation will be run via the parallel package, otherwise it will +be computed using batchtools, see \link{pMincApply} for details. The element should be numeric +indicating the number of jobs to split the computation into.} + +\item{collate}{A function to reduce the (potentially masked) list of results into a nice +structure. Defaults to \link{simplify_masked}} + +\item{column}{Which column to treat as the input from vertex files.} +} +\value{ +The a matrix with a row of results for each structure +} +\description{ +This is a wrapper around vertexApply with `transpose` set to `TRUE` +and `fun` wrapped in with `tapply` over atlas. +}