-
Notifications
You must be signed in to change notification settings - Fork 0
/
giotto.visium.kidney.html
616 lines (516 loc) · 29.4 KB
/
giotto.visium.kidney.html
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
<!DOCTYPE html>
<html>
<head>
<title>Giotto</title>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<script src="js/jquery.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<link rel="stylesheet" href="css/jquery-ui.min.css">
<link rel="stylesheet" href="css/bootstrap.4.1.0.min.css">
<link rel="stylesheet" href="css/carousel.css">
<link rel="stylesheet" href="css/prism.css">
<link rel="stylesheet" href="css/giotto.css">
<script src="js/bootstrap.4.1.0.min.js"></script>
<script src="js/carousel.js"></script>
<script src="js/prism.js"></script>
<script src="js/giotto.js"></script>
</head>
<body data-spy="scroll" data-target="#nex2" data-offset="80">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Giotto</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="giotto.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="documentation2.html">Documentation</a>
</li>
<li class="nav-item">
<a class="nav-link" href="giotto.install.2.html">Installation</a>
</li>
<li class="nav-item">
<a class="nav-link" href="giotto.dataset.html">Dataset Examples</a>
</li>
<li class="nav-item">
<a class="nav-link" href="giotto.download.html">Download</a>
</li>
<!--
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
-->
</ul>
</nav>
<div class="container-fluid">
<div class="row">
<nav class="col-md-2 d-none d-md-block bg-light sidebar">
<div class="sidebar-sticky">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" href="giotto.dataset.html">
Main page <span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="giotto.osmFISH.html">
osmFISH dataset
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="giotto.slideseq.html">
slideSeq part 1
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="giotto.slideseq2.html">
slideSeq part 2
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="giotto.cycif.html">
cyCIF dataset
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="giotto.seqfish.html">
seqFISH+ dataset
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="giotto.codex.html">
CODEX spleen
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="giotto.visium.brain.html">
Visium brain
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="giotto.visium.kidney.html">
Visium kidney
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="giotto.merfish.html">
merFISH hypothalamus
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="giotto.starmap.html">
STARmap dataset
</a>
</li>
</ul>
</div>
</nav>
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
<h1 class="h2">10X Visium kidney dataset </h1>
</div>
<!--
<nav id="nex2" class="navbar sticky-top navbar-light bg-light">
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" href="#s_create_giotto">Data loading</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#s_clustering">Clustering</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#s_marker_gene">Marker genes</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#s_spatial_subset">Spatial subsets</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#s_spatial_dist">Spatial distr</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#s_annotate_clust">Annotate clusters</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#s_analyses_paper">Analyses (paper)</a>
</li>
</ul>
</nav>
-->
<p>The Visium kidney data to run this tutorial can be found <a href="https://support.10xgenomics.com/spatial-gene-expression/datasets/1.0.0/V1_Mouse_Kidney">here</a></p>
<h4>Giotto global instructions</h4>
<pre><code class="language-R">library(Giotto)
## create instructions
## instructions allow us to automatically save all plots into a chosen results folder
## Here we will automatically save plots, for an example without automatic saving see the visium brain dataset
my_python_path = "/your/python/path/python"
results_folder = '/your/results/path/'
instrs = createGiottoInstructions(python_path = my_python_path,
save_dir = results_folder,
show_plot = F, return_plot = T, save_plot = T,
plot_format = 'png', dpi = 300, height = 9, width = 9)
</code></pre>
<h4>part 1: Data input</h4>
<p><a href="https://www.10xgenomics.com/spatial-transcriptomics/">10X genomics</a> recently launched a new platform to obtain spatial expression data using a Visium Spatial Gene Expression slide.</p>
<p><img src="figures/visium.kidney/visium_technology.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R">## expression and cell location
## expression data
data_dir = "path/to/Visum_data/"
data_path = paste0(data_dir,'raw_feature_bc_matrix/')
raw_matrix = get10Xmatrix(path_to_data = data_path, gene_column_index = 2) # gene symbol is in the 2nd column
## spatial locations and metadata
spatial_locations = fread(paste0(data_dir,'spatial/tissue_positions_list.csv'))
spatial_locations = spatial_locations[match(colnames(raw_matrix), V1)]
colnames(spatial_locations) = c('barcode', 'in_tissue', 'array_row', 'array_col', 'col_pxl', 'row_pxl')
</code></pre>
<p>High resolution png from original tissue.<br/>
<img src="figures/visium.kidney/mouse_kidney_highres.png" class="img-fluid" style="max-width:50%"></img></p>
<h4>part 2: Create Giotto object & process data</h4>
<pre><code class="language-R">## we need to reverse the column pixel to get the same .jpg image as provided by 10X
visium_kidney <- createGiottoObject(raw_exprs = raw_matrix,
spatial_locs = spatial_results[,.(row_pxl,-col_pxl)],
instructions = instrs,
cell_metadata = spatial_results[,.(in_tissue, array_row, array_col)])
## check metadata
pDataDT(visium_kidney)
## compare in tissue with provided jpg
spatPlot(gobject = visium_kidney, cell_color = 'in_tissue', point_size = 2,
cell_color_code = c('0' = 'lightgrey', '1' = 'blue'),
save_param = list(save_name = '2_in_tissue'))
</code></pre>
<p><img src="figures/visium.kidney/2_in_tissue.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R">## subset on spots that were covered by tissue
metadata = pDataDT(visium_kidney)
in_tissue_barcodes = metadata[in_tissue == 1]$cell_ID
visium_kidney = subsetGiotto(visium_kidney, cell_ids = in_tissue_barcodes)
## filter
visium_kidney <- filterGiotto(gobject = visium_kidney,
expression_threshold = 1,
gene_det_in_min_cells = 50,
min_det_genes_per_cell = 1000,
expression_values = c('raw'),
verbose = T)
## normalize
visium_kidney <- normalizeGiotto(gobject = visium_kidney, scalefactor = 6000, verbose = T)
## add gene & cell statistics
visium_kidney <- addStatistics(gobject = visium_kidney)
## visualize
spatPlot2D(gobject = visium_kidney,
save_param = list(save_name = '2_spatial_locations'))
</code></pre>
<p><img src="figures/visium.kidney/2_spatial_locations.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R">spatPlot2D(gobject = visium_kidney, cell_color = 'nr_genes', color_as_factor = F,
save_param = list(save_name = '2_nr_genes'))
</code></pre>
<p><img src="figures/visium.kidney/2_nr_genes.png" class="img-fluid" style="max-width:50%"></img></p>
<h4>part 3: dimension reduction</h4>
<pre><code class="language-R">## highly variable genes (HVG)
visium_kidney <- calculateHVG(gobject = visium_kidney,
save_param = list(save_name = '3_HVGplot'))
</code></pre>
<p><img src="figures/visium.kidney/3_HVGplot.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R">## select genes based on HVG and gene statistics, both found in gene metadata
gene_metadata = fDataDT(visium_kidney)
featgenes = gene_metadata[hvg == 'yes' & perc_cells > 4 & mean_expr_det > 0.5]$gene_ID
## run PCA on expression values (default)
visium_kidney <- runPCA(gobject = visium_kidney, genes_to_use = featgenes, scale_unit = F)
signPCA(visium_kidney, genes_to_use = featgenes, scale_unit = F,
save_param = list(save_name = '3_screeplot'))
</code></pre>
<p><img src="figures/visium.kidney/3_screeplot.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R">plotPCA(gobject = visium_kidney,
save_param = list(save_name = '3_PCA_reduction'))
</code></pre>
<p><img src="figures/visium.kidney/3_PCA_reduction.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R">## run UMAP and tSNE on PCA space (default)
visium_kidney <- runUMAP(visium_kidney, dimensions_to_use = 1:10)
plotUMAP(gobject = visium_kidney,
save_param = list(save_name = '3_UMAP_reduction'))
</code></pre>
<p><img src="figures/visium.kidney/3_UMAP_reduction.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R">visium_kidney <- runtSNE(visium_kidney, dimensions_to_use = 1:10)
plotTSNE(gobject = visium_kidney,
save_param = list(save_name = '3_tSNE_reduction'))
</code></pre>
<p><img src="figures/visium.kidney/3_tSNE_reduction.png" class="img-fluid" style="max-width:50%"></img></p>
<h4>part 4: cluster</h4>
<pre><code class="language-R">## sNN network (default)
visium_kidney <- createNearestNetwork(gobject = visium_kidney, dimensions_to_use = 1:10, k = 15)
## Leiden clustering
visium_kidney <- doLeidenCluster(gobject = visium_kidney, resolution = 0.4, n_iterations = 1000)
plotUMAP(gobject = visium_kidney,
cell_color = 'leiden_clus', show_NN_network = T, point_size = 2.5,
save_param = list(save_name = '4_UMAP_leiden'))
</code></pre>
<p><img src="figures/visium.kidney/4_UMAP_leiden.png" class="img-fluid" style="max-width:50%"></img></p>
<h4>part 5: co-visualize</h4>
<pre><code class="language-R"># expression and spatial
spatDimPlot(gobject = visium_kidney, cell_color = 'leiden_clus',
dim_point_size = 2, spat_point_size = 2.5,
save_param = list(save_name = '5_covis_leiden'))
</code></pre>
<p><img src="figures/visium.kidney/5_covis_leiden.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R">spatDimPlot(gobject = visium_kidney, cell_color = 'nr_genes', color_as_factor = F,
dim_point_size = 2, spat_point_size = 2.5,
save_param = list(save_name = '5_nr_genes'))
</code></pre>
<p><img src="figures/visium.kidney/5_nr_genes.png" class="img-fluid" style="max-width:50%"></img></p>
<h4>part 6: cell type marker gene detection</h4>
<h4>gini</h4>
<pre><code class="language-R">## ---- ##
gini_markers_subclusters = findMarkers_one_vs_all(gobject = visium_kidney,
method = 'gini',
expression_values = 'normalized',
cluster_column = 'leiden_clus',
min_genes = 20,
min_expr_gini_score = 0.5,
min_det_gini_score = 0.5)
topgenes_gini = gini_markers_subclusters[, head(.SD, 2), by = 'cluster']$genes
# violinplot
violinPlot(visium_kidney, genes = unique(topgenes_gini), cluster_column = 'leiden_clus',
strip_text = 8, strip_position = 'right',
save_param = c(save_name = '6_violinplot_gini', base_width = 5, base_height = 10))
</code></pre>
<p><img src="figures/visium.kidney/6_violinplot_gini.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R"># cluster heatmap
my_cluster_order = c(2, 4, 5, 3, 6, 7, 8, 9, 10, 1)
plotMetaDataHeatmap(visium_kidney, selected_genes = topgenes_gini, custom_cluster_order = my_cluster_order,
metadata_cols = c('leiden_clus'), x_text_size = 10, y_text_size = 10,
save_param = c(save_name = '6_metaheatmap_gini'))
</code></pre>
<p><img src="figures/visium.kidney/6_metaheatmap_gini.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R"># umap plots
dimGenePlot2D(visium_kidney, expression_values = 'scaled',
genes = gini_markers_subclusters[, head(.SD, 1), by = 'cluster']$genes,
cow_n_col = 3, point_size = 1,
genes_high_color = 'red', genes_mid_color = 'white', genes_low_color = 'darkblue', midpoint = 0,
save_param = c(save_name = '6_gini_umap', base_width = 8, base_height = 5))
</code></pre>
<p><img src="figures/visium.kidney/6_gini_umap.png" class="img-fluid" style="max-width:50%"></img></p>
<h4>scran</h4>
<pre><code class="language-R">## ----- ##
scran_markers_subclusters = findMarkers_one_vs_all(gobject = visium_kidney,
method = 'scran',
expression_values = 'normalized',
cluster_column = 'leiden_clus')
topgenes_scran = scran_markers_subclusters[, head(.SD, 2), by = 'cluster']$genes
# violinplot
violinPlot(visium_kidney, genes = unique(topgenes_scran), cluster_column = 'leiden_clus',
strip_text = 10, strip_position = 'right',
save_param = c(save_name = '6_violinplot_scran', base_width = 5))
</code></pre>
<p><img src="figures/visium.kidney/6_violinplot_scran.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R"># cluster heatmap
plotMetaDataHeatmap(visium_kidney, selected_genes = topgenes_scran, custom_cluster_order = my_cluster_order,
metadata_cols = c('leiden_clus'),
save_param = c(save_name = '6_metaheatmap_scran'))
</code></pre>
<p><img src="figures/visium.kidney/6_metaheatmap_scran.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R"># umap plots
dimGenePlot(visium_kidney, expression_values = 'scaled',
genes = scran_markers_subclusters[, head(.SD, 1), by = 'cluster']$genes,
cow_n_col = 3, point_size = 1,
genes_high_color = 'red', genes_mid_color = 'white', genes_low_color = 'darkblue', midpoint = 0,
save_param = c(save_name = '6_scran_umap', base_width = 8, base_height = 5))
</code></pre>
<p><img src="figures/visium.kidney/6_scran_umap.png" class="img-fluid" style="max-width:50%"></img></p>
<h4>part 7: cell-type annotation</h4>
<p>Visium spatial transcriptomics does not provide single-cell resolution, making cell type annotation a harder problem. Giotto provides 3 ways to calculate enrichment of specific cell-type signature gene list: </p>
<ul>
<li>PAGE<br/></li>
<li>rank<br/></li>
<li>hypergeometric test</li>
</ul>
<p>See the <a href="./mouse_visium_brain_200325.html">mouse Visium brain dataset</a> for an example.</p>
<h4>part 8: spatial grid</h4>
<pre><code class="language-R">visium_kidney <- createSpatialGrid(gobject = visium_kidney,
sdimx_stepsize = 400,
sdimy_stepsize = 400,
minimum_padding = 0)
spatPlot(visium_kidney, cell_color = 'leiden_clus', show_grid = T,
grid_color = 'red', spatial_grid_name = 'spatial_grid',
save_param = c(save_name = '8_grid'))
</code></pre>
<p><img src="figures/visium.kidney/8_grid.png" class="img-fluid" style="max-width:50%"></img></p>
<h4>part 9: spatial network</h4>
<pre><code class="language-R">## (default) delaunay network: stats + creation
plotStatDelaunayNetwork(gobject = visium_kidney, maximum_distance = 400, save_plot = F)
visium_kidney = createSpatialNetwork(gobject = visium_kidney, maximum_distance_delaunay = 400, minimum_k = 2)
spatPlot(gobject = visium_kidney, show_network = T,
network_color = 'blue', spatial_network_name = 'delaunay_network',
save_param = c(save_name = '9_delaunay_network'))
</code></pre>
<p><img src="figures/visium.kidney/9_delaunay_network.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R">## kNN network
visium_kidney <- createSpatialNetwork(gobject = visium_kidney, method = 'kNN', k = 5, maximum_distance_knn = 400)
spatPlot(gobject = visium_kidney, show_network = T,
network_color = 'blue', spatial_network_name = 'spatial_network',
save_param = c(save_name = '9_spatial_network_k5'))
</code></pre>
<p><img src="figures/visium.kidney/9_spatial_network_k5.png" class="img-fluid" style="max-width:50%"></img></p>
<h4>part 10: spatial genes</h4>
<h5>Spatial genes</h5>
<pre><code class="language-R">## kmeans binarization
kmtest = binSpect(visium_kidney, bin_method = 'kmeans',
do_fisher_test = T,
spatial_network_name = 'delaunay_network', verbose = T)
spatGenePlot(visium_kidney, expression_values = 'scaled',
genes = kmtest$genes[1:6], cow_n_col = 2, point_size = 1.5,
genes_high_color = 'red', genes_mid_color = 'white', genes_low_color = 'darkblue', midpoint = 0,
save_param = c(save_name = '10_spatial_genes_km'))
</code></pre>
<p><img src="figures/visium.kidney/10_spatial_genes_km.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R">## rank binarization
ranktest = binSpect(visium_kidney, bin_method = 'rank',
do_fisher_test = T, percentage_rank = 30,
spatial_network_name = 'delaunay_network', verbose = T)
spatGenePlot(visium_kidney, expression_values = 'scaled',
genes = ranktest$genes[1:6], cow_n_col = 2, point_size = 1.5,
genes_high_color = 'red', genes_mid_color = 'white', genes_low_color = 'darkblue', midpoint = 0,
save_param = c(save_name = '10_spatial_genes_rank'))
</code></pre>
<p><img src="figures/visium.kidney/10_spatial_genes_rank.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R">## silhouette
spatial_genes = silhouetteRank(gobject = visium_kidney,
expression_values = 'scaled',
rbp_p=0.95, examine_top=0.3)
spatGenePlot(visium_kidney, expression_values = 'scaled',
genes = spatial_genes$genes[1:6], cow_n_col = 2, point_size = 1.5,
genes_high_color = 'red', genes_mid_color = 'white', genes_low_color = 'darkblue', midpoint = 0,
save_param = c(save_name = '10_spatial_genes'))
</code></pre>
<p><img src="figures/visium.kidney/10_spatial_genes.png" class="img-fluid" style="max-width:50%"></img></p>
<h5>Spatial co-expression patterns</h5>
<pre><code class="language-R">## spatially correlated genes ##
ext_spatial_genes = kmtest[1:500]$genes
# 1. calculate gene spatial correlation and single-cell correlation
# create spatial correlation object
spat_cor_netw_DT = detectSpatialCorGenes(visium_kidney,
method = 'network', spatial_network_name = 'delaunay_network',
subset_genes = ext_spatial_genes)
# 2. identify most similar spatially correlated genes for one gene
Napsa_top10_genes = showSpatialCorGenes(spat_cor_netw_DT, genes = 'Napsa', show_top_genes = 10)
spatGenePlot(visium_kidney, expression_values = 'scaled',
genes = c('Napsa', 'Kap', 'Defb29', 'Prdx1'), point_size = 3,
save_param = c(save_name = '10_Napsa_correlated_genes'))
</code></pre>
<p><img src="figures/visium.kidney/10_Napsa_correlated_genes.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R"># 3. cluster correlated genes & visualize
spat_cor_netw_DT = clusterSpatialCorGenes(spat_cor_netw_DT, name = 'spat_netw_clus', k = 8)
heatmSpatialCorGenes(visium_kidney, spatCorObject = spat_cor_netw_DT, use_clus_name = 'spat_netw_clus',
save_param = c(save_name = '10_heatmap_correlated_genes', save_format = 'pdf',
base_height = 6, base_width = 8, units = 'cm'),
heatmap_legend_param = list(title = NULL))
</code></pre>
<p><img src="figures/visium.kidney/10_heatmap_correlated_genes.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R"># 4. rank spatial correlated clusters and show genes for selected clusters
netw_ranks = rankSpatialCorGroups(visium_kidney, spatCorObject = spat_cor_netw_DT, use_clus_name = 'spat_netw_clus',
save_param = c(save_name = '10_rank_correlated_groups',
base_height = 3, base_width = 5))
</code></pre>
<p><img src="figures/visium.kidney/10_rank_correlated_groups.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R">top_netw_spat_cluster = showSpatialCorGenes(spat_cor_netw_DT, use_clus_name = 'spat_netw_clus',
selected_clusters = 6, show_top_genes = 1)
# 5. create metagene enrichment score for clusters
cluster_genes_DT = showSpatialCorGenes(spat_cor_netw_DT, use_clus_name = 'spat_netw_clus', show_top_genes = 1)
cluster_genes = cluster_genes_DT$clus; names(cluster_genes) = cluster_genes_DT$gene_ID
visium_kidney = createMetagenes(visium_kidney, gene_clusters = cluster_genes, name = 'cluster_metagene')
spatCellPlot(visium_kidney,
spat_enr_names = 'cluster_metagene',
cell_annotation_values = netw_ranks$clusters,
point_size = 1.5, cow_n_col = 4,
save_param = c(save_name = '10_spat_enrichment_score_plots',
base_width = 13, base_height = 6))
</code></pre>
<p><img src="figures/visium.kidney/10_spat_enrichment_score_plots.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R"># example for gene per cluster
top_netw_spat_cluster = showSpatialCorGenes(spat_cor_netw_DT, use_clus_name = 'spat_netw_clus',
selected_clusters = 1:8, show_top_genes = 1)
first_genes = top_netw_spat_cluster[, head(.SD, 1), by = clus]$gene_ID
cluster_names = top_netw_spat_cluster[, head(.SD, 1), by = clus]$clus
names(first_genes) = cluster_names
first_genes = first_genes[as.character(netw_ranks$clusters)]
spatGenePlot(visium_kidney, genes = first_genes, expression_values = 'scaled', cow_n_col = 4, midpoint = 0, point_size = 2,
save_param = c(save_name = '10_spat_enrichment_score_plots_genes',
base_width = 11, base_height = 6))
</code></pre>
<p><img src="figures/visium.kidney/10_spat_enrichment_score_plots_genes.png" class="img-fluid" style="max-width:50%"></img></p>
<!--
<h4>part 11: HMRF domains</h4>
<pre><code class="language-R"># spatial genes
my_spatial_genes <- kmtest[1:100]$genes
# do HMRF with different betas
hmrf_folder = paste0(results_folder,'/','11_HMRF/')
if(!file.exists(hmrf_folder)) dir.create(hmrf_folder, recursive = T)
HMRF_spatial_genes = doHMRF(gobject = visium_kidney, expression_values = 'scaled',
spatial_network_name = 'delaunay_network',
spatial_genes = my_spatial_genes,
k = 5,
betas = c(0, 1, 6),
output_folder = paste0(hmrf_folder, '/', 'Spatial_genes/SG_topgenes_k5_scaled'))
## view results of HMRF
## results not displayed
for(i in seq(0, 5, by = 1)) {
viewHMRFresults2D(gobject = visium_kidney,
HMRFoutput = HMRF_spatial_genes,
k = 5, betas_to_view = i,
point_size = 2)
}
</code></pre>
<pre><code class="language-R">## alternative way to view HMRF results
#results = writeHMRFresults(gobject = ST_test,
# HMRFoutput = HMRF_spatial_genes,
# k = 5, betas_to_view = seq(0, 25, by = 5))
#ST_test = addCellMetadata(ST_test, new_metadata = results, by_column = T, column_cell_ID = 'cell_ID')
## add HMRF of interest to giotto object
visium_kidney = addHMRF(gobject = visium_kidney,
HMRFoutput = HMRF_spatial_genes,
k = 5, betas_to_add = c(0, 2),
hmrf_name = 'HMRF')
## visualize
spatPlot(gobject = visium_kidney, cell_color = 'HMRF_k5_b.0', point_size = 5,
save_param = c(save_name = '11_HMRF_k5_b.0'))
</code></pre>
<p><img src="figures/visium.kidney/11_HMRF_k5_b.0.png" class="img-fluid" style="max-width:50%"></img></p>
<pre><code class="language-R">spatPlot(gobject = visium_kidney, cell_color = 'HMRF_k5_b.2', point_size = 5,
save_param = c(save_name = '11_HMRF_k5_b.2'))
</code></pre>
<p><img src="figures/visium.kidney/11_HMRF_k5_b.2.png" class="img-fluid" style="max-width:50%"></img></p>
-->
<h4>Export and create Giotto Viewer</h4>
<pre><code class="language-R"># check which annotations are available
combineMetadata(visium_kidney, spat_enr_names = 'PAGE')
# select annotations, reductions and expression values to view in Giotto Viewer
viewer_folder = paste0(results_folder, '/', 'mouse_visium_kidney_viewer')
exportGiottoViewer(gobject = visium_kidney,
output_directory = viewer_folder,
spat_enr_names = 'PAGE',
factor_annotations = c('in_tissue',
'leiden_clus',
'MRF_k5_b.2'),
numeric_annotations = c('nr_genes',
'clus_25'),
dim_reductions = c('tsne', 'umap'),
dim_reduction_names = c('tsne', 'umap'),
expression_values = 'scaled',
expression_rounding = 2,
overwrite_dir = T)
</code></pre>
</main>
</div>
</div>
</body>
</html>