-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_construct_NetGraph.R
More file actions
77 lines (70 loc) · 3.98 KB
/
run_construct_NetGraph.R
File metadata and controls
77 lines (70 loc) · 3.98 KB
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
# 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(parallel)
library(doMC)
registerDoMC(14)
options(bg.subject_id='participant_id', bg.group='all_group')
grps = c('health_before', 'patient_before', 'health_after', 'patient_after')
# 1_network_construction --------------------------------------------------
out_dir = 'BrainGraphRDS'
dir.create(out_dir, recursive = TRUE, showWarnings = FALSE) # os.makedirs(dir_name, exist_ok=True) in python
## Network contains positive & negative & absolute
# Communication dynamics in the human connectome shape the cortex-wide propagation of direct electrical stimulation, Seguin, density=0.25
densities <- seq(0.25, 0.30, 0.05)
"my_data = fread('brainnetome_surface.csv')
my_data$x.mni <- as.numeric(my_data$x.mni)
my_data$y.mni <- as.numeric(my_data$y.mni)
my_data$z.mni <- as.numeric(my_data$z.mni)
my_data$lobe <- as.factor(my_data$lobe)
my_data$hemi <- as.factor(my_data$hemi)
my_data$gyrus <- as.factor(my_data$gyrus)
my_data$Yeo_7network <- as.factor(my_data$Yeo_7network)
my_data$Yeo_17network <- as.factor(my_data$Yeo_17network)
setkey(my_data, index)
setindex(my_data, name)
my_data
brainnetome_surface = my_data
save(brainnetome_surface, file='brainnetome_surface.rda')"
load('brainnetome_surface.rda')
brainnetome_surface
## --------------------------------------------------------------------------
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('all_subs_152_info.csv') # subs=152
inds = lapply(grps, function(x) covars.all[all_group == x, which = TRUE]) # 1=health=39, 2=patient=40
matfiles <- paste0('NetResults_invnodal/', covars.all$participant_id, '/raw_func_', covars.all$participant_id, '_invnodal.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]], 'brainnetome_surface' , level='subject',
modality = 'fmri',threshold = densities[i],
weighted = TRUE, gnames = covars.all$participant_id,
grpNames = covars.all$all_group )
}
saveRDS(gw.sub, file=file.path('BrainGraphRDS/', 'CFS_func_weighted_subject.rds'), compress = 'xz')
save2dataframe(gw.sub, file=file.path('BrainGraphRDS/', 'CFS_func_weighted_subject'))
#### CFS: fiber network graph weighted subject level
matfiles <- paste0('NetResults_invnodal/', covars.all$participant_id, '/raw_fiber_', covars.all$participant_id, '_invnodal.txt')
my.mats <- create_mats(matfiles, modality = 'dti',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]], 'brainnetome_surface', level='subject',
modality = 'dti',threshold = densities[i],
weighted = TRUE, gnames = covars.all$participant_id,
grpNames = covars.all$all_group )
}
saveRDS(gw.sub, file=file.path(out_dir, 'CFS_fiber_weighted_subject.rds'), compress = 'xz')
save2dataframe(gw.sub, file=file.path(out_dir, 'CFS_fiber_weighted_subject'))
## --------------------------------------------------------------------------
########## end. author@kangwu