-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlookup_roi_names.R
executable file
·49 lines (38 loc) · 1.41 KB
/
lookup_roi_names.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
#!/usr/bin/env Rscript
#read in command line arguments.
args <- commandArgs(trailingOnly = FALSE)
scriptpath <- dirname(sub("--file=", "", grep("--file=", args, fixed=TRUE, value=TRUE), fixed=TRUE))
argpos <- grep("--args", args, fixed=TRUE)
if (length(argpos) > 0L) {
args <- args[(argpos+1):length(args)]
} else {
args <- c()
}
if (length(args) < 1L) stop("Expects 1 argument: name of nifti containing regions")
if (length(args) == 2L) {
out_file <- args[2L]
} else {
out_file <- "roi_labels.csv"
}
library(fmri.pipeline)
library(glue)
library(dplyr)
#atlas <- "/proj/mnhallqlab/projects/clock_analysis/fmri/pfc_entropy/masks/Schaefer_DorsAttn_2.3mm.nii.gz"
atlas <- args[1L]
# these will be in RAI orientation (aka 'DICOM') and the first row is ROI = 0 (not interesting)
system(glue("3dCM -all_rois '{atlas}' > atlas_cm.txt"))
roi_cms <- read.table("atlas_cm.txt")[-1, ] # drop the first row (0 ROI value)
write.table(roi_cms, file = "atlas_cm.txt", row.names = F, col.names = F)
wami_obj <- afni_whereami$new(
coord_file = "atlas_cm.txt",
coord_orientation = "RAI", coord_space = "MNI", coord_file_columns = 0:2
)
wami_obj$run(force=TRUE)
label_df <- wami_obj$get_whereami_df()
unlink("atlas_cm.txt")
unlink("atlas_cm_whereami.txt")
label_df <- label_df %>%
arrange(x,y,z) %>%
mutate(spatial_roi_num = 1:n()) %>%
select(roi_num, spatial_roi_num, everything())
write.csv(label_df, file=out_file, row.names=FALSE)