-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlateralization_analysis.R
122 lines (101 loc) · 6.19 KB
/
lateralization_analysis.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# 0_load_packages ---------------------------------------------------------
library(brainGraph) # compute network properties
# remotes::install_version("igraph", version = "1.6.0")
library(igraph) # 1.6.0
packageVersion("igraph") # 1.6.0
library(data.table) # data.table
library(pracma) # compute AUC
library(freesurferformats)
library(parallel)
library(stringr)
library(doMC)
registerDoMC(detectCores())
options(bg.subject_id='participant_id', bg.group='group')
grps = c('health', 'patient')
# 1_network_construction --------------------------------------------------
## This is processed in python script. For functional network, the pearson
## correlation between two nodes is defined as the edge. For structural network,
## the sfit2_invnodevol_count-sum between two nodes is defined as the edge.
## The diagonal in functional network is 0 and in structural network is 0.
## CFS
## Functional network: NetFunc / CFS / PearCorz_sub-subxxx.txt
## Fiber network: NetFiber / CFS / Connectome_sub-subxxx.txt
## large population
## Functional network: NetFunc / ISYB / PearCorz_sub-xxx.txt
## Fiber network: NetFiber / ISYB / Connectome_sub-xxx.txt
## split network to positive & negative & absolute
## NetResults/CFS /subxxx
## /abs_fiber_xxx, abs_func_xxx, neg_fiber_xxx, neg_func_xxx, pos_fiber_xxx, pos_func_xxx
## /ISYB /subxxx
## Script is: Atlas / atlas_transform.py
# 2_network_properties_compute --------------------------------------------
## network similarity
## Network contains positive & negative & absolute
densities <- seq(0.10, 0.50, 0.01)
atlas = 'brainnetome'
## --------------------------------------------------------------------------
save2dataframe <- function(data, file_path_suffix){
vertex_df <- rbindlist(lapply(data, vertex_attr_dt))
graph_df <- rbindlist(lapply(data, graph_attr_dt))
fwrite(vertex_df, paste0(file_path_suffix, '_vertex.csv'), sep=',', col.names=TRUE)
fwrite(graph_df, paste0(file_path_suffix, '_graph.csv'), sep=',', col.names=TRUE)
}
#### CFS: functional network graph weighted subject level
covars.all <- fread('ClinicalMeasurements/CFS_subinfo.csv') # subs=79
inds = lapply(grps, function(x) covars.all[group == x, which = TRUE]) # 1=health=39, 2=patient=40
matfiles <- paste0('NetResults/CFS/', covars.all$participant_id, '/abs_func_', covars.all$participant_id, '.txt')
my.mats <- create_mats(matfiles, modality = 'fmri',threshold.by = 'density',
mat.thresh = densities, inds = inds)
gw.sub <- vector('list', length(densities)) # ws: weighted subject
for (i in seq_along(densities)){
gw.sub[[i]] <- make_brainGraphList(my.mats$A.norm.sub[[i]], atlas, level='subject',
modality = 'fmri',threshold = densities[i],
weighted = TRUE, gnames = covars.all$participant_id,
grpNames = covars.all$group )
}
saveRDS(gw.sub, file=file.path('BrainGraphRDS/', 'CFS_func_weighted_subject_abs.rds'), compress = 'xz')
save2dataframe(gw.sub, file=file.path('BrainGraphRDS/', 'CFS_func_weighted_subject_abs'))
#### CFS: fiber network graph weighted subject level
matfiles <- paste0('NetResults/CFS/', covars.all$participant_id, '/abs_fiber_', covars.all$participant_id, '.txt')
my.mats <- create_mats(matfiles, modality = 'fmri',threshold.by = 'density',
mat.thresh = densities, inds = inds)
gw.sub <- vector('list', length(densities)) # ws: weighted subject
for (i in seq_along(densities)){
gw.sub[[i]] <- make_brainGraphList(my.mats$A.norm.sub[[i]], atlas, level='subject',
modality = 'fmri',threshold = densities[i],
weighted = TRUE, gnames = covars.all$participant_id,
grpNames = covars.all$group )
}
saveRDS(gw.sub, file=file.path('BrainGraphRDS/', 'CFS_fiber_weighted_subject_abs.rds'), compress = 'xz')
save2dataframe(gw.sub, file=file.path('BrainGraphRDS/', 'CFS_fiber_weighted_subject_abs'))
## --------------------------------------------------------------------------
#### ISYB: functional network graph weighted subject level
covars.all <- fread('ClinicalMeasurements/ISYB_subinfo.csv') # subs=215
inds = lapply(grps, function(x) covars.all[group == x, which = TRUE]) # 1=health=215, 2=patient=0
matfiles <- paste0('NetResults/ISYB/', covars.all$participant_id, '/abs_func_', covars.all$participant_id, '.txt')
my.mats <- create_mats(matfiles, modality = 'fmri',threshold.by = 'density',
mat.thresh = densities, inds = inds)
gw.sub <- vector('list', length(densities)) # ws: weighted subject
for (i in seq_along(densities)){
gw.sub[[i]] <- make_brainGraphList(my.mats$A.norm.sub[[i]], atlas, level='subject',
modality = 'fmri',threshold = densities[i],
weighted = TRUE, gnames = covars.all$participant_id,
grpNames = covars.all$group )
}
saveRDS(gw.sub, file=file.path('BrainGraphRDS/', 'ISYB_func_weighted_subject_abs.rds'), compress = 'xz')
save2dataframe(gw.sub, file=file.path('BrainGraphRDS/', 'ISYB_func_weighted_subject_abs'))
#### ISYB: fiber network graph weighted subject level
matfiles <- paste0('NetResults/ISYB/', covars.all$participant_id, '/abs_fiber_', covars.all$participant_id, '.txt')
my.mats <- create_mats(matfiles, modality = 'fmri',threshold.by = 'density',
mat.thresh = densities, inds = inds)
gw.sub <- vector('list', length(densities)) # ws: weighted subject
for (i in seq_along(densities)){
gw.sub[[i]] <- make_brainGraphList(my.mats$A.norm.sub[[i]], atlas, level='subject',
modality = 'fmri',threshold = densities[i],
weighted = TRUE, gnames = covars.all$participant_id,
grpNames = covars.all$group )
}
saveRDS(gw.sub, file=file.path('BrainGraphRDS/', 'ISYB_fiber_weighted_subject_abs.rds'), compress = 'xz')
save2dataframe(gw.sub, file=file.path('BrainGraphRDS/', 'ISYB_fiber_weighted_subject_abs'))
# 3_structural_lateralization ---------------------------------------------
# 4_functional_compensation -----------------------------------------------