@@ -45,10 +45,6 @@ fnm <- unzip(zip, exdir=dir)
4545(sd <- readSpatialData(dirname(fnm[1])))
4646```
4747
48- ``` {r}
49-
50- ```
51-
5248### analysis
5349
5450We'll start out in Python and load the data into a ` spatialdata ` object:
@@ -59,6 +55,61 @@ We'll start out in Python and load the data into a `spatialdata` object:
5955
6056### quality control
6157
58+ ### exploratory
59+
60+ #### histopathology
61+
62+ Let's start out by visualization the histopathology image,
63+ i.e., the hematoxylin and eosin (H\& E) staining:
64+
65+ ``` {r plt-hne}
66+ cl <- rep(list(c(0, 1/3)), 3) # contrast
67+ plotSpatialData() + plotImage(sd, cl=cl)
68+ ```
69+
70+ We can also zoom into a particular region by specifying a bounding box and
71+ using ` crop() ` to subset the data accordingly; to do this more efficiently,
72+ we subset the object to contain only images before cropping:
73+
74+ ``` {r plt-hne-box}
75+ bb <- list(xmin=2000, xmax=4000, ymin=2000, ymax=3000)
76+ sp <- crop(sd["images", ], bb)
77+ plotSpatialData() + plotImage(sp, cl=cl)
78+ ```
79+
80+ #### immunofluorescence
81+
82+ In addition to the H\& E, the dataset also includes four immunofluorescence (IF)
83+ images capturing DAPI (nuclei), E-Cadhering (epithelia), 18S (cytoplasm), and
84+ Vimentin (stromal); the underlying image is thus a 3D array where the first
85+ dimension are channels, the second and third dimensions are height and width.
86+
87+ ``` {r chs}
88+ img <- image(sd, 2)
89+ cat(channels(img))
90+ cat(dim(img))
91+ ```
92+
93+ For consistent visualization, we'll first specify colors to use for each channel:
94+
95+ ``` {r}
96+ pal <- c("blue", "green", "cyan", "magenta")
97+ chs <- names(pal) <- channels(img)
98+ ```
99+
100+ Let's first visualize each channel separately (using the previously defined region):
101+
102+ ``` {r}
103+ ps <- lapply(chs, \(.) plotSpatialData() + plotImage(sp, 2, ch=., c=pal[.]) + ggtitle(.))
104+ wrap_plots(ps, nrow=2) & theme_void() & theme(plot.title=element_text(hjust=0.5), legend.position="none")
105+ ```
106+
107+ Alternatively, we can visualize a four-plex composite image (using the full tissue):
108+
109+ ``` {r}
110+ plotSpatialData() + plotImage(sd, 2, ch=chs, c=pal[chs])
111+ ```
112+
62113### processing
63114
64115The ` SpatialData ` object contains a single ` table ` element, represented as a
@@ -80,21 +131,15 @@ available in R/Bioc, e.g., `r BiocStyle::Biocpkg("scrapper")`:
80131# - community detection using Leiden algorithm
81132assayNames(se) <- "counts"
82133se <- normalizeRnaCounts.se(se)
83- se <- chooseRnaHvgs.se(se, top=2e3)
134+ se <- se[, se$sizeFactor > 0]
135+ se <- chooseRnaHvgs.se(se)
84136se <- runPca.se(se, features=rowData(se)$hvg)
85137se <- clusterGraph.se(se, method="leiden", resolution=0.5)
138+ table(sd) <- se
86139```
87140
88141### downstream
89142
90- Let's start out by visualization the histopathology image,
91- i.e., the hematoxylin and eosin (H\& E) staining:
92-
93- ``` {r plt-hne}
94- cl <- rep(list(c(0, 1/3)), 3) # contrast
95- plotSpatialData() + plotImage(sd, cl=cl)
96- ```
97-
98143### appendix
99144
100145::: {.callout-note icon=false, collapse=true}
0 commit comments