Skip to content

Commit 0c77917

Browse files
add NBS_lme and clean up unused functions
1 parent 4a39b6d commit 0c77917

17 files changed

+707
-1010
lines changed

DESCRIPTION

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Imports:
2424
cowplot,
2525
doParallel,
2626
doSNOW,
27-
fMRItools,
2827
foreach,
2928
ggplot2,
3029
ggplotify,

NAMESPACE

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export(CIFTI_subj_avg)
44
export(CIFTItoFC)
55
export(NBS)
6+
export(NBS_lme)
67
export(check_cifti)
78
export(cpm.lesion)
89
export(cpm.predict)
@@ -11,7 +12,6 @@ export(cpm.train.cv)
1112
export(edgelist)
1213
export(editJSON_IntendedFor)
1314
export(extract.edges)
14-
export(extractFC)
1515
export(extractFS.ROI)
1616
export(extract_headmotion)
1717
export(extract_links)
@@ -21,11 +21,11 @@ export(headmotion.XCP)
2121
export(headmotion.fmriprep)
2222
export(intersubject_similarity)
2323
export(reorder_subcortical)
24-
export(vectorizeFC)
2524
export(vizChord)
2625
export(vizConnectogram)
2726
export(vizGlassbrain)
2827
export(vizHeatmap)
28+
importFrom(Rfast,rint.reg)
2929
importFrom(caret,createFolds)
3030
importFrom(ciftiTools,ciftiTools.setOption)
3131
importFrom(ciftiTools,move_from_mwall)
@@ -38,8 +38,6 @@ importFrom(cowplot,get_plot_component)
3838
importFrom(cowplot,plot_grid)
3939
importFrom(doParallel,registerDoParallel)
4040
importFrom(doSNOW,registerDoSNOW)
41-
importFrom(fMRItools,dct_bases)
42-
importFrom(fMRItools,nuisance_regression)
4341
importFrom(foreach,"%dopar%")
4442
importFrom(foreach,foreach)
4543
importFrom(ggplot2,aes)

R/HCP_dat_func.R

Lines changed: 0 additions & 475 deletions
Large diffs are not rendered by default.

R/fmriprep_func.R

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -46,108 +46,3 @@ extract_headmotion=function(filename="motiondat.csv",start=1)
4646
write.table(motiondat, file = filename,sep = ",",quote = F,row.names = F)
4747
cat(paste0("headmotion data saved to ",filename))
4848
}
49-
########################################################################################################
50-
########################################################################################################
51-
52-
#' @title vectorizeFC
53-
#'
54-
#' @description vectorizing and concatenating and M x M matrices
55-
#'
56-
#' @details This function reads the M x M matrices (saved as .csv files) in a directory, vectorizes and concatenates them into a single N x ((M x M)-M)/2 matrix. N= number of subjects; M=number of nodes in the connectome
57-
#'
58-
#' @param FC_dir the directory containing the M x M matrices (saved as .csv files)
59-
#' @param filename the output format of the concatenated group level matrix. Only filenames with the *.csv or *.rds extensions are accepted. The .rds format uses less disk space. Set to 'FCmat.rds' by default
60-
#' @param task A string to select the .csv files with a specific taskname.
61-
#' @param fisherz `TRUE` or `FALSE` option specifying if the edge values should undergo a fisher-Z transformation. This would be applicable in cases and functional connectivity is calculated as a pearson's correlation coefficient. Set to `TRUE` by default.
62-
#' @param timeseries `TRUE` or `FALSE` option specifying if the parcellated timeseries are used as inputs. Set to `FALSE` by default.
63-
#' @returns Depending on whether a filename with a .csv or .rds file extension is specified, outputs a .csv file containing the N x ((M x M)-M)/2 matrix or a .rds file containing a list object: 1)N x ((M x M)-M)/2 matrix, 2) a vector of subject IDs.
64-
#'
65-
#' @examples
66-
#' \dontrun{
67-
#' vectorizeFC(FC_dir="FCmat", filename="FCmat.rds", fisherz=TRUE)
68-
#' }
69-
#' @importFrom stringr str_detect
70-
#' @importFrom psych fisherz
71-
#' @export
72-
#'
73-
#'
74-
########################################################################################################
75-
########################################################################################################
76-
vectorizeFC=function(FC_dir, filename="FCmat.rds", task, fisherz=TRUE, timeseries=FALSE)
77-
{
78-
##check filename extension
79-
if(stringr::str_detect(string=filename, pattern=".csv")==F & stringr::str_detect(string=filename, pattern=".rds")==F)
80-
{
81-
stop("invalid filename extension")
82-
}
83-
if(missing("task")) {subjlist=list.files(path=FC_dir)}
84-
else {subjlist=list.files(path=FC_dir,pattern=task)}
85-
86-
if(timeseries==F)
87-
{
88-
FCformat=read.csv(paste(FC_dir,"/",subjlist[1], sep=""), header=F)
89-
90-
#if subjects' FCmat is already vectorized
91-
if(dim(FCformat)[1]==1)
92-
{
93-
FCmat=matrix(NA,nrow=NROW(subjlist), ncol=dim(FCformat)[2])
94-
for(sub in 1:NROW(subjlist))
95-
{
96-
FCmat[sub,]=unlist(read.table(paste(FC_dir,"/",subjlist[sub], sep=""),header = F,sep=",",col.names = F))
97-
cat(paste(subjlist[sub],"\n"))
98-
}
99-
if(fisherz==T)
100-
{
101-
FCmat=psych::fisherz(FCmat)
102-
}
103-
}
104-
105-
#if subjects' FCmat has not been vectorized
106-
if(dim(FCformat)[1]>1)
107-
{
108-
x=dim(FCformat)[1]
109-
FCmat=matrix(NA,nrow=NROW(subjlist), ncol=((x*x-x)/2))
110-
for(sub in 1:NROW(subjlist))
111-
{
112-
FCmat.temp=read.table(paste(FC_dir,"/",subjlist[sub], sep=""),header = F,sep=",")
113-
FCmat[sub,]=FCmat.temp[upper.tri(FCmat.temp, diag = FALSE)]
114-
cat(paste(subjlist[sub],"\n"))
115-
remove(FCmat.temp)
116-
}
117-
if(fisherz==T)
118-
{
119-
FCmat=psych::fisherz(FCmat)
120-
}
121-
}
122-
} else if(timeseries==T)
123-
{
124-
FCformat=read.csv(paste(FC_dir,"/",subjlist[1], sep=""), header=F)
125-
x=NCOL(FCformat)
126-
FCmat=matrix(NA,nrow=NROW(subjlist), ncol=((x*x-x)/2))
127-
for(sub in 1:NROW(subjlist))
128-
{
129-
FCmat.temp=read.table(paste(FC_dir,"/",subjlist[sub], sep=""),header = F,sep=",")
130-
FCmat[sub,]=FCmat.temp[upper.tri(cor(FCmat.temp), diag = FALSE)]
131-
cat(paste(subjlist[sub],"\n"))
132-
remove(FCmat.temp)
133-
}
134-
if(fisherz==T)
135-
{
136-
FCmat=psych::fisherz(FCmat)
137-
}
138-
}
139-
140-
##output file
141-
if(stringr::str_detect(string=filename, pattern=".csv"))
142-
{
143-
write.table(FCmat,file = filename,row.names = F,col.names = F, sep=",")
144-
cat(paste("Concatenated FC matrices saved to",filename,"\n",sep=" "))
145-
} else if(stringr::str_detect(string=filename, pattern=".rds"))
146-
{
147-
saveRDS(list(FCmat,gsub(".csv","",subjlist)),file = filename)
148-
cat(paste("Concatenated FC matrices saved to",filename,"\n",sep=" "))
149-
}
150-
}
151-
152-
########################################################################################################
153-
########################################################################################################

0 commit comments

Comments
 (0)