LieberInstitute / spatialDLPFC

spatialDLPFC project involving Visium (n = 30), Visium SPG (n = 4) and snRNA-seq (n = 19) samples
http://research.libd.org/spatialDLPFC/
17 stars 3 forks source link

Prepare and eventually deploy iSEE shiny apps #80

Closed lcolladotor closed 2 years ago

lcolladotor commented 2 years ago

We will pseudo-bulk the Visium n = 30 samples in different ways. Given that spatialLIBD only has one pseudo-bulk level panel, and since we want users to be able to explore the data from the different pseudo-bulk analyses, we need to create some iSEE::iSEE() shiny apps.

This will involve adapting code from https://github.com/LieberInstitute/10xPilot_snRNAseq-human/tree/master/shiny_apps. Overall, it involves:

Since we had lots of similar apps in the Tran et al, Neuron, 2021 project I ended up writing templates and using the whisker package to fill out these templates and create the app_dir for each of the shiny apps. See https://github.com/LieberInstitute/10xPilot_snRNAseq-human/blob/810b47364af4c8afe426bd2a6b559bd6a9f1cc98/shiny_apps/00_clean_functions.R#L160-L182 and other parts of that script.

The apps we'll make will depend on the pseudo-bulk analyses we make. Though we could potentially make one for say each BayesSpace k across sample IDs, one for each k = 2 up to 28 (so 27 of them). This will let users explore our data at whichever resolution they want. So let's start with those.

Remember to optimize the memory of these pseudo-bulk objects, like with https://github.com/LieberInstitute/Visium_IF_AD/blob/3c7a829dc2bee97d8d7850c9df40e2eec6335ef0/code/99_prepare_for_shiny/01_prepare_shiny.R#L79-L82.

Colors will be a big one here. We should make it such that the colors for the clusters for a given k are the same as the colors we use in the spatialLIBD::run_app().

lcolladotor commented 2 years ago

For specifying colors, you need a named character vector like https://github.com/LieberInstitute/10xPilot_snRNAseq-human/blob/51d15ef9f5f2c4c53f55e22e3fe467de1a724668/shiny_apps/tran2021_DLPFC/app.R#L7. In this case Matt had made them.

library(iSEE)

library(scRNAseq)

# Example data ----
sce <- ReprocessedAllenData(assays="tophat_counts")
class(sce)

library(scater)
sce <- logNormCounts(sce, exprs_values="tophat_counts")

sce <- runPCA(sce, ncomponents=4)
sce <- runTSNE(sce)
rowData(sce)$ave_count <- rowMeans(assay(sce, "tophat_counts"))
rowData(sce)$n_cells <- rowSums(assay(sce, "tophat_counts") > 0)
sce

# launch the app itself ----

app <- iSEE(sce)
if (interactive()) {
  shiny::runApp(app, port=1234)
}

When we select the driver_1_s variable, some automatic colors are selected. We want to change them.

Screen Shot 2022-07-19 at 11 23 31 AM Screen Shot 2022-07-19 at 11 23 05 AM
## Choose colors
head(sce)
unique(sce$driver_1_s)

driver_colors <- c("red", "blue", "black")
names(driver_colors) <- unique(sce$driver_1_s)
driver_colors
> unique(sce$driver_1_s)
[1] "Scnn1a-Tg3-Cre"  "Rbp4-Cre_KL100"  "Ntsr1-Cre_GN220"
> 
> driver_colors <- c("red", "blue", "black")
> names(driver_colors) <- unique(sce$driver_1_s)
> driver_colors
 Scnn1a-Tg3-Cre  Rbp4-Cre_KL100 Ntsr1-Cre_GN220 
          "red"          "blue"         "black" 

Now that you have your colors chosen in a named character vector, we need to make an ExperimentColorMap() like at https://github.com/LieberInstitute/10xPilot_snRNAseq-human/blob/51d15ef9f5f2c4c53f55e22e3fe467de1a724668/shiny_apps/tran2021_DLPFC/app.R#L139-L148.

if (interactive()) {
  iSEE(sce, colormap = ExperimentColorMap(colData = list(
        driver_1_s = function(n) {
            driver_colors
        }
    )))
}

So now when we select the driver_1_s variable, the colors we specified in ExperimentColorMap() get used =).

Screen Shot 2022-07-19 at 11 21 20 AM Screen Shot 2022-07-19 at 11 21 43 AM
lcolladotor commented 2 years ago

@heenadivecha, we'll reduce this goal to just the k = 9 and k = 16 pseudo-bulk data. Since it's only 2 apps, we can do them manually instead of using code that writes code. Hence why I'm un-assigning @lahuuki from this issue.

lcolladotor commented 2 years ago

For k = 9 and k = 16, @heenadivecha let's use the files from:

You'll need to find where the files are and make soft links from your new shiny app directories (one for each k).

lcolladotor commented 2 years ago

For k = 28 (or other k values) use /dcs04/lieber/lcolladotor/spatialDLPFC_LIBD4035/spatialDLPFC/processed-data/rdata/spe/pseudo_bulked_spe/spe_pseudobulk_bayesSpace_normalized_filtered_cluster_k28.RDS

lcolladotor commented 2 years ago

Let's name them:

heenadivecha commented 2 years ago

iSEE apps for k=9, K=16 and k=28 were deployed