Skip to content

Complete draft of first spatial notebook#949

Open
sjspielman wants to merge 7 commits intomasterfrom
sjspielman/923-924-normalize-and-pretty-plots
Open

Complete draft of first spatial notebook#949
sjspielman wants to merge 7 commits intomasterfrom
sjspielman/923-924-normalize-and-pretty-plots

Conversation

@sjspielman
Copy link
Member

Closes #923
Closes #924

This PR adds the remaining sections to the first spatial notebook draft. I aimed to keep these sections pretty short since we have a lot already!

  1. Section on normalization: This is very brief, and pretty straightforward. Anything else we'd like to see here?
  2. Section on pretty plots: For this section...
    • I defined a vector of genes of interest, alongside a table briefly describing those genes. I then plot expression for two of the genes. Note that I'm using indexing here with the goi vector I defined - let me know if that's too confusing and I should hardcode some more.
    • Then, I have some TBD: either go on your own adventure to pick a gene from our list and plot it, or we can show them how to plot it all at once with purrr. I like the independent exploration on one hand, but I also really appreciate the story we can tell from seeing all these plots at once. Anyone have a preference?
    • Note: I only included plotCoords() here, since plotVisium() with overlaid colored spots is a wild adventure to interpret. Does anyone want to advocate for showing it (even if only to show "gee I can't read this")?
    • Cool with regular viridis? Of course this is logcounts and not a z-score, but I'm not worried about reusing that palette in this case. Does anyone disagree?

Rendered notebook:
knitted.nb.html

@sjspielman sjspielman marked this pull request as ready for review March 3, 2026 20:29
Copy link
Member

@jashapiro jashapiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good. I mostly have some comments about the gene list and how to handle getting it. It would be nice to provide the code to look up the gene ids from gene names (even better if that is already in the Space Ranger-derived rowData, but I don't remember if it is right now). But I would only use a vector after plotting a couple of individual genes (not pulling them from the vector). Or if you do use a named vector, use the names!

Comment on lines +789 to +797
goi_list <- c(
"WT1" = "ENSG00000184937",
"SIX1" = "ENSG00000126778",
"MYCN" = "ENSG00000134323",
"NCAM1" = "ENSG00000149294",
"COL1A1" = "ENSG00000108821",
"TAGLN" = "ENSG00000149591",
"PECAM1" = "ENSG00000261371"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think this is overkill. Just show the two genes. If you want to get fancy, maybe show them how to look up the gene symbol for a gene of interest, rather than providing a named vector (which is not a list, so don't name it that!)

We have a few more genes listed in the table, take a moment to plot one (or more!) below.
Do you see any spatial structure that seems consistent with the H&E?
Different from the H&E?
Are there regions of shared expression among genes, and would you expect that based on WT biology?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't go quietly.

Suggested change
Are there regions of shared expression among genes, and would you expect that based on WT biology?
Are there regions of shared expression among genes, and would you expect that based on Wilms tumor biology?


**OR**

Let's use some `purrr` magic to plot this all at once!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, I'm not too mad at this. But I'd still want to start with just a list of gene names and get the ensembl ids programmatically rather than providing them together.

Comment on lines +804 to +815
gene_index <- 1

wt1_plot <- ggspavis::plotCoords(
norm_spe,
# name of variable to color by
annotate = goi_list[gene_index],
# counts are plotted by default, so we need to override this
assay = "logcounts",
point_size = 1
) +
ggplot2::scale_color_viridis_c() +
ggplot2::labs(title = names(goi_list[gene_index]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do decide you want to use the vector of genes, don't make a named vector and then not take advantage of it!

Suggested change
gene_index <- 1
wt1_plot <- ggspavis::plotCoords(
norm_spe,
# name of variable to color by
annotate = goi_list[gene_index],
# counts are plotted by default, so we need to override this
assay = "logcounts",
point_size = 1
) +
ggplot2::scale_color_viridis_c() +
ggplot2::labs(title = names(goi_list[gene_index]))
gene_name <- "WT1"
wt1_plot <- ggspavis::plotCoords(
norm_spe,
# name of variable to color by
annotate = goi_list[gene_name],
# counts are plotted by default, so we need to override this
assay = "logcounts",
point_size = 1
) +
ggplot2::scale_color_viridis_c() +
ggplot2::labs(title = gene_name)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♀️

@sjspielman
Copy link
Member Author

I think what I would like to do is:

  • show plotting two genes individually (sans vector) that show contrasting biology. focus here on plotting, dont introduce potential confusion from a vector yet
  • then after we've plotting some, programmatically define a bigger vector of genes and show plotting them all with map, which demos a code strategies for looking at a lot of genes at once

Copy link
Member

@allyhawkins allyhawkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting that I don't have any additional comments at this time beyond what's been posted and agree with the plan to look at two genes individually and then plot the vector of genes.

@sjspielman
Copy link
Member Author

Updated as discussed! Current version: 01-spatial_intro.nb.html

Copy link
Member

@allyhawkins allyhawkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. My only comment is that I think the section showing the rowData and the two ensembl gene Ids is a little overkill and I would probably just remove it.


We'll need to provide the gene's corresponding row name, which is its Ensembl gene id, to `ggpsavis::plotCoords()` so let's go ahead and find those first.

The `rowData` slot helpfully provides a gene symbol/Ensembl id mapping, if you haven't memorized all the ids yet:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥁



```{r get-ensembl, live = TRUE}
# define gene symbols
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it can be helpful to show examples of grabbing information from the SPE, but I don't know that it's totally necessary here. Given the length of this notebook, I might favor skipping this and the next chunk.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe put something like this in the exercise instead to demo for them? (with solution = TRUE)
I have a panel of plots in the exercise outline too so this could be ready to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spatial instruction notebook 1: Draft marker gene section Spatial instruction notebook 1: Draft normalization section

3 participants