Skip to content

Commit feadeaf

Browse files
authored
Merge pull request #29 from slamballais/fix_filenames
0.8.4: added file_out_tree
2 parents 2b20ca8 + e7adb17 commit feadeaf

File tree

10 files changed

+48
-34
lines changed

10 files changed

+48
-34
lines changed

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
S3method(formula,vw_fastlm)
43
S3method(hist,vw)
54
S3method(nobs,vw_fastlm)
65
S3method(print,vw)
@@ -15,6 +14,7 @@ export(fbm_row_is_0)
1514
export(fbm_row_mean)
1615
export(fbm_row_sd)
1716
export(fbm_row_sum)
17+
export(formula.vw_fastlm)
1818
export(freeview)
1919
export(imp2list)
2020
export(load.annot)

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* Fixed that the model output files (p.mgh, t.mgh, etc) also contained the mcz threshold (e.g. cache.th30).
55
* Lots of comments removed/modified, and code was cleaned up a bit
66

7+
## Minor Tweaks
8+
* Added the `file_out_tree` argument, which controls whether output files also contain the full project name. By default, it is the inverse of `dir_out_tree`.
9+
710
# QDECR 0.8.3
811

912
## Minor tweaks

R/qdecr.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ qdecr <- function(id,
4343
dir_tmp = dir_out,
4444
dir_out,
4545
dir_out_tree = TRUE,
46+
file_out_tree = !dir_out_tree,
4647
clean_up = TRUE,
4748
clean_up_bm = TRUE,
4849
clobber = FALSE,
@@ -72,7 +73,7 @@ qdecr <- function(id,
7273
measure <- match.arg(measure)
7374
hemi <- match.arg(hemi)
7475
model <- match.arg(model)
75-
76+
7677
# Check margs
7778
if (is.null(margs)) stop("`margs` is not defined, so no model can be run.")
7879
margs <- if (model == "default") qdecr_setnames(margs, deparse(margs[[1]])) else qdecr_setnames(margs, model)
@@ -88,7 +89,7 @@ qdecr <- function(id,
8889
md <- imp2list(data)
8990

9091
# Assemble and check input arguments
91-
vw$input <- qdecr_check(id, md, margs, hemi, vertex, measure, model, target, project, dir_out_tree, clobber, fwhm, n_cores, prep_fun)
92+
vw$input <- qdecr_check(id, md, margs, hemi, vertex, measure, model, target, project, dir_out_tree, clobber, fwhm, n_cores, prep_fun, file_out_tree)
9293
vw$mask <- qdecr_check_mask(mask, mask_path)
9394
vw$paths <- check_paths(vw, dir_tmp, dir_subj, dir_out, dir_fshome, mask_path)
9495
mcz_thr <- check_mcz_thr(mcz_thr)
@@ -168,13 +169,13 @@ qdecr <- function(id,
168169
# Run clusterwise and move all files to the right directory
169170
for ( i in seq_along(vw$stack$names)){
170171
message2("\n", verbose = verbose)
171-
run_mri_surf_cluster(vw$paths$final_path, vw$paths$dir_fshome, vw$input$hemi, vw$stack$p[[i]], vw$post$fwhm_est,
172-
mask_path = vw$paths$final_mask_path, verbose = verbose, mcz_thr = mcz_thr, cwp_thr = cwp_thr,
172+
run_mri_surf_cluster(vw, vw$stack$p[[i]], vw$post$fwhm_est, mask_path = vw$paths$final_mask_path,
173+
verbose = verbose, mcz_thr = mcz_thr, cwp_thr = cwp_thr,
173174
stack = i, stack_name = vw$stack$names[i])
174175
}
175176
vw$post$final_mask <- load.mgh(vw$paths$final_mask_path)$x
176177

177-
catprompt("Calculating vertex-wise values", verbose = verbose)
178+
catprompt("Calculating vertex-wise values", verbose = verbose)
178179

179180
# Do FBM-calculations for plotting histograms and such
180181
vw$post$mgh_description <- list()

R/qdecr_check.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ qdecr_check_backing <- function(backing, clobber){
1212
}
1313

1414
qdecr_check <- function(id, md, margs, hemi, vertex, measure, model, target,
15-
project, dir_out_tree, clobber, fwhm, n_cores, prep_fun){
15+
project, dir_out_tree, clobber, fwhm, n_cores, prep_fun,
16+
file_out_tree){
1617

1718
# verify that id is correct and exists within data
1819
check_id(id, md)
@@ -42,6 +43,7 @@ qdecr_check <- function(id, md, margs, hemi, vertex, measure, model, target,
4243
input[["project"]] <- project
4344
input[["project2"]] <- paste(hemi, project, measure, sep = ".")
4445
input[["dir_out_tree"]] <- dir_out_tree
46+
input[["file_out_tree"]] <- file_out_tree
4547
input[["clobber"]] <- clobber
4648
input[["fwhm"]] <- fwhm
4749
input[["fwhmc"]] <- paste0("fwhm", fwhm)
@@ -143,7 +145,7 @@ check_id <- function(id, md){
143145
}
144146

145147
check_mcz_thr <- function(mcz_thr) {
146-
if (!is.numeric) stop("`mcz_thr` is not numeric.")
148+
if (!is.numeric(mcz_thr)) stop("`mcz_thr` is not numeric.")
147149
if (mcz_thr %in% c(13, 1.3, 0.05)) 13 else
148150
if (mcz_thr %in% c(20, 2.0, 0.01)) 20 else
149151
if (mcz_thr %in% c(23, 2.3, 0.005)) 23 else
@@ -158,7 +160,10 @@ check_paths <- function(vw, dir_tmp, dir_subj, dir_out, dir_fshome, mask_path){
158160
dir_out2 <- check_dir_out(dir_out, vw$input$project, vw$input$project2, vw$input$dir_out_tree, vw$input$clobber)
159161
if (is.null(dir_fshome) || dir_fshome == "") stop("dir_fshome is not specified. Please set the global variable FREESURFER_HOME.")
160162

161-
final_path <- file.path(dir_out2, vw$input$project2)
163+
final_path <- paste0(dir_out2, "/")
164+
if (vw$input$file_out_tree) final_path <- paste0(final_path, vw$input$project2)
165+
dat <- if (vw$input$file_out_tree) ".fwhm.dat" else "fwhm.dat"
166+
finalmask <- if (vw$input$file_out_tree) ".finalMask.mgh" else "finalMask.mgh"
162167
dir_tmp2 <- file.path(dir_tmp, vw$input$project2)
163168
backing_mgh <- paste0(dir_tmp2, "_mgh_backend")
164169

@@ -172,8 +177,8 @@ check_paths <- function(vw, dir_tmp, dir_subj, dir_out, dir_fshome, mask_path){
172177
paths[["backing_mgh"]] <- backing_mgh
173178
paths[["mask_path"]] <- mask_path
174179
paths[["final_path"]] <- final_path
175-
paths[["est_fwhm_path"]] <- paste0(final_path, ".fwhm.dat")
176-
paths[["final_mask_path"]] <- paste0(final_path, ".finalMask.mgh")
180+
paths[["est_fwhm_path"]] <- paste0(final_path, dat)
181+
paths[["final_mask_path"]] <- paste0(final_path, finalmask)
177182
paths[] <- lapply(paths, sub, pattern = "//", replacement = "/", fixed = TRUE)
178183
paths[] <- lapply(paths, sub, pattern = "/$", replacement = "")
179184
paths

R/qdecr_fastlm.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#' @param dir_fshome Freesurfer directory; defaults to FREESURFER_HOME
1919
#' @param dir_tmp directory to store the temporary big matrices; useful for shared memory; defaults to `dir_out`
2020
#' @param dir_out_tree if TRUE, creates a dir_out/project directory. If FALSE, all output is placed directory into dir_out
21+
#' @param file_out_tree if TRUE, adds the full project name to the output file names. By default it is the inverse of dir_out_tree
2122
#' @param clean_up_bm if TRUE, cleans all big matrices (.bk) that were generated in dir_tmp
2223
#' @param clean_up NOT IMPLEMENTED; will be used for setting cleaning of other files
2324
#' @param clobber if TRUE, ignores already existing directories and writes over them; if FALSE, stops and warns user that a given directory already exists
@@ -49,6 +50,7 @@ qdecr_fastlm <- function(formula,
4950
dir_fshome = Sys.getenv("FREESURFER_HOME"),
5051
dir_tmp = dir_out,
5152
dir_out_tree = TRUE,
53+
file_out_tree = !dir_out_tree,
5254
clean_up_bm = TRUE,
5355
clean_up = TRUE,
5456
clobber = FALSE,
@@ -74,7 +76,7 @@ if (sum(qt %in% rt) > 1) stop("qdecr currently cannot handle multiple vertex-wis
7476
qid <- rt %in% qt
7577
if (sum(terms[qid, ]) > 1) stop("qdecr currently cannot handle interactions or combinations of the vertex terms.")
7678
qqt <- rt[qid]
77-
qqt2 <- sub("qdecr_", "", qqt)
79+
measure <- sub("qdecr_", "", qqt)
7880
ff <- as.formula(deparse(formula))
7981
margs <- c(qdecr_decon(RcppEigen::fastLm()), list(formula = ff, data = data, method = 2))
8082
vw <- qdecr(id = id,
@@ -85,7 +87,7 @@ vw <- qdecr(id = id,
8587
fwhm = fwhm,
8688
mcz_thr = mcz_thr,
8789
cwp_thr = cwp_thr,
88-
measure = qqt2,
90+
measure = measure,
8991
mgh = mgh,
9092
mask = mask,
9193
mask_path = mask_path,
@@ -96,6 +98,7 @@ vw <- qdecr(id = id,
9698
dir_subj = dir_subj,
9799
dir_fshome = dir_fshome,
98100
dir_out_tree = dir_out_tree,
101+
file_out_tree = file_out_tree,
99102
clean_up = clean_up,
100103
clean_up_bm = clean_up_bm,
101104
clobber = clobber,

R/qdecr_make_stack.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ qdecr_make_stack <- function(vw, stats, mcz_thr, clusterfiles = c("cluster.mgh",
99
for (n in nn1) stack[[n]] <- list()
1010
for(i in seq_along(stack$names)){
1111
for (j in seq_along(nn1)){
12-
stack[[nn1[j]]][[stack$names[i]]] <- paste0(vw$paths$final_path, ".stack", i, ".", nn2[j])
12+
temp <- paste0("stack", i, ".", nn2[j])
13+
fp <- vw$paths$final_path
14+
stack[[nn1[j]]][[stack$names[i]]] <- if(!vw$input$file_out_tree) file.path(fp, temp) else paste(fp, temp, sep = ".")
1315
}
1416
}
1517
stack

R/qdecr_post.R

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,21 @@ calc_fwhm <- function(final_path, final_mask_path, est_fwhm_path, hemi, eres, ma
88
return(fwhm)
99
}
1010

11-
run_mri_surf_cluster <- function(final_path, dir_fshome, hemi, pval, fwhm, mask_path = NULL, cwp_thr = 0.025, mcz_thr = 30, csd_sign = "abs", verbose = FALSE, stack, stack_name) {
12-
11+
run_mri_surf_cluster <- function(vw, pval, fwhm, mask_path = NULL, cwp_thr = 0.025, mcz_thr = 30, csd_sign = "abs", verbose = FALSE, stack, stack_name) {
1312
mcz_thr2 <- paste0("th", mcz_thr)
14-
15-
o_base_name <- paste0(final_path, ".stack", stack, ".cache.", mcz_thr2, '.', csd_sign, ".sig")
1613
if (fwhm < 10) fwhm <- paste0("0", fwhm)
17-
csd <- file.path(dir_fshome, "average/mult-comp-cor/fsaverage", hemi, paste0("cortex/fwhm", fwhm), csd_sign, mcz_thr2, "mc-z.csd")
14+
csd <- file.path(vw$paths$dir_fshome, "average/mult-comp-cor/fsaverage", vw$input$hemi, paste0("cortex/fwhm", fwhm), csd_sign, mcz_thr2, "mc-z.csd")
1815
cmd_str <- paste("mri_surfcluster",
1916
"--in", pval,
2017
"--csd", csd,
21-
"--cwsig", paste0(o_base_name, ".cluster.mgh"),
22-
"--vwsig", paste0(o_base_name, ".voxel.mgh"),
23-
"--sum", paste0(o_base_name, ".cluster.summary"),
24-
"--ocn", paste0(o_base_name, ".ocn.mgh"),
25-
"--oannot", paste0(o_base_name, ".ocn.annot"),
26-
"--annot", "aparc",
27-
"--csdpdf", paste0(o_base_name, ".pdf.dat"),
18+
"--cwsig", vw$stack$cluster.mgh[[stack]],
19+
"--vwsig", vw$stack$voxel.mgh[[stack]],
20+
"--sum", vw$stack$cluster.summary[[stack]],
21+
"--ocn", vw$stack$ocn.mgh[[stack]],
22+
"--oannot", vw$stack$ocn.annot[[stack]],
23+
"--annot aparc",
2824
"--cwpvalthresh", cwp_thr,
29-
"--o", paste0(o_base_name, ".masked.mgh"),
25+
"--o", vw$stack$masked.mgh[[stack]],
3026
"--no-fixmni",
3127
"--surf", "white")
3228
cmd_str <- if (!is.null(mask_path)) paste(cmd_str, "--mask", mask_path) else paste(cmd_str, "--cortex")

man/formula.vw_fastlm.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/qdecr.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/qdecr_fastlm.Rd

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)