Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added all the functions from fslstats for simple wrappers
- Loading branch information
1 parent
808b422
commit ed59b85
Showing
14 changed files
with
287 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#' @title Image Mean Entropy | ||
#' @description Estimates Mean Entropy of Image from FSL | ||
#' @param img Object of class nifti, or path of file | ||
#' @param nonzero (logical) Should the statistic be taken over non-zero voxels | ||
#' @param verbose (logical) print out command before running | ||
#' @param ts (logical) is the series a timeseries (4D), invoking \code{-t} | ||
#' option | ||
#' @note This uses option -e or -E in \code{\link{fslstats}} | ||
#' @return Vector of unless ts option invoked, then matrix | ||
#' @export | ||
fslentropy = function(img, nonzero = FALSE, verbose = TRUE, ts = FALSE){ | ||
opts = "-e" | ||
opts = ifelse(nonzero, toupper(opts), opts) | ||
|
||
val = fslstats(img, opts = opts, verbose = verbose, ts = ts) | ||
val = strsplit(val, " ") | ||
if (length(val) == 1) { | ||
val = as.numeric(val[[1]]) | ||
} else { | ||
val = sapply(val, as.numeric) | ||
} | ||
val | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#' @title Image Mean | ||
#' @description Estimates Mean of Image from FSL | ||
#' @param img Object of class nifti, or path of file | ||
#' @param nonzero (logical) Should the statistic be taken over non-zero voxels | ||
#' @param verbose (logical) print out command before running | ||
#' @param ts (logical) is the series a timeseries (4D), invoking \code{-t} | ||
#' option | ||
#' @note This uses option -m or -M in \code{\link{fslstats}} | ||
#' @return Vector of unless ts option invoked, then matrix | ||
#' @export | ||
fslmean = function(img, nonzero = FALSE, verbose = TRUE, ts = FALSE){ | ||
opts = "-m" | ||
opts = ifelse(nonzero, toupper(opts), opts) | ||
|
||
val = fslstats(img, opts = opts, verbose = verbose, ts = ts) | ||
val = strsplit(val, " ") | ||
if (length(val) == 1) { | ||
val = as.numeric(val[[1]]) | ||
} else { | ||
val = sapply(val, as.numeric) | ||
} | ||
val | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#' @title Image Standard Deviation | ||
#' @description Estimates Standard Deviation of Image from FSL | ||
#' @param img Object of class nifti, or path of file | ||
#' @param nonzero (logical) Should the statistic be taken over non-zero voxels | ||
#' @param verbose (logical) print out command before running | ||
#' @param ts (logical) is the series a timeseries (4D), invoking \code{-t} | ||
#' option | ||
#' @note This uses option -s or -S in \code{\link{fslstats}} | ||
#' @return Vector of unless ts option invoked, then matrix | ||
#' @export | ||
fslsd = function(img, nonzero = FALSE, verbose = TRUE, ts = FALSE){ | ||
opts = "-s" | ||
opts = ifelse(nonzero, toupper(opts), opts) | ||
|
||
val = fslstats(img, opts = opts, verbose = verbose, ts = ts) | ||
val = strsplit(val, " ") | ||
if (length(val) == 1) { | ||
val = as.numeric(val[[1]]) | ||
} else { | ||
val = sapply(val, as.numeric) | ||
} | ||
val | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#' @title Image %FUNC% | ||
#' @description Estimates %FUNC% of Image from FSL | ||
#' @param img Object of class nifti, or path of file | ||
#' @param verbose (logical) print out command before running | ||
#' @param ts (logical) is the series a timeseries (4D), invoking \code{-t} | ||
#' option | ||
#' @note This uses option -%opt% in \code{\link{fslstats}} | ||
#' @return Vector of length 1 unless ts option invoked, then vector of with length the number of timepoints. | ||
#' @export | ||
fsl%func% = function(img, verbose = TRUE, ts = FALSE){ | ||
opts = "-%opt%" | ||
|
||
val = fslstats(img, opts = opts, verbose = verbose, ts = ts) | ||
val = strsplit(val, " ") | ||
if (length(val) == 1) { | ||
val = as.numeric(val[[1]]) | ||
} else { | ||
val = t(sapply(val, as.numeric)) | ||
} | ||
val | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
proper = function(x){ | ||
paste0(toupper(substr(x, 1,1)), substr(x, 2, nchar(x))) | ||
} | ||
|
||
############################################# | ||
# Function maker that involves 1 file | ||
############################################# | ||
makefunc = function(opt, FUNC, func, | ||
remove = TRUE){ | ||
|
||
x = readLines('fslr_Generic_fslstats.R') | ||
x = gsub("%opt%", opt, x) | ||
x = gsub("%FUNC%", FUNC, x) | ||
x = gsub("%func%", func, x) | ||
funcname = paste0("fsl", opt) | ||
|
||
writeLines(text = x, con = paste0("R/", funcname, ".R")) | ||
if (remove) file.remove(paste0("R/", funcname, ".R")) | ||
return(TRUE) | ||
} | ||
|
||
############################################# | ||
# Function maker that involves non-zero entries | ||
############################################# | ||
makefunc = function(opt, | ||
FUNC, | ||
func, | ||
remove = TRUE){ | ||
|
||
x = readLines('fslr_Generic_fslstats_nonzero.R') | ||
x = gsub("%opt%", opt, x) | ||
x = gsub("%OPT%", toupper(opt), x) | ||
x = gsub("%FUNC%", FUNC, x) | ||
x = gsub("%func%", func, x) | ||
funcname = paste0("fsl", func) | ||
|
||
writeLines(text = x, con = paste0("R/", funcname, ".R")) | ||
if (remove) file.remove(paste0("R/", funcname, ".R")) | ||
return(TRUE) | ||
} | ||
|
||
|
||
remove = FALSE | ||
################################################################ | ||
# Make Functions that take in 1 file | ||
################################################################ | ||
# makefunc("r", FUNC = "Robust Range", func = "rrange", | ||
# remove = TRUE) | ||
|
||
|
||
makefunc("m", FUNC = "Mean", func = "mean", | ||
remove = remove) | ||
makefunc("s", FUNC = "Standard Deviation", func = "sd", | ||
remove = remove) | ||
makefunc("e", FUNC = "Mean Entropy", func = "entropy", | ||
remove = remove) | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#' @title Image %FUNC% | ||
#' @description Estimates %FUNC% of Image from FSL | ||
#' @param img Object of class nifti, or path of file | ||
#' @param nonzero (logical) Should the statistic be taken over non-zero voxels | ||
#' @param verbose (logical) print out command before running | ||
#' @param ts (logical) is the series a timeseries (4D), invoking \code{-t} | ||
#' option | ||
#' @note This uses option -%opt% or -%OPT% in \code{\link{fslstats}} | ||
#' @return Vector of unless ts option invoked, then matrix | ||
#' @export | ||
fsl%func% = function(img, nonzero = FALSE, verbose = TRUE, ts = FALSE){ | ||
opts = "-%opt%" | ||
opts = ifelse(nonzero, toupper(opts), opts) | ||
|
||
val = fslstats(img, opts = opts, verbose = verbose, ts = ts) | ||
val = strsplit(val, " ") | ||
if (length(val) == 1) { | ||
val = as.numeric(val[[1]]) | ||
} else { | ||
val = sapply(val, as.numeric) | ||
} | ||
val | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.