MarcElosua / SPOTlight

Spatial Transcriptomics Capture Location Deconvolution
https://marcelosua.github.io/SPOTlight
GNU General Public License v3.0
162 stars 25 forks source link

SPOTlight Compatibility with Staffli Objects Generated from STUtility #41

Closed gabebarron closed 2 years ago

gabebarron commented 2 years ago

Hi!

I have been processing some 10X Visium data with STUtility. The pipeline generated therein returns a Staffli object where the scaled images in raster format and coordinates for the corresponding spots are saved.

I later turned the Staffli object into a Seurat object to do harmony integration and clustering analysis, but when I try to plot the Spatial Scatterpie it does not return. Do you have any suggestions on accessing the Staffli data?

MarcElosua commented 2 years ago

Hi @gabebarron,

Thank you for using SPOTlight and apologies for the delay in answering. If you install the latest version of SPOTlight you should be able to run plotSpatialScatterpie regardless of the data container. You can pass the parameters x (coordinates) and y (deconvoluted celltypes) as matrices. As for the image you can pass the path of the image you fed to spaceranger!

Please let me know if it works, Marc

jenli3 commented 2 years ago

Dear Marc

I've had the same issues as well using plotSpatialScatterpie using STUtility/Staffli spatial data using infoTable input which contains imgs, json, slide, spotfiles and samples

brief example:

_spe = InputFromTable(infotable = infoTable, min.gene.spots = 5, min.spot.count = 50, platform = "Visium") st.object = GetStaffli(spe) spe$sampleid = paste0("section", GetStaffli(spe)@meta.data$sample)_

this se object is then processed/analysed as usual pipelines I am able to use a ref sc data set and follow your tutorial to extract SPOTlight results to 'mat'. Issue is at the final step

_plotSpatialScatterpie( x = spe, y = mat, cell_types = colnames(y), img = FALSE, #(similar result if this is TRUE) scatterpie_alpha = 1, piescale = 0.11)

Running this gives the output. "Error: No images present in this Seurat object" ImagePlot(spe) still shows the rastered H&E tissue images

Is there something I'm missing for plotSpatialScatterpie input?

Thanks for your help Cheers, J

MarcElosua commented 2 years ago

hi @jenli3,

I haven't played around with STutility so I don't know how the conversion function works or how the Seurat object looks after it. When using plotSpatialScatterpie you can directly pass to the function the spot coordinates. Extracting them from Seurat looks like this:

Seurat::Images(spe) # Get names for the slices in the Seurat object
x <- as.matrix(Seurat::GetTissueCoordinates(sp_sub, "slice_name")) # extract coordinates form the image of interest

head(x)
#                                     imagerow  imagecol
# AAACAAGTATCTCCCA-1   376.3211  441.2937
# AAACACCAATAACTGC-1  434.7098  132.0243
# AAACAGAGCGACTCCT-1 142.7664  411.4929
# AAACATTTCCCGGATT-1   447.7043 422.7548
# AAACCCGAACGAAATC-1 343.9215  489.8065
# AAACCGGAAATGTTAA-1  402.1369  523.2457

SPOTlight::plotSpatialScatterpie(
    x = x,
    y = mtrx,
    img = FALSE)

I wonder how x looks for the converted Seurat object since plotSpatialScatterpie should do this under the hood already. Could you check if this works please?

jenli3 commented 2 years ago

Thanks Marc

I couldn't fix the issue, there's something about STUtility's S4 generation, I could not convert it to a SeuratObject your scripts ask for.

Even when checking str(object), I get "Formal class 'Seurat' [package "SeuratObject"] with 13 slots" but is(x, "Seurat") returns FALSE

Instead

Maybe there could be an option to say the "x" passed through is STUtility and bypass the automatic error message from your plotSpatialScatterpie.R?

Cheers, Jen

MarcElosua commented 2 years ago

Hi @jenli3 ,

I will try to implement this when I have some time. In the meantime you can install the latest version of SPOTlight:

install_github("https://github.com/MarcElosua/SPOTlight")

With the current version you can pass a matrix or dataframe to x and y with the necessary information:

#' @param x Object containig the spots coordinates, it can be an object of class
#'   SpatialExperiment, Seurat, dataframe or matrix. For the latter two
#'   rownames should have the spot barcodes to match x. If a matrix it has to
#'   of dimensions nrow(y) x 2 where the columns are the x and y coordinates
#'   in that order.
#' @param y Matrix or dataframe containing the deconvoluted spots. rownames
#'   need to be the spot barcodes to match to x.

Hope this helps!