-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractvars.R
88 lines (67 loc) · 2.9 KB
/
extractvars.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
# vars --------------------------------------------------------------------
library(tidyverse)
ses.mri <- read.csv(file = 'D:/projects/SES_anat/leisure_med/data/FS_SES_841_IMPUTE.csv') %>%
select(ID:GDS, EstimatedTotalIntraCranialVol) %>%
mutate_at(vars('ID', 'MRIID'), funs(as.character)) %>%
rename(TIV = EstimatedTotalIntraCranialVol)
ses.med <- ses.mri
ses.med$MRIID <- as.numeric(ses.med$MRIID)
ses.med$MRIID <- sprintf('sub-%04d', ses.med$MRIID)
ses.med <- ses.med %>%
arrange(MRIID) %>%
write_csv(file = 'D:/projects/SES_anat/leisure_med/derivatives/ses_med_beh.csv',
col_names = T)
# sourcedata.folder <- 'D:\\Projects\\SES_T1\\data\\sourcedata'
# subject.folders <- list.dirs(sourcedata.folder, recursive = F, full.names = F)
# sub <- gsub('.*sub-(\\d+).*', '\\1', subject.folders)
# sub <- as.data.frame(sub)
mat.file <- Sys.glob(file.path('./sourcedata/new', "sub-*.txt"))
sub <- gsub('.*sub-(\\d+).*', '\\1', mat.file)
sub <- as.data.frame(sub)
ses.func <- left_join(sub, ses.mri, by = c('sub' = 'MRIID')) %>%
mutate(sub = as.numeric(sub)
# GENDER = fct_recode(GENDER,
# '0' = 'Male',
# '1' = 'Female')
) %>%
arrange(sub)
ses.func$sub <- sprintf('sub-%04d', ses.func$sub)
ses.func %>%
write.csv(file = './derivatives/vars.csv')
write_delim(file = './derivatives/graphvars.csv',
delim = ';')
cov.ses <- ses.funcfc %>%
select(SES) %>%
write_csv(file = 'E:\\derivatives\\func_cov_ses.csv', col_names = F)
cov.group <- ses.funcfc %>%
select(NEWSESGROUP) %>%
write_csv(file = 'E:\\derivatives\\func_cov_group.csv', col_names = F)
cov.age <- ses.funcfc %>%
select(AGE) %>%
write_csv(file = 'E:\\derivatives\\func_cov_age.csv', col_names = F)
cov.gender <- ses.funcfc %>%
select(GENDER) %>%
write_csv(file = 'E:\\derivatives\\func_cov_gender.csv', col_names = F)
# atlas -------------------------------------------------------------------
bna <- read_csv('./atlas/subregion_func_network_Yeo_updated.csv') %>%
select(Label:region)
coordinate <- read_csv('./atlas/BNA_subregions.csv')
coordinate <- coordinate[,c(1:3 ,6:7)]
coordinate.l <- coordinate[,c(2,5)] %>%
rename(ID = `Label ID.L`,
MNI = `lh.MNI(X,Y,Z)`)
coordinate.r <- coordinate[,c(3,6)] %>%
rename(ID = `Label ID.R`,
MNI = `rh.MNI(X,Y,Z)`)
coordinate <- rbind(coordinate.l, coordinate.r) %>%
left_join(bna, ., by = c('Label' = 'ID')) %>%
separate(MNI, into = c('x', 'y', 'z'), sep = ',')
coordinate$Label <- 1
brainregions <- coordinate %>%
select(Label, region, region, x, y, z) %>%
cbind(., coordinate$region) %>%
rename(desc = `coordinate$region`) %>%
select(Label, region, desc, x, y, z) %>%
write_delim(file = './atlas/BrainRegion_BN_Atlas.csv',
delim = ';',
col_names = F)