-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
724 lines (646 loc) · 39.8 KB
/
index.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
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
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="generator" content="Hugo 0.114.1">
<title>StereoSeq Data Workflow</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Font Awesome for icons -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css"
integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
<!-- Custom Styles -->
<link rel="stylesheet" href="/css/sidebarStyle.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
<style>
.btn {
margin-top: 10px;
}
.content-section {
margin-left: 0;
padding-left: 0;
}
.nav {
list-style-type: none;
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-white">
<div class="container">
<a class="navbar-brand" href="#">StereoSeq Data Workflow</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a class="nav-link" href="#">Home</a></li>
</ul>
</div>
</div>
</nav>
<div class="container mt-4">
<div class="row">
<!-- Sidebar -->
<div class="col-md-3">
<div class="sticky-top" style="top: 20px;">
<h4>Preparation</h4>
<ul class="nav flex-column" style="list-style-type: none; padding: 0; margin: 0;">
<li class="nav-item"><a href="#preparation" class="nav-link">Preparation</a></li>
</ul>
<h4>Seurat Basic Workflow</h4>
<ul class="nav flex-column" style="list-style-type: none; padding: 0; margin: 0;">
<li class="nav-item"><a href="#Seurat loadData" class="nav-link">Load Data</a></li>
<li class="nav-item"><a href="#Seurat preprocessing" class="nav-link">Processing</a></li>
<li class="nav-item"><a href="#Seurat normalization" class="nav-link">Normalization</a></li>
<li class="nav-item"><a href="#Seurat dimensions reduction" class="nav-link">Dimensions reduction</a></li>
<li class="nav-item"><a href="#Seurat clustering" class="nav-link">Clustering</a></li>
<li class="nav-item"><a href="#Seurat find marker genes" class="nav-link">Find marker genes</a></li>
<li class="nav-item"><a href="#Seurat integration of scRNA-seq data" class="nav-link">Integration of scRNA-seq data</a></li>
<li class="nav-item"><a href="#Seurat cell type annotation" class="nav-link">Cell type annotation</a></li>
</ul>
<h4>Giotto basic Workflow</h4>
<ul class="nav flex-column" style="list-style-type: none; padding: 0; margin: 0;">
<li class="nav-item"><a href="#Giotto create giotto object" class="nav-link">Create Giotto object</a></li>
<li class="nav-item"><a href="#Giotto normalization and HVG" class="nav-link">Normalization and HVG</a></li>
<li class="nav-item"><a href="#Giotto dimension reduction" class="nav-link">Dimension reduction</a></li>
<li class="nav-item"><a href="#Giotto clustering" class="nav-link">Clustering</a></li>
<li class="nav-item"><a href="#Giotto find marker genes" class="nav-link">Find marker genes</a></li>
<li class="nav-item"><a href="#Giotto integration of scRNA-seq data" class="nav-link">Integration of scRNA-seq data</a></li>
</ul>
<h4>Advanced Analysis</h4>
<ul class="nav flex-column" style="list-style-type: none; padding: 0; margin: 0;">
<li class="nav-item"><a href="#Expression enhancement" class="nav-link">Expression
enhancement</a></li>
<li class="nav-item"><a href="#Spatial domain detection" class="nav-link">Spatial domain
detection</a></li>
<li class="nav-item"><a href="#Cell segmentation" class="nav-link">Cell segmentation</a></li>
<li class="nav-item"><a href="#Cell cell communications" class="nav-link">Cell cell
communications</a></li>
</ul>
</div>
</div>
<!-- Main Content -->
<div class="col-md-9 content-section">
<h1 class="mb-4">StereoSeq Data Workflow</h1>
<h2 class="mb-4" style="font-size: 20px">Created by Stomics US Data Team</h2>
<p>This is a StereoSeq data analysis workflow. This demonstration will use a data set <a
href="http://116.6.21.110:8090/share/21bb9df9-e6c5-47c5-9aa8-29f2d23a6df4" target="_blank"
rel="noopener noreferrer">SS200000135TL_D1</a> of a mouse brain.</p>
<div style="text-align: center;">
<img src="images/SS200000135TL_D1_stereoMap.png" alt="SS200000135TL_D1"style="width:800px; height:auto;">
</div>
<!-- Preparation Section -->
<h2 id="preparation" class="mt-5">Preparation</h2>
<h3>Environment Setup</h3>
<p>Ensure that the following dependencies are installed:</p>
<!-- Code block toggle button -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse" data-target="#envCode"
aria-expanded="false" aria-controls="envCode">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="envCode">
<pre><code class="language-bash">
# Install necessary packages
conda create -n stereoSeq_env python=3.8
conda activate stereoSeq_env
pip install numpy pandas scanpy
</code></pre>
</div>
<!-- loadData Section -->
<h2 id="Seurat loadData" class="mt-5">Load data</h2>
<p>Load data in R from rds file</p>
<!-- Code block toggle button -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse"
data-target="#loadRcode" aria-expanded="false" aria-controls="loadRcode">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="loadRcode">
<pre><code class="language-r">
library(Seurat)
data_path="./SS200000135TL_D1.adjusted.cellbin.rds"
st_data=readRDS(data_path)
</code></pre>
</div>
<!-- Preprocessing Section -->
<h2 id="Seurat preprocessing" class="mt-5">Processing</h2>
<h3>Filtering low quality spots</h3>
<p>
In spatial transcriptomics data, filtering low-quality spots is essential to ensure reliable
downstream analyses, and using robust metrics like the Median Absolute Deviation (MAD) helps
identify outliers effectively.
The MAD method provides a robust statistic of variability, minimizing the influence of extreme
values that may arise from technical noise or damaged tissue regions.
When applying MAD-based filtering, spots with extreme counts or features that deviate significantly
from the median by a set threshold, such as 3-5 MADs, are flagged and considered for removal.
This approach helps eliminate spots with anomalously low gene counts or excessive count depth that
may result from issues like broken membranes or sequencing errors.
</p>
<p>
Furthermore, filtering by the fraction of mitochondrial reads is crucial because spots with a high
proportion of mitochondrial counts often indicate compromised cell integrity. These compromised
spots may have lost most cytoplasmic RNA, leaving only mitochondrial transcripts, which can skew the
data.
However, it is important to apply this filter carefully, as certain cell types or tissue regions
might naturally have higher mitochondrial content due to biological functions related to
respiration.
</p>
<p>
By considering MAD-based thresholds for count depth and filtering based on mitochondrial read
fractions, researchers can strike a balance between removing poor-quality data and retaining
meaningful biological variation.
This approach ensures that only genuinely low-quality spots are filtered out, preserving spatial and
functional tissue heterogeneity.
Ultimately, these filtering steps improve the accuracy and interpretability of spatial
transcriptomics analysis by focusing on reliable, biologically relevant data.
</p>
<!-- Code block toggle button -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse"
data-target="#preparationCode" aria-expanded="false" aria-controls="preparationCode">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="preparationCode">
<pre><code class="language-r">
st_data=readRDS(data_path)
preProcessing = function(rds_data){
median_nCount <- median(metadata$nCount_Spatial, na.rm=TRUE)
abs_dev_nCount <- abs(metadata$nCount_Spatial - median_nCount)
mad_nCount <- median(abs_dev_nCount, na.rm = TRUE)
median_nFeature <- median(metadata$nFeature_Spatial, na.rm = TRUE)
abs_dev_nFeature <- abs(metadata$nFeature_Spatial - median_nFeature)
mad_nFeature <- median(abs_dev_nFeature, na.rm = TRUE)
lower_nCount <- median_nCount - 3 * mad_nCount
upper_nCount <- median_nCount + 3 * mad_nCount
lower_nFeature <- median_nFeature - 3 * mad_nFeature
upper_nFeature <- median_nFeature + 3 * mad_nFeature
rds_data.filter <- subset(rds_data, subset = nCount_Spatial > lower_nCount &
nCount_Spatial < upper_nCount &
nFeature_Spatial > lower_nFeature &
nFeature_Spatial < upper_nFeature &
percent.mito < 10)
return (rds_data.filter)
}
st_data.filter=preProcessing(st_data)
</code></pre>
</div>
<img src="images/SS200000135TL_D1.adjusted.cellbin.filter_plot.png" alt="Seurat filtering result"
style="width:600px; height:auto;">
<!-- Normalization Section -->
<h2 id="Seurat normalization" class="mt-5">Normalization</h2>
<p>
Normalization in spatial transcriptomics data is essential to account for technical variability and
ensure that differences in gene expression across spatial locations reflect true biological
variation rather than artifacts.
</p>
<h3>scTransform</h3>
<p>
scTransform Built upon a generalized linear model (GLM) framework, scTransform models gene
expression counts while considering factors such as sequencing depth and technical biases.
</p>
<!-- Code block toggle button -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse"
data-target="#scTransformCode" aria-expanded="false" aria-controls="scTransformCode">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="scTransformCode">
<pre><code class="language-r">
st_data.norm <- SCTransform(st_data.filter,assay="RNA" , vars.to.regress="percent.mito" , return.only.var.genes=FALSE)
</code></pre>
</div>
<img src="images/SS200000135TL_D1.adjusted.cellbin.SCT.png" alt="Description of image"
style="width:600px; height:auto;">
<h3>LogNormalize</h3>
<p>
LogNormalize is a widely used normalization technique.This method typically involves scaling each
cell's total gene expression to a fixed value (such as 10,000), followed by a log-transformation to
reduce the impact of outliers and high-expression genes.
</p>
<!-- Code block toggle button -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse"
data-target="#LogNormalizeCode" aria-expanded="false" aria-controls="LogNormalizeCode">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="LogNormalizeCode">
<pre><code class="language-r">
st_data <- NormalizeData(st_data.filter,assay='RNA' ,normalization.method="LogNormalize" )
</code></pre>
</div>
<img src="images/SS200000135TL_D1.adjusted.cellbin.logNormalizaPlot.png" alt="Description of image"
style="width:600px; height:auto;">
<!-- Dimensions reduction Section -->
<h2 id="Seurat dimensions reduction" class="mt-5">Dimensions reduction</h2>
<p>
The spatial transcriptomics datasets often contain tens of thousands of genes across tens of
thousands of spots or cells.
Demension reduction simplifies high-dimensional data into a lower-dimensional representation while
retaining the most important biological variation.
This aids in visualization, clustering, and downstream analyses.
</p>
<p>
Common techniques for dimension reduction:
</p>
<h4>Principal Component Analysis (PCA)</h4>
<p>
Projects high-dimensional gene expression data into a set of orthogonal components.
Captures the largest variance in the dataset using fewer dimensions (principal components).
</p>
<!-- Code block toggle button -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse"
data-target="#SeuratPCACode" aria-expanded="false" aria-controls="SeuratPCACode">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="SeuratPCACode">
<pre><code class="language-r">
st_data <- FindVariableFeatures(object = st_data)
st_data <- ScaleData(object = st_data)
st_data <- RunPCA(object = st_data)
</code></pre>
</div>
<h4>Uniform Manifold Approximation and Projection (UMAP)</h4>
<p>
Non-linear technique preserving global and local structures in the data.
Better suited for preserving clusters in noisy datasets compared to PCA.
</p>
<!-- Code block toggle button -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse"
data-target="#SeuratUMAPCode" aria-expanded="false" aria-controls="SeuratUMAPCode">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="SeuratUMAPCode">
<pre><code class="language-r">
st_data <- FindNeighbors(object = st_data, dims = 1:30)
st_data <- RunUMAP(object = st_data, dims = 1:30)
</code></pre>
</div>
<!-- Clustering Section -->
<h2 id="Seurat clustering" class="mt-5">Clustering</h2>
<p>
Clustering is a technique used to identify groups of cells with similar gene expression profiles,
providing insights into the cellular composition and spatial organization of tissues.
</p>
<p>
Common algorithm for clustering in seurat:
</p>
<p><b>Original Louvain Algorithm (algorithm = 1)</b></p>
<p>Basic version of the Louvain clustering algorithm. It is fast and efficient for small to medium-sized
datasets.
But May not capture fine-grained clusters as well as advanced methods.</p>
<p><b>Tips:</b> For quick, general-purpose clustering, especially with smaller datasets.</p>
<img src="images/seurat/louvain.png" alt="Description of image" style="width:600px; height:auto;">
<!-- Code block toggle button -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse" data-target="#SeuratLouvainCode" aria-expanded="false" aria-controls="SeuratLouvainCode">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="SeuratLouvainCode">
<pre><code class="language-r">
st_data.norm <- FindClusters(st_data.norm,algorithm=1,cluster.name="louvain",verbose = TRUE)
</code></pre>
</div>
<p><b>Louvain with Multilevel Refinement (algorithm = 2)</b></p>
<p>An enhanced version of Louvain with additional refinement steps to improve modularity.
It has better clustering quality than the original Louvain. It is slightly slower than the basic
Louvain algorithm.</p>
<p><b>Tips:</b> If you have a moderately sized dataset and need improved clustering accuracy.</p>
<img src="images/seurat/louvain2.png" alt="Description of image" style="width:600px; height:auto;">
<!-- Code block toggle button -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse" data-target="#SeuratLouvain2Code" aria-expanded="false" aria-controls="SeuratLouvain2Code">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="SeuratLouvain2Code">
<pre><code class="language-r">
st_data.norm <- FindClusters(st_data.norm,algorithm=2,cluster.name="louvain2",verbose = TRUE)
</code></pre>
</div>
<p><b>Leiden Algorithm (algorithm = 4)</b></p>
<p>An advanced clustering method that improves upon Louvain by addressing its limitations,
such as the resolution limit and random initialization dependency.
It produces more consistent and meaningful clusters.Better at detecting small, fine-grained
clusters.</p>
<p><b>Tips:</b> Recommended for most single-cell or spatial transcriptomics datasets due to its improved
clustering accuracy and stability.
<b>If you have a large dataset, eg.cell number > 40k, R may run into issues due to memory and long
vectors. To solve this, in seurat,
use the method = "igraph" instead of the default method="matrix"</b>
</p>
<img src="images/seurat/leiden.png" alt="Description of image" style="width:600px; height:auto;">
<!-- Code block toggle button -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse" data-target="#SeuratLeidenCode" aria-expanded="false" aria-controls="SeuratLeidenCode">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="SeuratLeidenCode">
<pre><code class="language-r">
st_data.norm <- FindClusters(st_data.norm,algorithm=4,method = "igraph",cluster.name="leiden",resolution=1, verbose = TRUE)
</code></pre>
</div>
<!-- Find Marker Genes Section -->
<h2 id="Seurat find marker genes" class="mt-5">Find Marker Genes</h2>
<p>
After clustering cells, finding marker genes is a crucial step for identifying unique gene
expression profiles that define each cluster.
Marker genes are typically those that are highly expressed within a specific cluster compared to
others, providing insights into cell types.
To find marker genes, statistical methods like differential expression analysis are applied to
compare gene expression across clusters, identifying genes with significantly higher expression in
each group.These marker genes can then be used to annotate clusters, link them to known cell types, and explore
spatial patterns of gene activity within the tissue architecture.
</p>
<!-- Code block toggle button -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse" data-target="#MarkerGeneCode" aria-expanded="false" aria-controls="MarkerGeneCode">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="MarkerGeneCode">
<pre><code class="language-r">
de_markers <- FindAllMarkers(st_data.norm,group.by="leiden",only.pos=TRUE,logfc.threshold=0.25,min.pct = 0.1)
</code></pre>
</div>
<img src="images/seurat/heatmap.png" alt="Description of image" style="width:600px; height:auto;">
<!-- Integration of scRNA-seq data section -->
<h2 id="Seurat integration of scRNA-seq data" class="mt-5">Integration of scRNA-seq data</h2>
<p>
By leveraging Seurat's integration workflow, scRNA-seq datasets can be aligned with spatial data, allowing the identification of spatially resolved cell types or states.
This process typically involves identifying shared features, such as gene expression patterns, to anchor scRNA-seq data to the spatial domain.
The combined analysis provides a comprehensive view of gene expression in the spatial tissue architecture, facilitating insights into tissue organization and cellular interactions.
</p>
<!-- Code block toggle button -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse" data-target="#SeuratIntegrationRCode" aria-expanded="false" aria-controls="SeuratIntegrationRCode">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="SeuratIntegrationRCode">
<pre><code class="language-r">
SingleCellData=readRDS("Mouse_brain_ref.anndata075.SCT.rds")
markers=read.csv(paste0(data_path,"mouse.brainMarker.csv"),header = FALSE)
markers=unique(markers$V2)
anchors = FindTransferAnchors(reference=SingleCellData, query = st_data.norm2,normalization.method = "SCT", features = markers)
predictions.assay <- TransferData(anchorset = anchors, refdata = SingleCellData$ClusterName, prediction.assay=TRUE, weight.reduction=st_data.norm2[["pca"]], dims=1:30)
non.mapping <- c()
for(i in 1:dim(predictions.assay)[1]){ if(sum(predictions.assay@data[i,])==0) non.mapping <- c(non.mapping, rownames(predictions.assay)[i])}
predictions.assay@misc$non.mapping <- non.mapping
predictions.assay@misc$mapping <- setdiff(levels(as.factor(SingleCellData$ClusterName )), non.mapping)
st_data.norm2[["predictions"]] <- predictions.assay
levels(as.factor(SingleCellData$ClusterName))
</code></pre>
</div>
<img src="images/seurat/seurat_integration.png" alt="Description of image" style="width:600px; height:auto;">
<!-- Cell Type Annotation -->
<h2 id="Seurat cell type annotation" class="mt-5">Cell Type Annotation</h2>
<p>
After clustered the spatial transcritpmics data and found the markers, we can use singleR to
annotation cell types.
This involves leveraging single-cell reference datasets to identify cell types in spatially resolved data.
singR uses correlation-based methods and/or supervised machine learning approaches to map spatial
spots to cell types in the reference dataset.
This process enables researchers to infer spatially resolved cellular compositions, revealing tissue
architecture and functional organization at single-cell resolution.
</p>
<!-- Code block toggle button -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse" data-target="#SeuratSingleRCode" aria-expanded="false" aria-controls="SeuratSingleRCode">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="SeuratSingleRCode">
<pre><code class="language-r">
annotations <- SingleR(test=st_sce, ref=scRNA_sce, labels=scRNA_sce$ClusterName)
st_data.norm2$singleR.labels <- annotations$labels[match(rownames([email protected]), rownames(annotations))]
</code></pre>
</div>
<img src="images/seurat/SingleR.annotation.png" alt="Description of image" style="width:600px; height:auto;">
<!-- Giotto Section -->
<h2 id="Giotto" class="mt-5">Giotto</h2>
<!-- Create giotto object Section -->
<h2 id="Giotto create giotto object" class="mt-5">Create Giotto Object</h2>
<p>
Giotto allows users to initialize a spatial transcriptomics dataset, setting up a structure that
includes expression data, spatial coordinates, and metadata for downstream analysis.
To create a Giotto object, we have to provide at least one matrix where genes are the row names and cells are the column names.
To add spatial information for cells or spots, we need to provide a matrix, data.table, or data.frame containing coordinates (CellID, X, Y).
</p>
<p>
We can get the expression matrix and coordinates directly from a seurat object
</p>
<p>
Addtionally, we can use <i>createGiottoInstructions</i> function in the Giotto to set global parameters for Giotto functions,
including specifying the Python path, plot display options, and plot saving preferences.
</p>
<!-- Code block toggle on -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse" data-target="#CreateGiottoobject" aria-expanded="false" aria-controls="CreateGiottoobject">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="CreateGiottoobject">
<pre><code class="language-r">
library(Matrix)
library(Giotto)
instructions = createGiottoInstructions(python_path = '/home/r-miniconda/envs/giotto_env/bin/python',
save_plot = TRUE,
save_dir = './')
out_path = "./"
prefix="SS200000135TL_D1.adjusted.cellbin"
st_data=readRDS("SS200000135TL_D1.adjusted.cellbin.filtered.rds")
meta_data = [email protected]
coordinates = data.frame(
ID = rownames(meta_data),
X = meta_data$x,
Y = meta_data$y
)
expression_matrix = st_data@assays$Spatial@counts
metadata = data.frame(
CellID = rownames(meta_data),
nCount = meta_data$nCount_Spatial,
nFeature = meta_data$nCount_Spatial,
mito=meta_data$percent.mito,
x=meta_data$x,
y=meta_data$y)
giotto_object=createGiottoObject(raw_exprs = expression_matrix, spatial_locs = coordinates,cell_metadata=metadata,instructions = instructions)
</code></pre>
</div>
<!-- Giotto normalization and HVG Section -->
<h2 id="Giotto normalization and HVG" class="mt-5">Normalization and HVG</h2>
<p>Giotto provides two normalization methods.</p>
<p>
<b>1.Standard</b>:Normalization for total library size and scaling;Log transformation of data;Z-scoring of data by genes and/or cells.</p>
<b>2.osmFISH</b>:Each gene divide the total gene count and multiply by the total number of genes.
Each cell divide the normalized gene counts by the total counts per cell and multiply by the total number of cells.</p>
<p>Here we use standard normalization<p>
<p>After normalization, we can calculate the highly variable genes. In Giotto, we use the default method, high COV within groups. In this method,
Genes are binned into groups based on average expression and the COV for each gene is converted into a z-score.
Genes with a z-score higher than the threshold are considered highly variable.</p>
<!-- Code block toggle on -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse" data-target="#GiottoNorm" aria-expanded="false" aria-controls="GiottoNorm">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="GiottoNorm">
<pre><code class="language-r">
giotto_object.norm=normalizeGiotto(gobject = giotto_object,verbose = T,norm_methods="standard")
giotto_obj=calculateHVG(giotto_object.norm)
</code></pre>
</div>
<img src="images/Giotto/HVGplot.png" alt="Description of image" style="width:600px; height:auto;">
<!-- Giotto dimension Reduction -->
<h2 id="Giotto dimension reduction" class="mt-5">Dimension Reduction</h2>
<p>Giotto provides three dimension reduction methods: PCA, UMAP and tSNE</p>
<!-- Code block toggle on -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse" data-target="#GiottoDimensionReduction" aria-expanded="false" aria-controls="GiottoDimensionReduction">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="GiottoDimensionReduction">
<pre><code class="language-r">
giotto_object=runPCA(gobject =giotto_object )
giotto_object=runUMAP(gobject = giotto_object)
</code></pre>
</div>
<!-- Giotto clustering Section -->
<h2 id="Giotto clustering" class="mt-5">Clustering</h2>
<p>First we create a shared nearest neighbor (sNN) network using the normalized expression values,
focusing on the first 30 dimensions with 50 neighbors per cell.
Apply Leiden and Louvain clustering on the sNN network, assigning cluster labels to Leiden_clus and Louvain_clus, respectively.
</p>
<p><b>Tips</b>:Choose the parameter k depends on the dataset's complexity and size:
For small datasets eg. less than 10,000 cells: Use smaller k (e.g., 10–30) to focus on local neighborhoods.
For large datasets : Use larger k (e.g., 30–100) to better capture global patterns.
Test different k values and visualize the results to ensure meaningful clustering.
</p>
<!-- Code block toggle on -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse" data-target="#Giottoclustering" aria-expanded="false" aria-controls="Giottoclustering">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="Giottoclustering">
<pre><code class="language-r">
giotto_object=createNearestNetwork(gobject = giotto_object,expression_values = "normalized",
type = "sNN",dimensions_to_use = 1:30,k=50)
giotto_object=doLeidenCluster(giotto_object,name="leiden_clus",nn_network_to_use = "sNN")
giotto_object=doLouvainCluster(giotto_object,name="Louvain_clus",version = c("community", "multinet"),nn_network_to_use = "sNN")
</code></pre>
</div>
<img src="images/Giotto/Clusters.png" alt="Clustering" style="width:600px; height:auto;">
<p>We can evaluate the gene expression correlation between clusters. </p>
<!-- Code block toggle on -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse" data-target="#GiottoHeatmap" aria-expanded="false" aria-controls="GiottoHeatmap">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="GiottoHeatmap">
<pre><code class="language-r">
hvg_genes <- giotto_object@gene_metadata[giotto_object@gene_metadata$hvg == "yes", ]$gene_ID
showClusterHeatmap(giotto_object,cluster_column = "leiden_clus",expression_values = "normalized",genes = hvg_genes)
</code></pre>
</div>
<img src="images/Giotto/Leiden_heatmap.png" alt="Clustering" style="width:600px; height:auto;">
<!-- Giotto find marker gene Section -->
<h2 id="Giotto find marker genes" class="mt-5">Find marker genes</h2>
<p>Giotto provides three different methods to detect cluster specific marker genes: scran, gini and mast. scran is generally recommended in spatial transcriptomics data.
</p>
<!-- Code block toggle on -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse" data-target="#GiottoFindMarkerGene" aria-expanded="false" aria-controls="GiottoFindMarkerGene">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="GiottoFindMarkerGene">
<pre><code class="language-r">
scran_markers =findScranMarkers_one_vs_all(giotto_object,expression_values = "normalized",cluster_column ="leiden_clus",pval = 0.01,logFC = 0.5,method = "scran",verbose=TRUE)
</code></pre>
</div>
<!-- Giotto Integration section -->
<h2 id="Giotto integration of scRNA-seq data" class="mt-5">Integration of scRNA-seq data</h2>
<!-- Code block toggle on -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse" data-target="#GiottoFIntegrationCode" aria-expanded="false" aria-controls="GiottoFIntegrationCode">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="GiottoFIntegrationCode">
<pre><code class="language-r">
SingleCellData=readRDS("Reference/Mouse_brain_ref.anndata075.rds")
sc_sign_matrix = makeSignMatrixRank(
as.matrix(SingleCellData@assays$RNA@data),
SingleCellData$ClusterName,
ties_method = "random",
gobject = giotto_obj
)
giotto_obj <- runSpatialEnrich(
giotto_obj,
enrich_method = c("rank"),
sign_matrix = sc_sign_matrix,
expression_values = c("normalized"),
)
</code></pre>
</div>
<!-- Expression Enhancement -->
<h2 id="Expression Enhancement" class="mt-5">Expression Enhancement</h2>
<h3>BayesSpace</h3>
<!-- Code block toggle button -->
<button class="btn btn btn-info float-right" type="button" data-toggle="collapse"
data-target="#BayesSpace" aria-expanded="false" aria-controls="BayesSpace">
Show/Hide Code
</button>
<!-- Collapsible code block -->
<div class="collapse" id="BayesSpace">
<pre><code class="language-r">
data=readRDS("SS200000135TL_D1.tissue.gef_bin20.seurat.rds")
st=as.SingleCellExperiment(data)
colData(st)$col=colData(st)$x/200
colData(st)$row=colData(st)$y/200
colData(st)$imagecol=colData(st)$x
colData(st)$imagerow=colData(st)$y
st <- spatialPreprocess(st, platform="ST" ,
n.PCs=7, n.HVGs=2000, log.normalize=FALSE)
st.tune <- qTune(st, qs=seq(2, 20), platform="ST", d=7)
qPlot(st.tune)
st.tune <- spatialCluster(st.tune, q=17, platform="ST", d=7,
init.method="mclust", model="t",
gamma=2,
nrep=1000, burn.in=100,
save.chain=TRUE)
st.enhanced <- spatialEnhance(st.tune, q=17, platform="ST", d=7,
model="t", gamma=2,
jitter_prior=0.3, jitter_scale=3.5,
nrep=1000, burn.in=100,
save.chain=TRUE)
markers=c("Ntng1")
st.enhanced <- enhanceFeatures(st.enhanced, st,
feature_names=markers,
nrounds=0)
featurePlot(st, "Ntng1")
featurePlot(st.enhanced, "Ntng1")
</code></pre>
</div>
<img src="images/Image_20241029120419.png" alt="Description of image" style="width:600px; height:auto;">
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
<!-- Highlight.js initialization -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
</body>
</html>