-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_construct_NetGraph_SCN.R
More file actions
101 lines (82 loc) · 3.61 KB
/
run_construct_NetGraph_SCN.R
File metadata and controls
101 lines (82 loc) · 3.61 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
library(data.table)
library(brainGraph)
OS <- .Platform$OS.type
if (OS == 'windows'){
pacman::p_load(snow, doSNOW)
num.cores <- as.numeric(Sys.getenv('NUMBER_OF_PROCESSORS'))
cl <- makeCluster(num.cores, type='SOCK')
clusterExport(cl, 'sim.rand.graph.par')
registerDoSNOW(cl)
} else {
suppressMessages(library(doMC))
registerDoMC(detectCores()-1)
}
options(bg.subject_id='participant_id', bg.group='all_group')
lhrh <- fread('BrainGraphRDS/CFS_thickness_mat_exclude_Subject_019.csv')
# sort name
load('brainnetome_surface.rda')
assign("brainnetome", brainnetome_surface, envir = .GlobalEnv)
setkey(brainnetome_surface, index)
newname <- c('participant_id', brainnetome_surface$name)
colnames(lhrh) <- newname
# begin
covars.all <- fread('subs_146_info.csv')
covars.all = covars.all[subject!='Subject_019', ]
covars.all[, sex := as.factor(sex)]
covars <- covars.all[,c('age', 'sex', 'BMI', 'participant_id', 'all_group')]
myResids <- get.resid(lhrh, covars, atlas = 'brainnetome', exclude.cov = 'all_group')
densities <- seq(0.01, 0.34, 0.01)
corrs <- corr.matrix(myResids, densities=densities)
g <- lapply(seq_along(densities), function(x)
make_brainGraphList(corrs[x], modality='thickness'))
dt.G <- rbindlist(lapply(g, graph_attr_dt))
dt.V <- rbindlist(lapply(g, vertex_attr_dt))
fwrite(dt.G, 'BrainGraphRDS/CFS_thickness_scn_graph.csv')
fwrite(dt.V, 'BrainGraphRDS/CFS_thickness_scn_vertex.csv')
########################################
options(bg.subject_id='participant_id', bg.group='all_group')
lhrh <- fread('BrainGraphRDS/CFS_coupling_mat_exclude_Subject_019.csv')
# sort name
load('brainnetome_surface.rda')
assign("brainnetome", brainnetome_surface, envir = .GlobalEnv)
setkey(brainnetome_surface, index)
newname <- c('participant_id', brainnetome_surface$name)
colnames(lhrh) <- newname
# begin
covars.all <- fread('subs_146_info.csv')
covars.all = covars.all[subject!='Subject_019', ]
covars.all[, sex := as.factor(sex)]
covars <- covars.all[,c('age', 'sex', 'BMI', 'participant_id', 'all_group')]
myResids <- get.resid(lhrh, covars, atlas = 'brainnetome', exclude.cov = 'all_group')
densities <- seq(0.01, 0.34, 0.01)
corrs <- corr.matrix(myResids, densities=densities, what = 'raw') # raw
g <- lapply(seq_along(densities), function(x)
make_brainGraphList(corrs[x], modality='coupling'))
dt.G <- rbindlist(lapply(g, graph_attr_dt))
dt.V <- rbindlist(lapply(g, vertex_attr_dt))
fwrite(dt.G, 'BrainGraphRDS/CFS_coupling_scn_graph.csv')
fwrite(dt.V, 'BrainGraphRDS/CFS_coupling_scn_vertex.csv')
########################################
options(bg.subject_id='participant_id', bg.group='all_group')
lhrh <- fread('BrainGraphRDS/CFS_coupling_mat_exclude_Subject_019.csv')
# sort name
load('brainnetome_surface.rda')
assign("brainnetome", brainnetome_surface, envir = .GlobalEnv)
setkey(brainnetome_surface, index)
newname <- c('participant_id', brainnetome_surface$name)
colnames(lhrh) <- newname
# begin
covars.all <- fread('subs_146_info.csv')
covars.all = covars.all[subject!='Subject_019', ]
covars.all[, sex := as.factor(sex)]
covars <- covars.all[,c('age', 'sex', 'BMI', 'participant_id', 'all_group')]
myResids <- get.resid(lhrh, covars, atlas = 'brainnetome', exclude.cov = 'all_group')
densities <- seq(0.01, 0.34, 0.01)
corrs <- corr.matrix(myResids, densities=densities) # raw
g <- lapply(seq_along(densities), function(x)
make_brainGraphList(corrs[x], modality='coupling'))
dt.G <- rbindlist(lapply(g, graph_attr_dt))
dt.V <- rbindlist(lapply(g, vertex_attr_dt))
fwrite(dt.G, 'BrainGraphRDS/CFS_coupling_residual_scn_graph.csv')
fwrite(dt.V, 'BrainGraphRDS/CFS_coupling_residual_scn_vertex.csv')
########## end. author@kangwu