ludvigla / semla

Other
62 stars 5 forks source link

Issue with point size not keeping scale with image dimensions #19

Open ejscience opened 1 year ago

ejscience commented 1 year ago

I have loaded some data into an SE object using the following code

samples <- "/mnt/newusb/rojas/spatialtranscriptomics/spaceranger_outs/RhSpTr-emb020-021/emb020/outs/filtered_feature_bc_matrix.h5"
imgs <- "/mnt/newusb/rojas/spatialtranscriptomics/spaceranger_outs/RhSpTr-emb020-021/emb020/outs/spatial/tissue_hires_image.png"
spotfiles <- "/mnt/newusb/rojas/spatialtranscriptomics/spaceranger_outs/RhSpTr-emb020-021/emb020/outs/spatial/tissue_positions.csv"
json <- "/mnt/newusb/rojas/spatialtranscriptomics/spaceranger_outs/RhSpTr-emb020-021/emb020/outs/spatial/scalefactors_json.json"
sample_ids <- c("emb020")

infoTable <- tibble(samples, imgs, spotfiles, json, sample_ids)
print(infoTable)

se_emb020 <- ReadVisiumData(infoTable, 
                            remove_spots_outside_HE = F,
                            remove_spots_outside_tissue = F)

se_emb020 <- LoadImages(se_emb020)
ImagePlot(se_emb020)

From there I was able to graph out my feature plot as a first pass

MapFeatures(se_emb020, 
            features = c("nCount_Spatial"),
            colors = viridis(11, direction = 1),
            scale_alpha = F,
            pt_size = 1.6,
            image_use = "raw",
            override_plot_dims = TRUE) & ThemeLegendRight()

However, as you can see the pt size is not at the correct 1. Which I assumed was the actual size of the capture dots.

image

I then tried to zoom in using the crop functions and these seem to be having an issue with my sections

I tried to map with this grid

image

Then I ran this crop

MapFeatures(se_emb020,
            features = c("DDX4"), 
            image_use = "raw", 
            pt_size = 1.6,
            colors = cols_he, 
            crop_area = c(.15, .4, .5, .8))
image

And this one

MapFeatures(se_emb020,
            features = c("DDX4"), 
            image_use = "raw", 
            pt_size = 1.6,
            colors = cols_he, 
            crop_area = c(.15, .5, .4, .7))
image

Could anyone explain why the dots are not staying the same across either the cropping or the size of the image?

lfranzen commented 11 months ago

Hi! Thank you for addressing this and for your detailed description of the issue. As you have noticed, the default spot size does not correspond to the actual size of a capture spot, as this is not the most trivial matter to solve. The data is plotted using ggplot with geom_point(), and the spot sizes provided (pt_size) is passed directly to the size argument in geom_point(). As with other plots created this way and in the cases you're showing here, the point sizes will be kept constant and not change in relation to the plot area (i.e. axis limits, or crop areas in this case). Therefore, you'll here have to manually adjust (increase) the pt_size when cropping/decreasing the field of view.

Having a default pt_size that would correspond to the actual spot diameter would of course be a desirable functionality, and is something that we could look into for future updates of semla. Thanks again for highlighting this, and apologies if the current behaviour of pt_size was not clear from the documentations. Hope this description answers your question!

jemorlanes commented 6 months ago

Hello!

I'm joining very late here. I just wanted to mention that for VisiumHD this will not be an issue. When plotting the VisiumHD spots on top of the HE, the size of the spots (squares) represents their true size in relation to the HE image.

We are working on a tutorial with basic guidelines/issues encountered when working with this type of data. For a bit more context regarding what we are working on right now, issue #28 could be interesting.

Thanks for using the package! :))