<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<title>Importing Spatial Data</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">Importing Spatial Data</h1>
</div>
<style>
.title{
display: none;
}
body {
text-align: justify
}
.center {
display: block;
margin-left: auto;
margin-right: auto;
}
table, th, td {
border-collapse: collapse;
align-self: center;
padding-right: 10px;
padding-left: 10px;
}
</style>
<style type="text/css">
.watch-out {
color: black;
}
</style>
<p><br></p>
<div id="working-with-voltron-objects" class="section level1">
<h1>Working with VoltRon objects</h1>
<p>In this tutorial, we will cover some of the fundemantel built-in
functions of VoltRon to manage data, images and spatial information of
assays. Here is the list of example datasets included in the
Package.</p>
<pre class="r watch-out"><code>data("visium_data")
data("melc_data")
data("xenium_data")
data("merged_object")</code></pre>
<p><br></p>
<div id="samplemetadata" class="section level2">
<h2>Sample Metadata</h2>
<p>The sample metadata is a summarized data frame which provides
informations on assays, layers and sample (tissue blocks) included in
the VoltRon object. You can use the <strong>SampleMetadata</strong>
function to call this table. The row names are the unique assay IDs,
following assay types (e.g. Visium), layer name and Sample (typicall
tissue block with multiple layers and assays).</p>
<pre class="r watch-out"><code>SampleMetadata(visium_data)</code></pre>
<pre><code>## Assay Layer Sample
## Assay1 Visium Section1 Anterior1</code></pre>
<p><br></p>
</div>
<div id="metadata" class="section level2">
<h2>Metadata</h2>
<p>The <strong>Metadata</strong> function calls the metadata table of
the main assay type (see <a href="#assays">vrMainAssay</a>).</p>
<pre class="r watch-out"><code>Metadata(visium_data)</code></pre>
<pre><code>## id Count assay_id Assay Layer Sample
## AAAGGCTCTCGCGCCG-1_Assay1 AAAGGCTCTCGCGCCG-1_Assay1 39690 Assay1 Visium Section1 Anterior1
## AAATGGCCCGTGCCCT-1_Assay1 AAATGGCCCGTGCCCT-1_Assay1 33516 Assay1 Visium Section1 Anterior1
## AAATTACACGACTCTG-1_Assay1 AAATTACACGACTCTG-1_Assay1 12250 Assay1 Visium Section1 Anterior1
## AAGACATACGTGGTTT-1_Assay1 AAGACATACGTGGTTT-1_Assay1 31821 Assay1 Visium Section1 Anterior1
## ACCTACTATAAATCTA-1_Assay1 ACCTACTATAAATCTA-1_Assay1 41387 Assay1 Visium Section1 Anterior1
## ACGCGGGCCAAGGACA-1_Assay1 ACGCGGGCCAAGGACA-1_Assay1 48003 Assay1 Visium Section1 Anterior1</code></pre>
<p>You can also specify the assay ID or the assay type to call metadata
of a subset of spatial points.</p>
<pre class="r watch-out"><code>Metadata(visium_data, assay = "Visium")
Metadata(visium_data, assay = "Assay1")</code></pre>
<p>The <strong>type</strong> argument returns all spatial points of a
given spatial point type (ROI, spot, cell, molecule or tile).</p>
<pre class="r watch-out"><code>Metadata(visium_data, type = "spot")</code></pre>
<p>If the type argument is specified as <strong>all</strong>. Then this
would return the VoltRon Metadata Object (vrMetadata)</p>
<pre class="r watch-out"><code>Metadata(visium_data, type = "all")</code></pre>
<pre><code>## VoltRon Metadata Object
## This object includes:
## 100 spots</code></pre>
<p><br></p>
</div>
<div id="spatialpoints" class="section level2">
<h2>Spatial Points</h2>
<p>In a VoltRon object, spatial points are spatially defined entities
with coordinates, segments which are of any of five assay types (ROI,
spot, cell, molecule and tile).</p>
<p>The <strong>vrSpatialPoints</strong> function return the IDs of these
entities for further downstream operations, such as subsetting etc.</p>
<pre class="r watch-out"><code>vrSpatialPoints(visium_data)</code></pre>
<pre><code>## [1] "AAAGGCTCTCGCGCCG-1_Assay1" "AAATGGCCCGTGCCCT-1_Assay1" "AAATTACACGACTCTG-1_Assay1"</code></pre>
<p>You can also specify the assay ID or the assay type to call metadata
of a subset of spatial points.</p>
<pre class="r watch-out"><code>vrSpatialPoints(visium_data, assay = "Visium")
vrSpatialPoints(visium_data, assay = "Assay1")</code></pre>
<pre><code>## [1] "AAAGGCTCTCGCGCCG-1_Assay1" "AAATGGCCCGTGCCCT-1_Assay1" "AAATTACACGACTCTG-1_Assay1"</code></pre>
<p><br></p>
</div>
<div id="assays" class="section level2">
<h2>Assays</h2>
<p>The default (or main) assay of the VoltRon object is typically shown
when printed (next to the assay name says “main” in paranthesis)</p>
<pre class="r watch-out"><code>melc_data</code></pre>
<pre><code>## VoltRon Object
## control_case_3:
## Layers: Section1
## Assays: MELC(Main)
## Features: main(Main)</code></pre>
<p>You can also call/get the name of the default (or main) using the
<strong>vrMainAssay</strong> function</p>
<pre class="r watch-out"><code>vrMainAssay(melc_data)</code></pre>
<pre><code>## [1] "MELC"</code></pre>
<p>You can also set the main assay yourself, but only the assay types
given in the <strong>Assay</strong> column of
<strong>SampleMetadata(object)</strong>.</p>
<pre class="r watch-out"><code>SampleMetadata(melc_data)</code></pre>
<pre><code>## Assay Layer Sample
## Assay1 MELC Section1 control_case_3</code></pre>
<pre class="r watch-out"><code>vrMainAssay(melc_data) <- "MELC"</code></pre>
<p>You can also get the assay IDs associated with the main assay using
<strong>vrAssayNames</strong> function.</p>
<pre class="r watch-out"><code>vrAssayNames(melc_data)</code></pre>
<pre><code>## [1] "Assay1"</code></pre>
<p>The assay type can be provided with the <strong>assay</strong>
arguement to get type specific assay IDs</p>
<pre class="r watch-out"><code>vrAssayNames(melc_data, assay = "MELC")</code></pre>
<pre><code>## [1] "Assay1"</code></pre>
<p><br></p>
</div>
<div id="coordinates-and-segments" class="section level2">
<h2>Coordinates and Segments</h2>
<p>The <strong>vrCoordinates</strong> function is used to call the
centroids of spots, cells and all other spatial points types with
VoltRon objects.</p>
<pre class="r watch-out"><code>vrCoordinates(visium_data)</code></pre>
<pre><code>## x y z
## CCTTGACCACTTTATT-1_Assay1 463.78658 183.1497 0
## ATTTGTCTTGGGAGCT-1_Assay1 374.97419 275.8864 0
## TCACGCATTGTAGATC-1_Assay1 250.58520 319.1566 0
## CCGAGCTGTGCTTGTC-1_Assay1 474.47505 411.9449 0
## GCATGGGTACTGACGC-1_Assay1 87.10844 269.6902 0
## AGTCGGCCCAAACGAC-1_Assay1 215.00861 368.6231 0</code></pre>
<p>You can also specify the assay ID or the assay type to call
coordinates of a subset of spatial points.</p>
<pre class="r watch-out"><code>vrCoordinates(visium_data, assay = "Visium")
vrCoordinates(visium_data, assay = "Assay1")</code></pre>
<p><br></p>
<p>Each assay a VoltRon object may incorporate indefinite number of
coordinate systems. One can look for these coordinate systems using the
<strong>vrMainSpatial</strong> function, and select one of systems to
call coordinates (see <a href="#image">vrMainSpatial</a>)</p>
<pre class="r watch-out"><code>vrCoordinates(visium_data, spatial_name = "main")</code></pre>
<p>The <strong>reg</strong> option in the <strong>vrCoordinates</strong>
function looks for a registered version of the main coordinate system
and returns its coordinates (if there is any).</p>
<pre class="r watch-out"><code>vrCoordinates(visium_data, spatial_name = "main", reg = TRUE)</code></pre>
<pre><code>## Warning in .local(object, ...): There are no registered spatial systems with name main!</code></pre>
<pre><code>## x y z
## CCTTGACCACTTTATT-1_Assay1 463.78658 183.1497 0
## ATTTGTCTTGGGAGCT-1_Assay1 374.97419 275.8864 0
## TCACGCATTGTAGATC-1_Assay1 250.58520 319.1566 0
## CCGAGCTGTGCTTGTC-1_Assay1 474.47505 411.9449 0
## GCATGGGTACTGACGC-1_Assay1 87.10844 269.6902 0
## AGTCGGCCCAAACGAC-1_Assay1 215.00861 368.6231 0</code></pre>
<p><br></p>
<p>The arguements of the <strong>vrSegments</strong> functions are
idential to vrCoordinates and return a list of polygon corners
associated with the coordinate system of the coordinates.</p>
<pre class="r watch-out"><code>vrSegments(xenium_data)
vrSegments(xenium_data, assay = "Xenium")
vrSegments(xenium_data, assay = "Assay1")
vrSegments(xenium_data, spatial_name = "main")
vrSegments(xenium_data, spatial_name = "main", reg = TRUE)</code></pre>
<pre><code>## $`171_Assay1`
## id x y
## 1 171 105.25 145.50
## 2 171 101.75 144.25
## 3 171 101.50 143.25
## 4 171 109.75 135.25
## 5 171 112.00 127.00
## 6 171 115.50 123.50
## 7 171 120.00 123.50
## 8 171 124.25 132.50
## 9 171 121.00 136.00
## 10 171 120.25 140.00
## 11 171 111.25 143.50
## 12 171 105.50 145.25
## 13 171 105.25 145.50
##
## $`180_Assay1`
## id x y
## 14 180 148.25 153.25
## 15 180 145.75 151.50
## 16 180 143.25 147.50
## 17 180 143.25 146.25
## 18 180 143.00 144.50
## 19 180 142.50 140.50
## 20 180 144.25 140.50
## 21 180 146.25 140.75
## 22 180 148.50 141.00
## 23 180 151.00 144.75
## 24 180 150.50 150.00
## 25 180 148.75 153.25
## 26 180 148.25 153.25</code></pre>
<p><br></p>
</div>
<div id="image" class="section level2">
<h2>Images and Coordinate Systems</h2>
<p>Below we review some of the essential built-in functions to
manipulate and manage images of a VoltRon object as well as the
coordinate systems that are associated with these images.</p>
<p><br></p>
<div id="spatial-coordinate-systems" class="section level3">
<h3>Spatial Coordinate Systems</h3>
<p>In a VoltRon object, each image has a unique ID which is also
associated with a coordinate (or spatial) system. The names of these
spatial systems can be called using the <strong>vrSpatialNames</strong>
function.</p>
<pre class="r watch-out"><code>vrSpatialNames(visium_data)</code></pre>
<pre><code>## [1] "main"</code></pre>
<p>You can also specify the assay ID or the assay type to call image
names of a subset assays or any assay type (see <a
href="#samplemetadata">Sample Metadata</a>)</p>
<pre class="r watch-out"><code>vrSpatialNames(visium_data, assay = "Visium")
vrSpatialNames(visium_data, assay = "Assay1")</code></pre>
<pre><code>## [1] "main"</code></pre>
<p><br></p>
<p>If you wanna see the list of all spatial systems associated with all
assays of the main assay type, you can call the
<strong>vrMainSpatial</strong> function.</p>
<pre class="r watch-out"><code>vrMainSpatial(visium_data)</code></pre>
<pre><code>## Assay Spatial
## 1 Assay1 main</code></pre>
<p>You can also specify the assay ID or the assay type to call spatial
system names of a subset assays or any assay type (see <a
href="#samplemetadata">Sample Metadata</a>)</p>
<pre class="r watch-out"><code>vrMainSpatial(visium_data, assay = "Visium")
vrMainSpatial(visium_data, assay = "Assay1")</code></pre>
<pre><code>## Assay Spatial
## 1 Assay1 main</code></pre>
<p><br></p>
</div>
<div id="channel-names" class="section level3">
<h3>Channel Names</h3>
<p>Each spatial system object (vrSpatial) in VoltRon object can also
include a indefinite number of channels which you can get (or request) a
list of for further use.</p>
<pre class="r watch-out"><code>vrImageChannelNames(melc_data)
vrImageChannelNames(melc_data, assay = "MELC")
vrImageChannelNames(melc_data, assay = "Assay1")</code></pre>
<pre><code>## Assay Layer Sample Spatial Channels
## Assay1 MELC Section1 control_case_3 MELC DAPI,CD45</code></pre>
<p><br></p>
</div>
<div id="get-and-set-images" class="section level3">
<h3>Get and Set Images</h3>
<p>In VoltRon, images can be called specifically, or return as a list.
The return image is of a magick image object (see <a
href="https://cran.r-project.org/web/packages/magick/vignettes/intro.html">magick</a>
package)</p>
<pre class="r watch-out"><code>vrImages(visium_data)
vrImages(visium_data, assay = "Visium")
vrImages(visium_data, assay = "Assay1")</code></pre>
<p><img src="voltronobjects_files/figure-html/unnamed-chunk-36-1.png" width="60%" style="display: block; margin: auto;" /></p>
<!-- <img width="50%" height="50%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/voltronobjects_HE.png" class="center"> -->
<p><br></p>
<p>Once you know the name of a specific channel, you can the image of a
specific channel by providing the name and the associated channel.</p>
<pre class="r watch-out"><code>vrImages(melc_data, name = "MELC", channel = "DAPI")</code></pre>
<p><img src="voltronobjects_files/figure-html/unnamed-chunk-38-1.png" width="60%" style="display: block; margin: auto;" /></p>
<!-- <img width="50%" height="50%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/importdata_DAPI.png" class="center"> -->
<p><br></p>
<p>You can set up the main channel as well as the main spatial system
name for later use.</p>
<pre class="r watch-out"><code>vrMainSpatial(melc_data, assay = "Assay1") <- c("MELC", "CD45")
vrImages(melc_data)</code></pre>
<p><img src="voltronobjects_files/figure-html/unnamed-chunk-40-1.png" width="60%" style="display: block; margin: auto;" /></p>
<!-- <img width="50%" height="50%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/importdata_CD45.png" class="center"> -->
<p><br></p>
<p>You can also resize the images as they are being returned. This is
usually used for visualization purposes and helps speeding up
visualization for large images. This is accomplished with
<strong>scale.perc</strong> arguement.</p>
<pre class="r watch-out"><code>vrImages(melc_data, scale.perc = 25)</code></pre>
<p><br></p>
</div>
<div id="combining-image-channels" class="section level3">
<h3>Combining Image Channels</h3>
<p>VoltRon even allows manipulation of channel images if you also
provide an associate list of colors.</p>
<pre class="r watch-out"><code>melc_data <- combineChannels(melc_data,
channels = c("DAPI", "CD45"), colors = c("grey", "green"),
channel_key = "combined")</code></pre>
<p>These new images can be stored as new channels within the same image
object, and called later again</p>
<pre class="r watch-out"><code>vrImageChannelNames(melc_data)</code></pre>
<pre><code>## Assay Layer Sample Spatial Channels
## Assay1 MELC Section1 control_case_3 MELC DAPI,CD45,combined</code></pre>
<pre class="r watch-out"><code>vrImages(melc_data, channel = "combined")</code></pre>
<p><img src="voltronobjects_files/figure-html/unnamed-chunk-45-1.png" width="60%" style="display: block; margin: auto;" /></p>
<p><br></p>
</div>
</div>
<div id="feature-matrix-data" class="section level2">
<h2>Feature Matrix (Data)</h2>
<pre class="r watch-out"><code>vrData(visium_data)[3:8,3:5]</code></pre>
<pre><code>## AAATTACACGACTCTG-1_Assay1 AAGACATACGTGGTTT-1_Assay1 ACCTACTATAAATCTA-1_Assay1
## Gm19938 0 0 0
## Gm37381 0 0 0
## Rp1 0 0 0
## Sox17 0 1 1
## Gm37587 0 0 0
## Gm37323 0 0 0</code></pre>
<pre class="r watch-out"><code>vrData(visium_data, norm = TRUE)[3:8,3:5]</code></pre>
<pre><code>## AAATTACACGACTCTG-1_Assay1 AAGACATACGTGGTTT-1_Assay1 ACCTACTATAAATCTA-1_Assay1
## Gm19938 0 0.0000000 0.0000000
## Gm37381 0 0.0000000 0.0000000
## Rp1 0 0.0000000 0.0000000
## Sox17 0 0.2732722 0.2164184
## Gm37587 0 0.0000000 0.0000000
## Gm37323 0 0.0000000 0.0000000</code></pre>
<p><br></p>
</div>
<div id="embedding" class="section level2">
<h2>Embeddings</h2>
<p>You can parse and even set individual embedding elements in a VoltRon
object.</p>
<pre class="r watch-out"><code>vrEmbeddingNames(xenium_data)</code></pre>
<pre><code>## [1] "pca" "umap"</code></pre>
<p>You can use these names of get the associated embedding dataset from
the object.</p>
<pre class="r watch-out"><code>vrEmbeddings(xenium_data, type = "umap")</code></pre>
<pre><code>## x y
## 171_Assay1 -7.110343 0.451607
## 180_Assay1 5.333756 3.896294
## 182_Assay1 3.805085 4.581084
## 185_Assay1 5.330851 3.870111
## 197_Assay1 -4.397479 2.763229
## 206_Assay1 -1.753468 3.973698</code></pre>
<p>You can also set and create new embedding elements in the voltron
object. In this case, you have to make sure that the row names should
match with the targeted spatial points.</p>
<pre class="r watch-out"><code>new_umap_data <- vrEmbeddings(xenium_data, type = "umap")
vrEmbeddings(xenium_data, type = "new_umap") <- new_umap_data*2</code></pre>
<p>Now we can observe changes to the new embedding data.</p>
<pre class="r watch-out"><code>vrEmbeddings(xenium_data, type = "new_umap")</code></pre>
<pre><code>## x y
## 171_Assay1 -14.220687 0.903214
## 180_Assay1 10.667511 7.792587
## 182_Assay1 7.610170 9.162168
## 185_Assay1 10.661703 7.740223
## 197_Assay1 -8.794958 5.526458
## 206_Assay1 -3.506937 7.947396</code></pre>
<p>You can choose individual assay names or assay classes.</p>
<pre class="r watch-out"><code>vrEmbeddings(xenium_data, type = "umap", assay = "Xenium")
vrEmbeddings(xenium_data, type = "pca", assay = "Assay1")</code></pre>
<p><br></p>
</div>
<div id="subsetting-voltron-objects" class="section level2">
<h2>Subsetting VoltRon objects</h2>
<p><br></p>
<div id="sampleassay" class="section level3">
<h3>sample/assay</h3>
<p>VoltRon object can be subsetted in a variety of ways using assay
names, sample names, spatial point names, features (e.g. gene), image
coordinates (crop boxes or bounding boxes) as well as interactively.</p>
<pre class="r watch-out"><code>visium_data_subset <- subset(visium_data, assays = "Assay1")</code></pre>
<pre class="r watch-out"><code>visium_data_subset <- subset(visium_data, samples = "Anterior1")
visium_data_subset</code></pre>
<pre><code>## VoltRon Object
## Anterior1:
## Layers: Section1
## Assays: Visium(Main)
## Features: RNA(Main)</code></pre>
<p><br></p>
</div>
<div id="spatial-points" class="section level3">
<h3>spatial points</h3>
<p>You can use a list of spatial points (typically using
<strong>vrSpatialPoints</strong> function, see <a
href="#spatialpoints">vrSpatialPoints</a>)</p>
<pre class="r watch-out"><code>selected_points <- vrSpatialPoints(visium_data)
selected_points[1:20]</code></pre>
<pre><code>## [1] "AAAGGCTCTCGCGCCG-1_Assay1" "AAATGGCCCGTGCCCT-1_Assay1" "AAATTACACGACTCTG-1_Assay1"</code></pre>
<pre class="r watch-out"><code>visium_data_subset <- subset(visium_data, spatialpoints = selected_points[1:20])
visium_data_subset</code></pre>
<pre><code>## VoltRon Object
## Anterior1:
## Layers: Section1
## Assays: Visium(Main)
## Features: RNA(Main)</code></pre>
<p><br></p>
</div>
<div id="features" class="section level3">
<h3>features</h3>
<p>You can select a few number of features and subset the features given
this list. However, it would only subset the main assay (see <a
href="#assays">vrMainAssay</a>)</p>
<pre class="r watch-out"><code>selected_features <- vrFeatures(visium_data)
selected_features[1:20]</code></pre>
<pre><code>## [1] "Xkr4" "Gm1992" "Gm19938" "Gm37381" "Rp1" "Sox17" "Gm37587" "Gm37323" "Mrpl15" "Lypla1"
## [11] "Tcea1" "Rgs20" "Gm16041" "Atp6v1h" "Oprk1" "Npbwr1" "Rb1cc1" "4732440D04Rik" "Alkal1" "St18"</code></pre>
<pre class="r watch-out"><code>visium_data_subset <- subset(visium_data, features = selected_features[1:20])
vrFeatures(visium_data_subset)</code></pre>
<pre><code>## [1] "Xkr4" "Gm1992" "Gm19938" "Gm37381" "Rp1" "Sox17" "Gm37587" "Gm37323" "Mrpl15" "Lypla1"
## [11] "Tcea1" "Rgs20" "Gm16041" "Atp6v1h" "Oprk1" "Npbwr1" "Rb1cc1" "4732440D04Rik" "Alkal1" "St18"</code></pre>
<p><br></p>
</div>
<div id="interactive-subsetting" class="section level3">
<h3>Interactive subsetting</h3>
<p>VoltRon allows interactively subsetting spatial data. Using the
arguement <strong>interactive = TRUE</strong>, a mini Shiny app is
triggered where users can select a bounding box to crop the spatial
data.</p>
<pre class="r watch-out"><code>visium_data_subset_info <- subset(visium_data, interactive = TRUE)
visium_data_subset <- visium_data_subset_info$subsets[[1]]</code></pre>
<pre><code>VoltRon Object
Anterior1_subset:
Layers: Section1
Assays: Visium(Main) </code></pre>
<pre class="r watch-out"><code>vrImages(visium_data_subset)</code></pre>
<p><br></p>
</div>
</div>
<div id="visualization" class="section level2">
<h2>Visualization</h2>
<p>VoltRon provides visualization utilities for both spatial and
embedding level visualizations.</p>
<p><br></p>
<div id="spatial-plots" class="section level3">
<h3>Spatial Plots</h3>
<p><strong>vrSpatialPlot</strong> is the main function for visualize
labels and identities of cells. This information is parsed from the
Metadata of the main assay (see <a href="#assays">vrMainAssay</a>). The
users can also specify the assay.</p>
<pre class="r watch-out"><code>vrSpatialPlot(xenium_data, group.by = "clusters")</code></pre>
<p><img width="50%" height="50%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/voltronobjects_sp.png" class="center"></p>
<p><br></p>
<p>You can also visualize the segments of spatial points and even get
the segments transparent</p>
<pre class="r watch-out"><code>vrSpatialPlot(xenium_data, group.by = "clusters", plot.segments = TRUE, alpha = 0.6)</code></pre>
<p><img width="50%" height="50%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/voltronobjects_spsegment.png" class="center"></p>
<p><br></p>
<p>The background color can be set to any color.</p>
<pre class="r watch-out"><code>vrSpatialPlot(xenium_data, group.by = "clusters", plot.segments = TRUE,
background.color = "white")</code></pre>
<p><img width="50%" height="50%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/voltronobjects_spback.png" class="center"></p>
<p><br></p>
<p>In cases where there are multiple coordinate systems, you can get the
background set to the name of the image (or coordinate system). You can
get the name of these images from <a
href="#image">vrSpatialNames</a>.</p>
<p>If also want to select a channel from the same coordinate system, you
can set background arguement as a vector of 2 where first is the name of
the image (coordinate system) and the other would be channel name. You
can get the name of these channels from <a
href="#image">vrImageChannelNames</a>.</p>
<pre class="r watch-out"><code>vrSpatialPlot(xenium_data, group.by = "clusters", plot.segments = TRUE,
spatial = "main")
vrSpatialPlot(xenium_data, group.by = "clusters", plot.segments = TRUE,
spatial = "main", channel = "DAPI")</code></pre>
<p><br></p>
<p>If the visualized assay is of a type “spot”, you can crop the image
to encapsulate the smallest subset that include all spots.</p>
<pre class="r watch-out"><code>vrSpatialPlot(visium_data, group.by = "Sample", crop = TRUE)</code></pre>
<p><img width="50%" height="50%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/voltronobjects_spcrop.png" class="center"></p>
<p><br></p>
<p>The <strong>vrSpatialFeaturePlot</strong> functions the same way as
vrSpatialPlot but requires extra arguements such as
<strong>features</strong> for selecting features, <strong>norm</strong>
for normalized expression (default), and <strong>log</strong> for log
transformed counts.</p>
<pre class="r watch-out"><code>vrSpatialFeaturePlot(visium_data, features = "Count")
vrSpatialFeaturePlot(visium_data, features = "Stat1", norm = TRUE)</code></pre>
<p><img width="100%" height="100%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/voltronobjects_spfeature.png" class="center"></p>
<p><br></p>
<p>For all variations of <strong>vrSpatialPlot</strong> and
<strong>vrSpatialFeaturePlot</strong> functions above, you can specifiy
the assay names or assay class.</p>
<pre class="r watch-out"><code>vrSpatialPlot(visium_data, assay = "Visium", plot.segments = TRUE)
vrSpatialPlot(visium_data, assay = "Assay1", plot.segments = TRUE)
vrSpatialFeaturePlot(visium_data, assay = "Visium", features = "Count")
vrSpatialFeaturePlot(visium_data, assay = "Assay1", features = "Count")</code></pre>
<p><br></p>
</div>
<div id="spatial-plots-multi-layer" class="section level3">
<h3>Spatial Plots (Multi-Layer)</h3>
<p><strong>vrSpatialPlot</strong> function can be paired with the
<strong>addSpatialLayer</strong> function to add additional assays of
the same spatial coordinate system as the original assay. We use the
piping operator “|>” to connect to functions which overlays the
results of the first image with the second.
<strong>addSpatialLayer</strong> will check if two assays are within the
same tissue block and coordinate system, and will overlay these assays
if thats the case.</p>
<p>This utility can be used to visualize molecules along with cell
segments. Here we can also color each individual molecule (gene)
type.</p>
<pre class="r watch-out"><code>library(ggnewscale)</code></pre>
<pre class="r watch-out"><code>vrSpatialPlot(merged_object, plot.segments = TRUE, group.by = "clusters") |>
addSpatialLayer(merged_object, assay = "Assay2", group.by = "gene", alpha = 1,
colors = list(KRT15 = "blue", KRT14 = "green"))</code></pre>
<pre><code>## Warning: Duplicated `override.aes` is ignored.</code></pre>
<p><img src="voltronobjects_files/figure-html/unnamed-chunk-73-1.png" width="60%" style="display: block; margin: auto;" /></p>
<p><br></p>
<p>You can also visualize the segments that represents annotations of
the tissue sections along with the cells.</p>
<pre class="r watch-out"><code>vrSpatialPlot(merged_object, plot.segments = FALSE, group.by = "clusters") |>
addSpatialLayer(merged_object, assay = "Assay3", group.by = "Region", alpha = 0.3,
color = list(Region1 = "blue", Region2 = "yellow"))</code></pre>
<pre><code>## Warning: Duplicated `override.aes` is ignored.</code></pre>
<p><img src="voltronobjects_files/figure-html/unnamed-chunk-74-1.png" width="60%" style="display: block; margin: auto;" /></p>
<p><br></p>
</div>
<div id="embedding-plots" class="section level3">
<h3>Embedding Plots</h3>
<p>Dimensional reduction and embedding features are also possible for
the VoltRon objects.</p>
<pre class="r watch-out"><code>vrEmbeddingPlot(xenium_data, embedding = "umap", group.by = "clusters", label = T)</code></pre>
<p><img width="50%" height="50%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/voltronobjects_embed.png" class="center"></p>
<p><br></p>
<p>The <strong>vrEmbeddingFeaturePlot</strong> functions the same way as
vrEmbeddingPlot but requires extra arguements such as
<strong>features</strong> for selecting features, <strong>norm</strong>
for normalized expression (default), and <strong>log</strong> for log
transformed counts.</p>
<pre class="r watch-out"><code>vrEmbeddingFeaturePlot(xenium_data, embedding = "umap", features = "Count")
vrEmbeddingFeaturePlot(xenium_data, embedding = "umap", features = "KRT5", norm = FALSE)</code></pre>
<p><img width="100%" height="100%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/voltronobjects_embedfeature.png" class="center"></p>
<p><br></p>
<p>For all variations of <strong>vrEmbeddingPlot</strong> and
<strong>vrEmbeddingFeaturePlot</strong> functions above, you can
specifiy the assay names or assay class.</p>
<pre class="r watch-out"><code>vrEmbeddingPlot(xenium_data, assay = "Xenium", embedding = "umap")
vrEmbeddingPlot(xenium_data, assay = "Assay1", embedding = "umap")
vrEmbeddingFeaturePlot(xenium_data, assay = "Xenium", embedding = "umap", features = "Count")
vrEmbeddingFeaturePlot(xenium_data, assay = "Assay1", embedding = "umap", features = "Count")</code></pre>
</div>
</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,h4",
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>