-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvertex.Rmd
167 lines (121 loc) · 6.32 KB
/
vertex.Rmd
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
---
title: "R Notebook"
output: html_notebook
---
**This notebook will not work on RStudio Cloud (at least on the free account), due to the RAM requirements. **
We will now move onto visualizing surface/vertex-level data. In particular, we will focus on visualizing output from freesurfer, and use the awesome fsbrain package developed by Tim Schäfer & Christine Ecker (https://github.com/dfsp-spirit/fsbrain)
First lets install `fsbrain` and also an example freesurfer output for 2 subjects that comes with fsbrain. This can take a while (upto ~10mins):
```{r}
install.packages("fsbrain")
fsbrain::download_optional_data()
```
Lets set up the path to the example freesurfer output provided by fsbrain and a subject list for the two subjects in the example data, and then select one of the subjects for further visualization.
```{r}
library("fsbrain")
subjects_dir = fsbrain::get_optional_data_filepath("subjects_dir")
subjects_list = c("subject1", "subject2")
subject_id = 'subject1'
```
Lets first visualize the 'annotations', which are the atlas-based subject-specific parcellation generated by freesurfer, known as `aparc`. Visualization commands in fsbrain use a RGL graphics device and will open in a new window:
```{r}
vis.subject.annot(subjects_dir = subjects_dir,
subject_id = 'subject1',
atlas = 'aparc',
hemi = 'both',
views=c('si'))
```
Try changing the `views` to one of these option: 'si', 'sr', 't4' and 't9':
```{r}
vis.subject.annot(subjects_dir = subjects_dir,
subject_id = 'subject1',
atlas = 'aparc',
hemi = 'both',
views='sr')
```
We can also plot different metrics provided by freesurfer on the native subject surface, such as cortical thickness:
```{r}
vis.subject.morph.native(subjects_dir = subjects_dir,
subject_id = 'subject1',
measure = 'thickness',
hemi='both',
views=c('t4'))
```
Try plotting `area` or `volume` on only one hemisphere (`lh` or `rh`):
```{r}
vis.subject.morph.native(subjects_dir = subjects_dir,
subject_id = 'subject1',
measure = 'area',
hemi='rh',
views=c('si'))
```
You can also plot the native surface using .label files. Here we are just plotting the cortical lables on the white matter surface. It is also possible (and usually prefered) to plot on the inflated pial (grey matter) surface, but the example data provided does not include `inflated` surfaces to reduce the size of the example data.
```{r}
surface <- 'white'
hemi <- 'both'
label <- 'cortex.label'
vis.subject.label(subjects_dir = subjects_dir,
subject_id = subject_id,
label = label,
hemi = hemi)
```
We can also select specific vertices to highlight. Here, we will select just 5 vertices on both hemispheres, although usually effects are larger than just 5 vertices.
```{r}
surface <- 'white'
my_lh_result <- my_rh_result <- c(1000, 1001, 1002, 1003, 1004, 1005) #select 5 verticies
#Hint: this is a very small effect, have a look at in the occipital lobe to see if you can find it!
vis.labeldata.on.subject(subjects_dir = subjects_dir,
vis_subject_id = subject_id,
lh_labeldata = my_lh_result,
rh_labeldata = my_rh_result,
views = "si")
```
Lets make the effect on the right hemisphere larger:
```{r}
rh_labeldata <- 5000 #select a random vertex
rh_surface = subject.surface(subjects_dir, subject_id, surface, 'rh') # delcare the th surface
rh_labeldata_neighborhood = mesh.vertex.neighbors(rh_surface, rh_labeldata); # extend neighborhood for better visibility
rh_labeldata_neighborhood = mesh.vertex.neighbors(rh_surface, rh_labeldata_neighborhood$vertices) # extend neighborhood again
vis.labeldata.on.subject(subjects_dir,
subject_id,
my_lh_result,
rh_labeldata_neighborhood$vertices,
views=c('si'),
surface=surface)
```
Lets now try and visualize a specific region from the `aparc` atlas, but creating a mask of that region and overlaying it on the subjects' surface:
```{r}
surface = 'white'
hemi = 'both'
atlas = 'aparc'
region = 'bankssts' #Hint: you can see the list of labels on a aparc atlas by calling lh_annot$colortable$struct_names
# Create a mask from a region of an annotation:
lh_annot = subject.annot(subjects_dir, subject_id, 'lh', atlas)
rh_annot = subject.annot(subjects_dir, subject_id, 'rh', atlas)
lh_label = label.from.annotdata(lh_annot, region)
rh_label = label.from.annotdata(rh_annot, region)
lh_mask = mask.from.labeldata.for.hemi(lh_label, length(lh_annot$vertices))
rh_mask = mask.from.labeldata.for.hemi(rh_label, length(rh_annot$vertices))
# visualize it
vis.mask.on.subject(subjects_dir, subject_id, lh_mask, rh_mask)
```
Try visualising some of the other regions in the aparc atlas:
```{r}
surface = 'white'
hemi = 'both'
atlas = 'aparc'
region = '' #Hint: you can see the list of labels on a aparc atlas by calling lh_annot$colortable$struct_names
# Create a mask from a region of an annotation:
lh_annot = subject.annot(subjects_dir, subject_id, 'lh', atlas)
rh_annot = subject.annot(subjects_dir, subject_id, 'rh', atlas)
lh_label = label.from.annotdata(lh_annot, region)
rh_label = label.from.annotdata(rh_annot, region)
lh_mask = mask.from.labeldata.for.hemi(lh_label, length(lh_annot$vertices))
rh_mask = mask.from.labeldata.for.hemi(rh_label, length(rh_annot$vertices))
# visualize it
vis.mask.on.subject(subjects_dir, subject_id, lh_mask, rh_mask)
```
Please see the `fsbrian` vignette for a ton of other features, such as group-level visulisations: https://cran.r-project.org/web/packages/fsbrain/vignettes/fsbrain.html
If you are interested in plotting gifti and cifti data, check out:
* [ciftiTools](https://github.com/mandymejia/ciftiTools)
* [Blog by Jo Etzel](https://mvpa.blogspot.com/2020/03/volume-and-surface-brain-plotting-knitr.html)
Thanks to [Tim Schäfer & Christine Ecker](https://github.com/dfsp-spirit/fsbrain) for developing fsbrain, this notebook is largely based on their vignette.