[413088]: / docs / spotanalysis.html

Download this file

1051 lines (954 with data), 43.9 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
 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
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<title>Cell/Spot Analysis</title>
<script src="site_libs/header-attrs-2.29/header-attrs.js"></script>
<script src="site_libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/flatly.min.css" rel="stylesheet" />
<script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<style>h1 {font-size: 34px;}
h1.title {font-size: 38px;}
h2 {font-size: 30px;}
h3 {font-size: 24px;}
h4 {font-size: 18px;}
h5 {font-size: 16px;}
h6 {font-size: 12px;}
code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
pre:not([class]) { background-color: white }</style>
<script src="site_libs/jqueryui-1.13.2/jquery-ui.min.js"></script>
<link href="site_libs/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" />
<script src="site_libs/tocify-1.9.1/jquery.tocify.js"></script>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<link href="site_libs/highlightjs-9.12.0/textmate.css" rel="stylesheet" />
<script src="site_libs/highlightjs-9.12.0/highlight.js"></script>
<link href="site_libs/font-awesome-6.5.2/css/all.min.css" rel="stylesheet" />
<link href="site_libs/font-awesome-6.5.2/css/v4-shims.min.css" rel="stylesheet" />
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<style type="text/css">code{white-space: pre;}</style>
<script type="text/javascript">
if (window.hljs) {
hljs.configure({languages: []});
hljs.initHighlightingOnLoad();
if (document.readyState && document.readyState === "complete") {
window.setTimeout(function() { hljs.initHighlighting(); }, 0);
}
}
</script>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
img {
max-width:100%;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
details > summary > p:only-child {
display: inline;
}
pre code {
padding: 0;
}
</style>
<style type="text/css">
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #cccccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #adb5bd;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
border-radius: 6px 0 6px 6px;
}
</style>
<script type="text/javascript">
// manage active state of menu based on current page
$(document).ready(function () {
// active menu anchor
href = window.location.pathname
href = href.substr(href.lastIndexOf('/') + 1)
if (href === "")
href = "index.html";
var menuAnchor = $('a[href="' + href + '"]');
// mark the anchor link active (and if it's in a dropdown, also mark that active)
var dropdown = menuAnchor.closest('li.dropdown');
if (window.bootstrap) { // Bootstrap 4+
menuAnchor.addClass('active');
dropdown.find('> .dropdown-toggle').addClass('active');
} else { // Bootstrap 3
menuAnchor.parent().addClass('active');
dropdown.addClass('active');
}
// Navbar adjustments
var navHeight = $(".navbar").first().height() + 15;
var style = document.createElement('style');
var pt = "padding-top: " + navHeight + "px; ";
var mt = "margin-top: -" + navHeight + "px; ";
var css = "";
// offset scroll position for anchor links (for fixed navbar)
for (var i = 1; i <= 6; i++) {
css += ".section h" + i + "{ " + pt + mt + "}\n";
}
style.innerHTML = "body {" + pt + "padding-bottom: 40px; }\n" + css;
document.head.appendChild(style);
});
</script>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before, .tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "\e259";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "\e258";
font-family: 'Glyphicons Halflings';
border: none;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
background-color: transparent;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<!-- code folding -->
<style type="text/css">
#TOC {
margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
position: relative;
width: 100%;
}
}
@media print {
.toc-content {
/* see https://github.com/w3c/csswg-drafts/issues/4434 */
float: right;
}
}
.toc-content {
padding-left: 30px;
padding-right: 40px;
}
div.main-container {
max-width: 1200px;
}
div.tocify {
width: 20%;
max-width: 260px;
max-height: 85%;
}
@media (min-width: 768px) and (max-width: 991px) {
div.tocify {
width: 25%;
}
}
@media (max-width: 767px) {
div.tocify {
width: 100%;
max-width: none;
}
}
.tocify ul, .tocify li {
line-height: 20px;
}
.tocify-subheader .tocify-item {
font-size: 0.90em;
}
.tocify .list-group-item {
border-radius: 0px;
}
.tocify-subheader {
display: inline;
}
.tocify-subheader .tocify-item {
font-size: 0.95em;
}
</style>
</head>
<body>
<div class="container-fluid main-container">
<!-- setup 3col/9col grid for toc_float and main content -->
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-3">
<div id="TOC" class="tocify">
</div>
</div>
<div class="toc-content col-xs-12 col-sm-8 col-md-9">
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-bs-toggle="collapse" data-target="#navbar" data-bs-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">VoltRon</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="tutorials.html">Explore</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Vignette
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li class="dropdown-submenu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">Spatial Data Integration</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="registration.html">Spatial Data Alignment</a>
</li>
<li>
<a href="multiomic.html">Multi-omic Integration</a>
</li>
<li>
<a href="nicheclustering.html">Niche Clustering</a>
</li>
</ul>
</li>
<li class="dropdown-submenu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">Downstream Analysis</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="roianalysis.html">ROI Analysis</a>
</li>
<li>
<a href="spotanalysis.html">Cell/Spot Analysis</a>
</li>
<li>
<a href="moleculeanalysis.html">Molecule Analysis</a>
</li>
<li>
<a href="pixelanalysis.html">Pixels (Image Only) Analysis</a>
</li>
</ul>
</li>
<li class="dropdown-submenu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">Utilities</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="interactive.html">Interactive Utilities</a>
</li>
<li>
<a href="importingdata.html">Importing Spatial Data</a>
</li>
<li>
<a href="voltronobjects.html">Working with VoltRon Objects</a>
</li>
<li>
<a href="conversion.html">Converting VoltRon Objects</a>
</li>
<li>
<a href="ondisk.html">OnDisk-based Analysis Utilities</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-envelope-o"></span>
Contact
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="https://bioinformatics.mdc-berlin.de">Altuna Lab/BIMSB Bioinfo</a>
</li>
<li>
<a href="https://www.mdc-berlin.de/landthaler">Landthaler Lab/BIMSB</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-github"></span>
GitHub
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="https://github.com/BIMSBbioinfo/VoltRon">VoltRon</a>
</li>
<li>
<a href="https://github.com/BIMSBbioinfo">BIMSB Bioinfo</a>
</li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<div id="header">
<h1 class="title toc-ignore">Cell/Spot Analysis</h1>
</div>
<style>
.title{
display: none;
}
body {
text-align: justify
}
.center {
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
<style type="text/css">
.watch-out {
color: black;
}
</style>
<p><br></p>
<div id="xenium-data-analysis" class="section level1">
<h1>Xenium Data Analysis</h1>
<p>VoltRon is an end-to-end spatial omic analysis package which also
supports investigating spatial points in single cell resolution. VoltRon
includes essential built-in functions capable of
<strong>filtering</strong>, <strong>processing</strong> and
<strong>clustering</strong> as well as <strong>visualizing</strong>
spatial datasets with a goal of cell type discovery and annotation.</p>
<p>In this use case, we analyse readouts of the experiments conducted on
example tissue sections analysed by the <a
href="https://www.10xgenomics.com/platforms/xenium">Xenium In Situ</a>
platform. Two tissue sections of 5 <span
class="math inline">\(\mu\)</span>m tickness are derived from a single
formalin-fixed, paraffin-embedded (FFPE) breast cancer tissue block.
More information on the spatial datasets and the study can be also be
found on the <a
href="https://www.biorxiv.org/content/10.1101/2022.10.06.510405v1">BioArxiv
preprint</a>.</p>
<p>You can import these readouts from the <a
href="https://www.10xgenomics.com/products/xenium-in-situ/preview-dataset-human-breast">10x
Genomics website</a> (specifically, import <strong>In Situ Replicate
1/2</strong>). Alternatively, you can <strong>download a zipped
collection of Xenium readouts</strong> from <a
href="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/SpatialDataAlignment/Xenium_vs_Visium/10X_Xenium_Visium.zip">here</a>.</p>
<p><br></p>
<div id="building-voltron-objects" class="section level2">
<h2>Building VoltRon objects</h2>
<p>VoltRon includes built-in functions for converting readouts of Xenium
experiments into VoltRon objects. The <strong>importXenium</strong>
function locates all readout documents under the output folder of the
Xenium experiment, and forms a VoltRon object. We will import both
Xenium replicates separately, and merge them after some image
manipulation.</p>
<pre class="r watch-out"><code>library(VoltRon)
Xen_R1 &lt;- importXenium(&quot;Xenium_R1/outs&quot;, sample_name = &quot;XeniumR1&quot;, import_molecules = TRUE)
Xen_R2 &lt;- importXenium(&quot;Xenium_R2/outs&quot;, sample_name = &quot;XeniumR2&quot;, import_molecules = TRUE)</code></pre>
<p>Before moving on to the downstream analysis of the imaging-based
data, we can inspect both Xenium images. We use the
<strong>vrImages</strong> function to call and visualize reference
images of all VoltRon objects. Observe that the DAPI image of the second
Xenium replicate is dim, hence we might need to increase the
brightness.</p>
<pre class="r watch-out"><code>vrImages(Xen_R1)
vrImages(Xen_R2)</code></pre>
<table>
<tbody>
<tr style="vertical-align: center">
<td style="width:50%; vertical-align: center">
<img src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/xeniumr1.png" class="center">
</td>
<td style="width:50%; vertical-align: center">
<img src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/xeniumr2.png" class="center">
</td>
</tr>
</tbody>
</table>
<p><br></p>
<p>We can adjust the brightness of the second Xenium replicate using the
<strong>modulateImage</strong> function where we can change the
brightness and saturation of the reference image of this VoltRon object.
This functionality is optional for VoltRon objects and should be used
when images require further adjustments.</p>
<pre class="r watch-out"><code>Xen_R2 &lt;- modulateImage(Xen_R2, brightness = 800)
vrImages(Xen_R2)</code></pre>
<p><img width="40%" height="40%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/xeniumr2_new.png" class="center"></p>
<p><br></p>
<p>Once both VoltRon objects are created and images are well-tuned, we
can merge these two into a single VoltRon object.</p>
<pre class="r watch-out"><code>Xen_list &lt;- list(Xen_R1, Xen_R2)
Xen_data &lt;- merge(Xen_list[[1]], Xen_list[-1])</code></pre>
<pre><code>VoltRon Object
XeniumR1:
Layers: Section1
XeniumR2:
Layers: Section1
Assays: Xenium(Main) </code></pre>
<p><br></p>
</div>
<div id="spatial-visualization" class="section level2">
<h2>Spatial Visualization</h2>
<p>With <strong>vrSpatialPlot</strong>, we can visualize Xenium
experiments in both cellular and subcellular context. Since we have not
yet started analyzing raw counts of cells, we can first visualize some
transcripts of interest. We first visualize mRNAs of ACTA2, a marker for
smooth muscle cell actin, and TCF7, an early exhausted t cell marker. We
can interactively select a subset of interest within the tissue section
and visualize the localization of these transcripts. Here we subset a
ductal carcinoma niche, and visualize visualize mRNAs of
<strong>(i)</strong> ACTA2, a marker for smooth muscle cell actin, and
<strong>(ii)</strong> TCF7, an early exhausted t cell marker.</p>
<pre class="r watch-out"><code>Xen_R1_subsetinfo &lt;- subset(Xen_R1, interactive = TRUE)
Xen_R1_subset &lt;- Xen_R1_subsetinfo$subsets[[1]]
vrSpatialPlot(Xen_R1_subset, assay = &quot;Xenium_mol&quot;, group.by = &quot;gene&quot;,
group.id = c(&quot;ACTA2&quot;, &quot;KRT15&quot;, &quot;TACSTD2&quot;, &quot;CEACAM6&quot;), pt.size = 0.2, legend.pt.size = 5)</code></pre>
<p><img width="70%" height="70%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_transcripts_visualize.png" class="center"></p>
<p>We can also visualize count data of cells in the Xenium replicates.
The behaviour of <strong>vrSpatialFeaturePlot</strong> (and most
plotting functions in VoltRon) depend on the number of assays associated
with the assay type (e.g. Xenium is both cell and subcellular type).
Here, we have two assays, and we visualize two features, hence the
resulting plot would include four panels. Prior to spatial
visualization, we can normalize the counts to correct for count depth of
cells by <strong>(i)</strong> dividing counts with total counts in each
cell, <strong>(ii)</strong> multiply with some constant (default:
10000), and followed by <strong>(iii)</strong> log transformation of the
counts.</p>
<pre class="r watch-out"><code>Xen_data &lt;- normalizeData(Xen_data, sizefactor = 1000)
vrSpatialFeaturePlot(Xen_data, features = c(&quot;ACTA2&quot;, &quot;TCF7&quot;), alpha = 1, pt.size = 0.7)</code></pre>
<p><img width="90%" height="90%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_spatialfeature_xenium.png" class="center"></p>
</div>
<div id="processing-and-embedding" class="section level2">
<h2>Processing and Embedding</h2>
<p>Some number of cells in both Xenium replicates might have extremely
low counts. Although cells are detected at these locations, the low
total counts of cells would make it challenging for phenotyping and
clustering these cells. Hence, we remove such cells from the VoltRon
objects.</p>
<pre class="r watch-out"><code>Xen_data &lt;- subset(Xen_data, Count &gt; 5)</code></pre>
<p>VoltRon is capable of reducing dimensionality of datasets using both
PCA and UMAP which we gonna use to build profile-specific neighborhood
graphs and partition the data into cell types.</p>
<pre class="r watch-out"><code>Xen_data &lt;- getPCA(Xen_data, dims = 20)
Xen_data &lt;- getUMAP(Xen_data, dims = 1:20)</code></pre>
<p>We can also visualize the normalized expression of these features on
embedding spaces (e.g. UMAP) using
<strong>vrEmbeddingFeaturePlot</strong> function.</p>
<pre class="r watch-out"><code>vrEmbeddingFeaturePlot(Xen_data, features = c(&quot;LRRC15&quot;, &quot;TCF7&quot;), embedding = &quot;umap&quot;,
pt.size = 0.4)</code></pre>
<p><img width="100%" height="100%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_featureplot_xenium.png" class="center"></p>
<p><br></p>
</div>
<div id="clustering" class="section level2">
<h2>Clustering</h2>
<p>Next, we build neighborhood graphs with the <strong>shared nearest
neighbors (SNN)</strong> of cells which are constructed from
dimensionally reduced gene expression profiles. The function
<strong>getProfileNeighbors</strong> also has an option of building
<strong>k-nearest neighbors (kNN)</strong> graphs.</p>
<pre class="r watch-out"><code>Xen_data &lt;- getProfileNeighbors(Xen_data, dims = 1:20, method = &quot;SNN&quot;)
vrGraphNames(Xen_data)</code></pre>
<pre><code>[1] &quot;SNN&quot;</code></pre>
<p>We can later conduct a clustering of cells using the <strong>leiden’s
method</strong> from the igraph package, which is utilized with the
<strong>getClusters</strong> function.</p>
<pre class="r watch-out"><code>Xen_data &lt;- getClusters(Xen_data, resolution = 1.0, label = &quot;Clusters&quot;, graph = &quot;SNN&quot;)</code></pre>
<p>Now we can label each cell with the associated clustering index and
take a look at the clustering accuracy on the embedding space, and we
can also visualize these clusters on a spatial context.</p>
<pre class="r watch-out"><code>vrEmbeddingPlot(Xen_data, group.by = &quot;Clusters&quot;, embedding = &quot;umap&quot;,
pt.size = 0.4, label = TRUE)</code></pre>
<p><img width="60%" height="60%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_embedplot_xenium.png" class="center"></p>
<pre class="r watch-out"><code>vrSpatialPlot(Xen_data, group.by = &quot;Clusters&quot;, pt.size = 0.18, background.color = &quot;black&quot;)</code></pre>
<p><img width="100%" height="100%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_spatial_xenium.png" class="center"></p>
<p><br></p>
</div>
<div id="annotation" class="section level2">
<h2>Annotation</h2>
<p>We can annotate each of these clusters according to their positive
markers across 313 features. One can use the
<strong>FindAllMarkers</strong> from the <a
href="https://satijalab.org/seurat/">Seurat</a> package to pinpoint
these markers by first utilizing the <strong>as.Seurat</strong> function
first on the Xenium assays of the VoltRon object.</p>
<p>For more information on conversion to other packages, please visit
the <a href="conversion.html">Converting VoltRon Objects</a>.</p>
<p>Let us create a new metadata feature from the
<strong>Clusters</strong> column, called <strong>CellType</strong>, we
can insert this new metadata column directly to the object.</p>
<pre class="r watch-out"><code>clusters &lt;- factor(Xen_data$Clusters, levels = sort(unique(Xen_data$Clusters)))
levels(clusters) &lt;- c(&quot;DCIS_1&quot;,
&quot;DCIS_2&quot;,
&quot;CD4_TCells&quot;,
&quot;Adipocytes&quot;,
&quot;PLD4+_LILRA4+_CD4+_Cells&quot;,
&quot;ACTA2_myoepithelial&quot;,
&quot;IT_2&quot;,
&quot;Macrophages&quot;,
&quot;MastCells&quot;,
&quot;Bcells&quot;,
&quot;StromalCells&quot;,
&quot;CD8_TCells&quot;,
&quot;CD8_TCells&quot;,
&quot;EndothelialCells&quot;,
&quot;StromalCells&quot;,
&quot;MyelomaCells&quot;,
&quot;IT_1&quot;,
&quot;IT_2&quot;,
&quot;ACTA2_myoepithelial&quot;,
&quot;DCIS_2&quot;,
&quot;IT_3&quot;,
&quot;KRT15_myoepithelial&quot;)
Xen_data$CellType &lt;- as.character(clusters)</code></pre>
<p><strong>vrSpatialPlot</strong> function can visualize multiple types
of metadata columns, and users can change the location of the legends as
well.</p>
<pre class="r watch-out"><code>vrSpatialPlot(Xen_data, group.by = &quot;CellType&quot;, pt.size = 0.13, background.color = &quot;black&quot;,
legend.loc = &quot;top&quot;, n.tile = 500)</code></pre>
<p><img width="100%" height="100%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_spatial_xenium_annotated.png" class="center"></p>
<p><br></p>
</div>
</div>
<div id="visium-data-analysis" class="section level1">
<h1>Visium Data Analysis</h1>
<p>Spot-based spatial transcriptomic assays capture spatially-resolved
gene expression profiles that are somewhat closer to single cell
resolution. However, each spot still include a few number of cells that
are likely from a combination of cell types within the tissue of origin.
VoltRon analyzes spot level spatial data sets and even allows selecting
a highly variable subset of features to cluster spots into meaningful
groups of in situ spots for detecting niches of interests</p>
<div id="import-st-data" class="section level2">
<h2>Import ST Data</h2>
<p>For this tutorial we will analyze spot-based transcriptomic assays
from Mouse Brain generated by the <a
href="https://www.10xgenomics.com/products/spatial-gene-expression">Visium</a>
instrument.</p>
<p>You can find and download readouts of all four Visium sections <a
href="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Cellanalysis/Visium/MouseBrainSerialSections.zip">here</a>.
The <strong>Mouse Brain Serial Section 1</strong> datasets can be
downloaded from <a
href="https://www.10xgenomics.com/resources/datasets?menu%5Bproducts.name%5D=Spatial%20Gene%20Expression&amp;query=&amp;page=1&amp;configure%5BhitsPerPage%5D=50&amp;configure%5BmaxValuesPerFacet%5D=1000">here</a>
(specifically, please filter for <strong>Species=Mouse</strong>,
<strong>AnatomicalEntity=brain</strong>, <strong>Chemistry=v1</strong>
and <strong>PipelineVersion=v1.1.0</strong>).</p>
<p>We will now import each of four samples separately and merge them
into one VoltRon object. There are four sections in total given two
serial anterior and serial posterior sections, hence we have <strong>two
tissue blocks each having two layers</strong>.</p>
<pre class="r watch-out"><code>library(VoltRon)
Ant_Sec1 &lt;- importVisium(&quot;Sagittal_Anterior/Section1/&quot;, sample_name = &quot;Anterior1&quot;)
Pos_Sec1 &lt;- importVisium(&quot;Sagittal_Posterior/Section1/&quot;, sample_name = &quot;Posterior1&quot;)
# merge datasets
MBrain_Sec &lt;- merge(Ant_Sec1, Pos_Sec1, samples = c(&quot;Anterior&quot;, &quot;Posterior&quot;))
MBrain_Sec</code></pre>
<pre><code>VoltRon Object
Anterior:
Layers: Section1
Posterior:
Layers: Section1
Assays: Visium(Main) </code></pre>
<p>VoltRon maps metadata features on the spatial images, multiple
features can be provided for all assays/layers associated with the main
assay (Visium).</p>
<pre class="r watch-out"><code>vrSpatialFeaturePlot(MBrain_Sec, features = &quot;Count&quot;, crop = TRUE, alpha = 1, ncol = 2)</code></pre>
<p><img width="80%" height="80%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_visium_firstplot.png" class="center"></p>
<p><br></p>
</div>
<div id="feature-selection" class="section level2">
<h2>Feature Selection</h2>
<p>VoltRon captures the nearly full transcriptome of the Visium data
which then can be filtered from a list of features ranked by their
variance and importance. We use the <strong>variance stabilization
transformation (vst)</strong> on each individual assay using the
<strong>getFeatures</strong> function and combine these ranked list to
capture features important for all assay of the Visium data later with
<strong>getVariableFeatures</strong> function.</p>
<pre class="r watch-out"><code>head(vrFeatures(MBrain_Sec))</code></pre>
<pre><code>[1] &quot;Xkr4&quot; &quot;Gm1992&quot; &quot;Gm19938&quot; &quot;Gm37381&quot; &quot;Rp1&quot; &quot;Sox17&quot; </code></pre>
<pre class="r watch-out"><code>length(vrFeatures(MBrain_Sec))</code></pre>
<pre><code>[1] 33502</code></pre>
<pre class="r watch-out"><code>MBrain_Sec &lt;- normalizeData(MBrain_Sec)
MBrain_Sec &lt;- getFeatures(MBrain_Sec, n = 3000)
head(vrFeatureData(MBrain_Sec))</code></pre>
<pre><code> mean var adj_var rank
Xkr4 0.0248608534 0.0249941807 0.02800216 14114
Gm1992 0.0000000000 0.0000000000 0.00000000 0
Gm19938 0.0285714286 0.0322197476 0.03224908 13889
Gm37381 0.0000000000 0.0000000000 0.00000000 0
Rp1 0.0003710575 0.0003710575 0.00000000 0
Sox17 0.1907235622 0.2219629135 0.23715920 10304</code></pre>
<pre class="r watch-out"><code>selected_features &lt;- getVariableFeatures(MBrain_Sec)
head(selected_features, 20)</code></pre>
<pre><code>[1] &quot;Bc1&quot; &quot;mt-Co1&quot; &quot;mt-Co3&quot; &quot;mt-Atp6&quot; &quot;mt-Co2&quot; &quot;mt-Cytb&quot; &quot;mt-Nd4&quot; &quot;mt-Nd1&quot; &quot;mt-Nd2&quot;
[2] &quot;Fth1&quot; &quot;Hbb-bs&quot; &quot;Cst3&quot; &quot;Gapdh&quot; &quot;Tmsb4x&quot; &quot;Mbp&quot; &quot;Rplp1&quot; &quot;Ttr&quot; &quot;Ppia&quot;
[3] &quot;Ckb&quot; &quot;mt-Nd3&quot; </code></pre>
</div>
<div id="embedding" class="section level2">
<h2>Embedding</h2>
<p>Now we can learn and visualize PCA and UMAP embeddings on this
smaller number of selected features</p>
<pre class="r watch-out"><code>MBrain_Sec &lt;- getPCA(MBrain_Sec, features = selected_features, dims = 30)
MBrain_Sec &lt;- getUMAP(MBrain_Sec, dims = 1:30)
vrEmbeddingPlot(MBrain_Sec, embedding = &quot;umap&quot;)</code></pre>
<p><img width="65%" height="65%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_visium_umap.png" class="center"></p>
<p><br></p>
</div>
<div id="clustering-1" class="section level2">
<h2>Clustering</h2>
<pre class="r watch-out"><code>MBrain_Sec &lt;- getProfileNeighbors(MBrain_Sec, dims = 1:30, k = 10, method = &quot;SNN&quot;)
vrGraphNames(MBrain_Sec)</code></pre>
<pre><code>[1] &quot;SNN&quot;</code></pre>
<pre class="r watch-out"><code>MBrain_Sec &lt;- getClusters(MBrain_Sec, resolution = 0.5, label = &quot;Clusters&quot;, graph = &quot;SNN&quot;)
vrEmbeddingPlot(MBrain_Sec, embedding = &quot;umap&quot;, group.by = &quot;Clusters&quot;)</code></pre>
<p><img width="65%" height="65%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_visium_umap_clusters.png" class="center"></p>
<p><br></p>
<pre class="r watch-out"><code>vrSpatialPlot(MBrain_Sec, group.by = &quot;Clusters&quot;)</code></pre>
<p><img width="65%" height="65%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_visium_spatial_clusters1.png" class="center"></p>
<p><br></p>
</div>
</div>
<div id="melc-data-analysis" class="section level1">
<h1>MELC Data Analysis</h1>
<p>VoltRon also provides support for imaging based proteomics assays. In
this next use case, we analyze cells characterized by
<strong>multi-epitope ligand cartography (MELC)</strong> with a panel of
44 parameters. We use the already segmented cells on which expression of
<strong>43 protein features</strong> (excluding DAPI) were mapped to
these cells.</p>
<p>We use the segmented cells over microscopy images collected from
<strong>control</strong> and <strong>COVID-19</strong> lung tissues of
donors categorized based on disease durations (<strong>control</strong>,
<strong>acute</strong>, <strong>chronic</strong> and
<strong>prolonged</strong>). Each image is associated with one of few
field of views (FOVs) from a single tissue section of a donor. See <a
href="https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE190732">GSE190732</a>
for more information. You can download the <strong>IFdata.csv</strong>
file and the folder with the <strong>DAPI</strong> images <a
href="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Cellanalysis/MELC/GSE190732.zip">here</a>.</p>
<p>We import the <strong>protein intensities</strong>,
<strong>metadata</strong> and <strong>coordinates</strong> associated
with segmented cells across FOVs of samples.</p>
<pre class="r watch-out"><code>library(VoltRon)
IFdata &lt;- read.csv(&quot;IFdata.csv&quot;)
data &lt;- IFdata[,c(2:43)]
metadata &lt;- IFdata[,c(&quot;disease_state&quot;, &quot;object_id&quot;, &quot;cluster&quot;, &quot;Clusters&quot;,
&quot;SourceID&quot;, &quot;Sample&quot;, &quot;FOV&quot;, &quot;Section&quot;)]
coordinates &lt;- as.matrix(IFdata[,c(&quot;posX&quot;,&quot;posY&quot;)], rownames.force = TRUE)</code></pre>
<p><br></p>
<div id="importing-melc-data" class="section level2">
<h2>Importing MELC data</h2>
<p>Before analyzing MELC assays across FOVs, we should <strong>build a
VoltRon object</strong> for each individual FOV/Section by using the
<strong>formVoltron</strong> function. We then merge these sections to
respective tissue blocks by defining their samples of origins. We can
also define <strong>assay names</strong>, <strong>assay types</strong>
and <strong>sample (i.e. block) names</strong> of these objects.</p>
<pre class="r watch-out"><code>library(dplyr)
library(magick)
vr_list &lt;- list()
sample_metadata &lt;- metadata %&gt;% select(Sample, FOV, Section) %&gt;% distinct()
for(i in 1:nrow(sample_metadata)){
vrassay &lt;- sample_metadata[i,]
cells &lt;- rownames(metadata)[metadata$Section == vrassay$Section]
image &lt;- image_read(paste0(&quot;DAPI/&quot;, vrassay$Sample, &quot;/DAPI_&quot;, vrassay$FOV, &quot;.tif&quot;))
vr_list[[vrassay$Section]] &lt;- formVoltRon(data = t(data[cells,]),
metadata = metadata[cells,],
image = image,
coords = coordinates[cells,],
main.assay = &quot;MELC&quot;,
assay.type = &quot;cell&quot;,
sample_name = vrassay$Section)
}</code></pre>
<p>Before moving forward with merging FOVs, we should <strong>flip
coordinates</strong> of cells and perhaps also then
<strong>resize</strong> these images. The main reason for this
coordinate flipping is that the y-axis of most digital images are of the
opposite direction to the commonly used coordinate spaces.</p>
<pre class="r watch-out"><code>for(i in 1:nrow(sample_metadata)){
vrassay &lt;- sample_metadata[i,]
vr_list[[vrassay$Section]] &lt;- flipCoordinates(vr_list[[vrassay$Section]])
vr_list[[vrassay$Section]] &lt;- resizeImage(vr_list[[vrassay$Section]], size = 600)
}</code></pre>
<p>Finally, we merge these assays into one VoltRon object. The
<strong>samples</strong> arguement in the merge function determines
which assays are layers of a single tissue sample/block.</p>
<pre class="r watch-out"><code>vr_merged &lt;- merge(vr_list[[1]], vr_list[-1], samples = sample_metadata$Sample)
vr_merged </code></pre>
<pre><code>VoltRon Object
control_case_3:
Layers: Section1 Section2
control_case_2:
Layers: Section1 Section2
control_case_1:
Layers: Section1 Section2 Section3
acute_case_3:
Layers: Section1 Section2
acute_case_1:
Layers: Section1 Section2
...
There are 13 samples in total
Assays: MELC(Main) </code></pre>
<p><br></p>
<p>The prolonged case 4 has two fields of views (FOVs). By subsetting on
the sample of a prolonged case, we can visualize only these two
sections, and visualize the protein expression of CD31 and
Pancytokeratin which are markers of endothelial and epithelial
cells.</p>
<pre class="r watch-out"><code>vr_subset &lt;- subset(vr_merged, samples = &quot;prolonged_case_4&quot;)
g1 &lt;- vrSpatialFeaturePlot(vr_subset, features = c(&quot;CD31&quot;, &quot;Pancytokeratin&quot;), alpha = 1,
pt.size = 0.7, background.color = &quot;black&quot;)</code></pre>
<p><img width="90%" height="90%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_spatialfeature.png" class="center"></p>
<p><br></p>
</div>
<div id="dimensionality-reduction" class="section level2">
<h2>Dimensionality Reduction</h2>
<p>We can utilize dimensional reduction of the available protein markers
using the getPCA and getUMAP functions, but now with relatively lower
numbers of principal components which are enough to capture the
information across 44 features.</p>
<pre class="r watch-out"><code>vr_merged &lt;- getPCA(vr_merged, dims = 10)
vr_merged &lt;- getUMAP(vr_merged, dims = 1:10)
vrEmbeddingFeaturePlot(vr_merged, features = c(&quot;CD31&quot;, &quot;Pancytokeratin&quot;), embedding = &quot;umap&quot;)</code></pre>
<p><img width="100%" height="100%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_embedding.png" class="center"></p>
<p><br></p>
</div>
<div id="clustering-2" class="section level2">
<h2>Clustering</h2>
<p>Now we can visualize the clusters across these sections and perhaps
also check for clusters that may reside in only specific disease
conditions.</p>
<pre class="r watch-out"><code># SNN graph and clusters
vr_merged &lt;- getProfileNeighbors(vr_merged, dims = 1:10, k = 10, method = &quot;SNN&quot;)
vrGraphNames(vr_merged)</code></pre>
<pre><code>[1] &quot;SNN&quot;</code></pre>
<pre class="r watch-out"><code>vr_merged &lt;- getClusters(vr_merged, resolution = 0.8, label = &quot;MELC_Clusters&quot;, graph = &quot;SNN&quot;)
# install patchwork package
if (!requireNamespace(&quot;patchwork&quot;, quietly = TRUE))
install.packages(&quot;patchwork&quot;)
library(patchwork)
# visualize conditions and clusters
vr_merged$Condition &lt;- gsub(&quot;_[0-9]$&quot;, &quot;&quot;, vr_merged$Sample)
g1 &lt;- vrEmbeddingPlot(vr_merged, group.by = c(&quot;Condition&quot;), embedding = &quot;umap&quot;)
g2 &lt;- vrEmbeddingPlot(vr_merged, group.by = c(&quot;MELC_Clusters&quot;), embedding = &quot;umap&quot;,
label = TRUE)
g1 | g2</code></pre>
<p><img width="100%" height="100%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_embeddingclusters.png" class="center"></p>
<p><br></p>
</div>
<div id="visualization-of-markers" class="section level2">
<h2>Visualization of Markers</h2>
<p>VoltRon provides both violin plots (<strong>vrViolinPlot</strong>)
and heatmaps (<strong>vrHeatmapPlot</strong>) to further investigate the
enrichment of markers across newly clustered datasets.
<strong>Note:</strong> the vrHeatmapPlot function would require you to
have the <strong>ComplexHeatmap</strong> package in your namespace.</p>
<pre class="r watch-out"><code># install patchwork package
if (!requireNamespace(&quot;ComplexHeatmap&quot;, quietly = TRUE))
BiocManager::install(&quot;ComplexHeatmap&quot;)
library(ComplexHeatmap)
# Visualize Markers
vrHeatmapPlot(vr_merged, features = vrFeatures(vr_merged),
group.by = &quot;MELC_Clusters&quot;, show_row_names = TRUE)</code></pre>
<p><img width="80%" height="80%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_heatmapclusters.png" class="center"></p>
<p><br></p>
<pre class="r watch-out"><code>vrViolinPlot(vr_merged, features = c(&quot;CD3&quot;, &quot;SMA&quot;, &quot;Pancytokeratin&quot;, &quot;CCR2&quot;),
group.by = &quot;MELC_Clusters&quot;, ncol = 2)</code></pre>
<p><img width="80%" height="80%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_violinclusters.png" class="center"></p>
<p><br></p>
</div>
<div id="neighborhood-analysis" class="section level2">
<h2>Neighborhood Analysis</h2>
<p>We use the <strong>vrNeighbourhoodEnrichment</strong> function to
detect cell type pairs that co occur within each others’ neighborhoods.
First, we establish <strong>spatial neighborhood graphs</strong> that
determine the neighbors of each cell on tissue sections.</p>
<p><a
href="https://en.wikipedia.org/wiki/Delaunay_triangulation">Delaunay
tesselations</a> or graphs are commonly used to determine neighbors of
spatial entities. The function <strong>getSpatialNeighbors</strong>
builds a delaunay graph of all assays of a certain type and detects
neighbors of cells in a VoltRon object.</p>
<pre class="r watch-out"><code>vr_merged &lt;- getSpatialNeighbors(vr_merged, method = &quot;delaunay&quot;)</code></pre>
<p>The graph <strong>delaunay</strong>, which we will use for
spatially-aware neightborhood analysis, is now the second graph
available in the VoltRon object along with <strong>SNN</strong>.</p>
<pre class="r watch-out"><code>vrGraphNames(vr_merged)</code></pre>
<pre><code>[1] &quot;SNN&quot; &quot;delaunay&quot;</code></pre>
<p>Once neighbors are founds, we can apply a <strong>permutation
test</strong> that compares the number of cell type occurances with an
expected number of these occurances under multiple permutations of
labels in the tissue (fixed coordinates but cells are randomly
labelled). A similar approach is used to by several spatial analysis
frameworks and packages (<a
href="https://www.nature.com/articles/nmeth.4391">Schapiro et. al
2017</a>, <a
href="https://www.nature.com/articles/s41592-021-01358-2">Palla et. al
2022</a>).</p>
<p>Here, we will use the original cell type labels annotated by <a
href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9922044/">Mothes et.
al 2023</a>.</p>
<pre class="r watch-out"><code>neighborhood_results &lt;- vrNeighbourhoodEnrichment(vr_merged, group.by = &quot;Clusters&quot;)</code></pre>
<p>The neighborhood analysis provides the results of:</p>
<ul>
<li>the <strong>association</strong> tests (whether cell types are
within each other’s neighborhood)</li>
<li>the <strong>segregation</strong> tests (whether cell types are
clustered separately)</li>
</ul>
<p>between all cell type pairs across each layers and assay.</p>
<p>The number of each cell in a pair in each section is reported to
assess the impact of the results of the test (i.e. low number of
abundance in one cell type may indicate low impact).</p>
<pre class="r watch-out"><code>head(neighborhood_results)</code></pre>
<div>
<pre><code style="font-size: 10px;"> from_value to_value p_assoc p_segreg p_assoc_adj p_segreg_adj n_from n_to AssayID Assay Layer Sample
Assay1.1 CD163+ macs CD163+ macs 0.0000000 1.00000000 0.0000 1.00000000 41 41 Assay1 MELC Section1 control_case_3
Assay1.2 CD163+ macs CD4+ T cells 0.9380000 0.03300000 0.9980 0.09762866 41 48 Assay1 MELC Section1 control_case_3
Assay1.3 CD163+ macs CD8+ Tcells 0.8779011 0.04339051 0.9980 0.09762866 41 11 Assay1 MELC Section1 control_case_3
Assay1.4 CD163+ macs NK cells 0.8190000 0.08700000 0.9980 0.15660000 41 15 Assay1 MELC Section1 control_case_3
Assay1.5 CD163+ macs endothelia 0.1230000 0.85100000 0.5535 0.95737500 41 139 Assay1 MELC Section1 control_case_3
Assay1.6 CD163+ macs epithelia 0.9320000 0.03600000 0.9980 0.09762866 41 39 Assay1 MELC Section1 control_case_3</code></pre>
</div>
<p><br></p>
<pre class="r watch-out"><code>vrNeighbourhoodEnrichmentPlot(neighborhood_results, assay = &quot;Assay1&quot;, type = &quot;assoc&quot;)</code></pre>
<p><img width="70%" height="70%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_neighenrichment.png" class="center"></p>
</div>
</div>
</div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.odd').parent('tbody').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
$(document).ready(function () {
$('.tabset-dropdown > .nav-tabs > li').click(function () {
$(this).parent().toggleClass('nav-tabs-open');
});
});
</script>
<!-- code folding -->
<script>
$(document).ready(function () {
// temporarily add toc-ignore selector to headers for the consistency with Pandoc
$('.unlisted.unnumbered').addClass('toc-ignore')
// move toc-ignore selectors from section div to header
$('div.section.toc-ignore')
.removeClass('toc-ignore')
.children('h1,h2,h3,h4,h5').addClass('toc-ignore');
// establish options
var options = {
selectors: "h1,h2,h3",
theme: "bootstrap3",
context: '.toc-content',
hashGenerator: function (text) {
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_');
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
};
options.showAndHide = false;
options.smoothScroll = false;
// tocify
var toc = $("#TOC").tocify(options).data("toc-tocify");
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>