You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lessons/13_machine_learning.qmd
+46-14Lines changed: 46 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -50,10 +50,32 @@ When doing XYZ...
50
50
51
51
## Cortical layer dataset
52
52
53
-
As an example of a real-world application of machine learning, we will be using a dataset that comes from spatial locations associated with different cortical layers in the human brain. These layers are broken into 6 cortical layers (L1, L2, L3, L4, L5, L6) and 2 white matter layers (WM1 and WM2). Each of these layers has a unique spatial location in the cortex and a unique gene expression profile.
53
+
::: columns
54
54
55
-
Here, we have created an example dataset that is based on the [paper](https://www.biorxiv.org/content/10.64898/2026.01.12.698703v1.full), which used spatial transcriptomics (Visium HD) to profile expression in cortical layers in the human brain across different age groups.
55
+
::: {.column width="25%"}
56
+
As an example of a real-world application of machine learning, we will be using a dataset that comes from spatial locations associated with different cortical layers in the human brain. These layers are broken into 6 cortical layers (L1, L2, L3, L4, L5, L6) and a white matter layer. Each of these layers has a unique spatial location.
57
+
:::
58
+
59
+
::: column
60
+
::: {#fig-cortical_layers_paper .figure}
61
+
{height=50}
62
+
63
+
Spatial locations of the cortical layers in the human brain. <br>
64
+
_Image source: [Rai et al. (2026)](https://www.biorxiv.org/content/10.64898/2026.01.12.698703v1.full)_
65
+
:::
66
+
:::
67
+
:::
56
68
69
+
Based upon [this dataset](https://www.biorxiv.org/content/10.64898/2026.01.12.698703v1.full), we have generated a synthetic dataset that contains the x and y coordinates of cells in the cortex with cortical layer labels. Additionally, we have included the log-normalized expression values of known marker genes for each cortical layer.
70
+
71
+
::: {#fig-cortical_marker_genes .figure}
72
+
{width=550}
73
+
74
+
Example of the spatial expression of known marker genes for each cortical layer. <br>
75
+
_Image source: [Rai et al. (2026)](https://www.biorxiv.org/content/10.64898/2026.01.12.698703v1.full)_
76
+
:::
77
+
78
+
**We will be using this synthetic dataset to train a random forest classifier to predict the cortical layer labels based on the spatial location and gene expression of each cell.**
57
79
58
80
The dataset contains spatial coordinates of cells in the cortex, as well as the cortical layer that each cell belongs to.
59
81
@@ -105,20 +127,30 @@ In the dataframe, you have have noted that we also have columns: `AQP4`, `HPCAL1
105
127
```{python}
106
128
#| label: fig-cortical_marker_genes
107
129
#| fig-cap: Spatial plot of the gene expression of known marker genes for each cortical layer.
108
-
# Marker genes for each cortical layer
109
-
genes = ["AQP4", "HPCAL1", "FREM3",
130
+
# List of marker genes to plot
131
+
genes = ["AQP4", "HPCAL1", "FREM3",
110
132
"TRABD2A", "KRT17", "MOBP"]
111
133
112
-
# Plot the expression of each marker gene across the cortex
113
-
for gene in genes:
114
-
plt.figure(figsize=(6, 4))
115
-
sns.scatterplot(data=df_cortical,
116
-
x="x", y="y",
117
-
hue=gene,
118
-
palette="viridis",
119
-
edgecolor=None)
120
-
plt.title(f"Expression of {gene} across the cortex")
121
-
plt.show()
134
+
# Initialize a plot with rows and columns for each gene
135
+
fig, axes = plt.subplots(2, 3, figsize=(15, 8))
136
+
137
+
# Make axes a flat list so we can index easily
138
+
axes = axes.flatten()
139
+
140
+
for i, gene in enumerate(genes):
141
+
ax = axes[i]
142
+
sns.scatterplot(
143
+
data=df_cortical,
144
+
x="x", y="y",
145
+
hue=gene,
146
+
palette="viridis",
147
+
edgecolor=None,
148
+
ax=ax
149
+
)
150
+
ax.set_title(f"Expression of {gene} across the cortex")
0 commit comments