Skip to content

Commit 129df30

Browse files
Update CIFTItoFC.R
added option to concatenate runs/sessions for each subject
1 parent f52f6aa commit 129df30

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

R/CIFTItoFC.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#' @param path The filepath to directory containing the subject folders. Set to `./.` by default.
1212
#' @param atlas The version (number of parcels) of the Schaefer atlas; it has to be in multiples of 100, from 100 to 1000. set to `200` by default. The specified atlas template will be automatically downloaded from here if it does not exist in the current directory.
1313
#' @param dtseries The filename extension of the fMRI volumes. Set to `_space-fsLR_den-91k_desc-denoised_bold.dtseries.nii` by default
14+
#' @param concat_subj When set to `TRUE` (default), timeseries data from multiple runs/sessions of the same subject is first Z-scaled and then concatenated into a single larger timeseries data frame before computing the FC.
1415
#' @param filename Filename of the concatenated FC vector file. Set to `FC.rds` by default
1516
#' @returns outputs N (number of subjects) x E (number of unique) matrices as a .rds file
1617
#'
@@ -24,7 +25,7 @@
2425

2526
########################################################################################################
2627
########################################################################################################
27-
CIFTItoFC=function(path="./",wb_path="/home/junhong.yu/workbench/bin_rh_linux64", dtseries="_space-fsLR_den-91k_desc-denoised_bold.dtseries.nii", atlas=200,filename="FC.rds")
28+
CIFTItoFC=function(path="./",wb_path="/home/junhong.yu/workbench/bin_rh_linux64", dtseries="_space-fsLR_den-91k_desc-denoised_bold.dtseries.nii", concat_subj=TRUE, atlas=200,filename="FC.rds")
2829
{
2930
filelist=list.files(path=path,pattern=dtseries,recursive = T)
3031
sublist=unique(gsub(pattern ="/ses-0./func",replacement = "",dirname(filelist)))
@@ -46,7 +47,8 @@ CIFTItoFC=function(path="./",wb_path="/home/junhong.yu/workbench/bin_rh_linux64"
4647

4748
## defining subcortical parcel indices for reordering ROIs subsequently
4849
reorder.subcortical.idx=c(9,18,8,17,6,3,13,1,11,10,19,7,16,5,15,4,14,2,12)+atlas
49-
50+
51+
if(concat_subj==F) {sublist=filelist}
5052

5153
all_FC=matrix(NA,nrow=length(sublist),ncol=(((atlas+19)^2)-(atlas+19))/2)
5254
for (sub in 1:length(sublist))
@@ -100,5 +102,12 @@ CIFTItoFC=function(path="./",wb_path="/home/junhong.yu/workbench/bin_rh_linux64"
100102
remove(xii, xii0, xii.final, xii_pmean, FCmat,timeseries.dat,filelist.sub)
101103
}
102104
cat(paste0("Saving ", filename," ..."))
103-
saveRDS(list(dirname(sublist),psych::fisherz(all_FC)),file=filename)
105+
if(concat_subj==T)
106+
{
107+
saveRDS(list(dirname(sublist),psych::fisherz(all_FC)),file=filename)
108+
} else if (concat_subj==F)
109+
{
110+
saveRDS(list(basename(sublist),psych::fisherz(all_FC)),file=filename)
111+
}
104112
}
113+

0 commit comments

Comments
 (0)