Skip to content

Commit

Permalink
Merge pull request #30 from mandymejia/4.3
Browse files Browse the repository at this point in the history
4.3
  • Loading branch information
damondpham committed Aug 19, 2021
2 parents 475521f + ccadda7 commit f67b757
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 28 deletions.
24 changes: 19 additions & 5 deletions R/make_xifti_components.R
Expand Up @@ -82,11 +82,25 @@ make_cortex <- function(
idx_string <- paste("-column", paste(idx, collapse=" -column "))
}
cortex_original <- cortex
cortex <- file.path(
tempdir(),
# [TO DO] more elegant naming?
gsub("\\.gii$", ".selected_idx\\.func\\.gii", basename(cortex_original))
)

# Name for new GIFTI file
if (endsWith(cortex, ".func.gii")) {
cortex <- file.path(
tempdir(),
gsub("\\.func\\.gii$", "\\.sel_idx\\.func\\.gii", basename(cortex_original))
)
} else if (endsWith(cortex, ".label.gii")) {
cortex <- file.path(
tempdir(),
gsub("\\.label\\.gii$", "\\.sel_idx\\.label\\.gii", basename(cortex_original))
)
} else {
# Guess func.
# [TO DO] warn user?
cortex <- file.path(
tempdir(), paste0(basename(cortex_original), ".func.gii")
)
}

run_wb_cmd(paste(
"-metric-merge", cortex, "-metric", cortex_original, idx_string
Expand Down
23 changes: 18 additions & 5 deletions R/read_cifti_flat.R
Expand Up @@ -14,7 +14,8 @@
#' and then reading it in. Should the GIFTI file be kept? If \code{FALSE}
#' (default), write it in a temporary directory regardless of \code{write_dir}.
#' @param gifti_fname File path of GIFTI-format data to save the CIFTI as.
#' Default: the CIFTI_fname but with the extension replaced with "flat.gii".
#' Should end with ".func.gii". Default: the CIFTI_fname but with the extension
#' replaced with ".func.gii".
#' @inheritParams idx_Param
#' @param write_dir The directory in which to save the GIFTI, if it is being
#' kept. If \code{NULL} (default), use the current working directory.
Expand All @@ -39,14 +40,23 @@ read_cifti_flat <- function(
stop("`", cifti_fname, "` is not an existing file.")
}

# Get the components of the CIFTI file path.
# Get the components of the CIFTI and GIFTI file paths.
bname_cifti <- basename(cifti_fname)
extn_cifti <- get_cifti_extn(bname_cifti) # "dtseries.nii" or "dscalar.nii"
extn_cii <- get_cifti_extn(bname_cifti)
extn_cii <- paste0(".", extn_cii) # e.g. ".dtseries.nii"
is_label = FALSE# extn_cii == ".dlabel.nii"
extn_gii <- ifelse(is_label, ".label.gii", ".func.gii")
extn_gii2 <- gsub(".", "\\.", extn_gii, fixed=TRUE)
extn_cii2 <- paste0(gsub(".", "\\.", extn_cii, fixed=TRUE), "$")

# If gifti_fname is not provided, use the CIFTI_fname but replace the
# extension with "flat.gii".
if (is.null(gifti_fname)) {
gifti_fname <- gsub(extn_cifti, "flat.gii", bname_cifti, fixed=TRUE)
if (grepl(bname_cifti, extn_cii2)) {
gifti_fname <- gsub(extn_cii2, extn_gii2, bname_cifti)
} else {
gifti_fname <- paste0(bname_cifti, extn_gii)
}
}
if (!keep) { write_dir <- tempdir() }
gifti_fname <- format_path(gifti_fname, write_dir, mode=2)
Expand Down Expand Up @@ -74,7 +84,10 @@ read_cifti_flat <- function(
gifti_fname_original <- gifti_fname
gifti_fname <- file.path(
tempdir(),
gsub("\\.gii$", ".selected_idx\\.gii", basename(gifti_fname_original))
gsub(
paste0(extn_gii2, "$"), paste0("\\.sel_idx", extn_gii2),
basename(gifti_fname_original)
)
)

run_wb_cmd(paste(
Expand Down
20 changes: 12 additions & 8 deletions R/read_xifti2.R
Expand Up @@ -95,7 +95,10 @@ read_xifti2 <- function(
if (!is.null(cortexL)) {
x <- resample_gifti(
cortexL,
paste0("resamp", cifti_component_suffix("cortexL")),
paste0(
"resamp",
cifti_component_suffix("cortexL", ifelse(grepl("label\\.gii$", cortexL), "label", "func"))
),
hemisphere="left", resamp_res=resamp_res,
ROIcortex_original_fname=cortexL_mwall,
read_dir=read_dir, write_dir=tdir
Expand All @@ -107,7 +110,10 @@ read_xifti2 <- function(
if (!is.null(cortexR)) {
x <- resample_gifti(
cortexR,
paste0("resamp", cifti_component_suffix("cortexR")),
paste0(
"resamp",
cifti_component_suffix("cortexR", ifelse(grepl("label\\.gii$", cortexR), "label", "func"))
),
hemisphere="right", resamp_res=resamp_res,
ROIcortex_original_fname=cortexR_mwall,
read_dir=read_dir, write_dir=tdir
Expand All @@ -118,19 +124,17 @@ read_xifti2 <- function(
## Left surface.
if (!is.null(surfL)) {
surfL <- resample_gifti(
surfL,
paste0("surf_resamp", cifti_component_suffix("cortexL")),
hemisphere="left", file_type="surf", resamp_res=resamp_res,
surfL, paste0("resamp", cifti_component_suffix("cortexL", "surf")),
hemisphere="left", file_type="surface", resamp_res=resamp_res,
read_dir=read_dir, write_dir=tdir
)
}

## Right surface.
if (!is.null(surfR)) {
surfR <- resample_gifti(
surfR,
paste0("surf_resamp", cifti_component_suffix("cortexR")),
hemisphere="left", file_type="surf", resamp_res=resamp_res,
surfR, paste0("resamp", cifti_component_suffix("cortexR", "surf")),
hemisphere="right", file_type="surface", resamp_res=resamp_res,
read_dir=read_dir, write_dir=tdir
)
}
Expand Down
4 changes: 4 additions & 0 deletions cran-comments.md
Expand Up @@ -26,3 +26,7 @@ Passes all the tests in `tests/run_ciftiTools_tests.R`
## Submission revision

The previous submission was rejected because the tarball was over 5 MB. It has been reduced to 3.25 MB.

## Submission revision 2

The previous submission (0.4.1) was cancelled manually.
3 changes: 2 additions & 1 deletion man/read_cifti_flat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-misc.R
Expand Up @@ -179,10 +179,10 @@ test_that("Miscellaneous functions are working", {
if (!grepl("dlabel", cii_fname)) {
# Smooth metric GIFTI
fnames_sep <- separate_cifti(cii_fname, write_dir=tdir)
smooth_gifti(fnames_sep[1], file.path(tdir, "sm.metric.gii"), hemisphere="left")
smooth_gifti(fnames_sep[1], file.path(tdir, "sm.func.gii"), hemisphere="left")
smg1 <- gifti::readgii(
smooth_gifti(
fnames_sep[3], file.path(tdir, "sm.metric.gii"),
fnames_sep[3], file.path(tdir, "sm.func.gii"),
ROI_fname=fnames_sep[4], hemisphere="right"
)
)
Expand Down
2 changes: 1 addition & 1 deletion vignettes/ciftiTools_vignette.Rmd
Expand Up @@ -36,7 +36,7 @@ library(ciftiTools)
Next, we indicate where to find the Connectome Workbench. This can be the full path to the Connectome Workbench executable file, or the path to its containing folder, in which case `ciftiTools` will locate the full path. Here, we will use the latter:

```{r}
# Replace '/Applications/workbench' with the actual path to
# Replace '../../workbench' with the actual path to
# the Connectome Workbench folder on your computer.
# If successful, the full path to the Workbench executable will be printed.
ciftiTools.setOption('wb_path', '../../workbench')
Expand Down
12 changes: 6 additions & 6 deletions vignettes/ciftiTools_vignette.html

Large diffs are not rendered by default.

0 comments on commit f67b757

Please sign in to comment.