ludvigla / semla

Other
47 stars 6 forks source link

Will semla be compatible with HD visium? #28

Closed NiklausZZZ closed 2 months ago

NiklausZZZ commented 2 months ago

Hi there!

I wanted to express my gratitude for the incredible tool provided by the authors. I noticed that Semla doesn't seem to be compatible with 10X HD Visium data. Do you have plans to make Semla compatible with HD Visium in the future?

NiklausZZZ commented 2 months ago

se = LoadImages(se) ! White space will be added to H&E images to fit all spots on the images

── Loading H&E images ──

ℹ Loading image from ./Visium_HD/square_008um/spatial/tissue_lowres_image.png Error in FUN(): ! image_height has to be smaller than or equal to 389px Run rlang::last_trace() to see where the error occurred.

NiklausZZZ commented 2 months ago

Human Colorectal Cancer test data downloaded from https://www.10xgenomics.com/datasets/visium-hd-cytassist-gene-expression-libraries-of-human-crc

jemorlanes commented 2 months ago

Hello! :)

Great question! Currently semla is fully compatible with VisiumHD. We are working on a tutorial regarding specificities of VisiumHD's data structure and basic guidelines/common issues encountered when plotting the data. Semla has now a branch in development in which we are making constant changes to some of the plotting functions . These changes are focused on plotting the VisiumHD spots as squares instead of points, which was the only available option until now. You can install this in-development branch with remotes::install_github("ludvigla/semla@grid_plots"). Our plan is to continue updating and supporting semla for VisiumHD and other technologies.

The issue you are encountering now however, is unrelated to VisiumHD. The function LoadImages() takes as default for the argument image_height of 400. However, the _tissue_lowresimage.png that you are trying to load has a height of 389px, and that is why the error is popping up.

If you want a higher resolution image for downstream plotting, I recommend you load the _tissue_hiresimage.png instead. Then you can load it at it's max resolution with the following: se.hd <- LoadImages(se.hd, image_height = as.numeric(GetImageInfo(se.hd)$height)) Otherwise, if you want to work with the lowres image, you can load it as such: se.hd <- LoadImages(se.hd, image_height = 389)

Going back to the in-development branch, we have made some changes to the MapFeatures function, and are currently working on MapLabels and MapMultipleFeatures. Now we have an extra argument called shape in which you can specify how you wish to represent the spots. The default argument is "points", and the extra options are "tile" and "raster". All the plotting options that you can find in the tutorial of the website should be compatible with this new version of the function. Some example code:

MapFeatures(se.hd, features = "nFeature_Spatial", shape = "tile", image_use = "raw")
MapFeatures(se.hd, features = "nFeature_Spatial", shape = "tile", image_use = NULL)
MapFeatures(se.hd, features = "nFeature_Spatial", shape = "raster", image_use = NULL)
NiklausZZZ commented 2 months ago

Great! It's working perfectly! Thank you very much for your prompt response.

By the way, regarding the result of MapFeatures(se.hd, features = "nFeature_Spatial", shape = "tile", image_use = "raw"), it seems that it might be influenced by the original tissue_lowres_image.png. Any suggestions would be greatly appreciated! image

jemorlanes commented 2 months ago

No problem! :)

What is happening here is that the tissue image is much greater than the capture area of VisiumHD. The file _detected_tissueimage.jpg (you should find it in the "spatial" folder) shows the area of the tissue that is actually under the capture array. If you open it, you will see that the highlighted area is the same as the area with counts in the image you attached.

In semla we give the option to either plot the entire loaded image (which is what you are doing up there), or to crop the image to show only the capture area + a bit of it's surroundings. You can control this with the argument override_plot_dims = TRUE. So the code should be MapFeatures(se.hd, features = "nFeature_Spatial", shape = "tile", image_use = "raw", override_plot_dims = TRUE)

Hope this achieves what you want!

NiklausZZZ commented 2 months ago

Cool! Thank you so much for your quick response.

Famingzhao commented 2 months ago

Hi guys! This is really an interesting topic about Visium HD~ Recently, I introduced the semla R package in the Chinese community, see:

I just wanted to let the authors know that the semla R package is getting a lot of attention! I will add the Visium HD to the series of Chinese tutorials!

ludvigla commented 2 months ago

Thanks for sharing this @Famingzhao, I really like your blog posts. Thank god for Googles translate feature 😁 And nice to see the comparison between NNLS and cell2location!

We did some benchmarks for the the NNLS method in the paper (supplementary material) that you should check out. We tried cell2location, stereoscope, RCTD and Seurat.

NiklausZZZ commented 2 months ago

Hi, I installed the newest version of semla by remotes::install_github("ludvigla/semla@grid_plots"). But I encountered a new bug, as followed:

MapLabels(se, column_name = "seurat_clusters",  image_use = "raw", pt_alpha = 0.6, pt_size = 2)
Error in MapLabels.Seurat(se, column_name = "seurat_clusters", image_use = "raw",  : 
  object 'shape' not found

Any suggestions would be greatly appreciated!

NiklausZZZ commented 2 months ago

I found some potential reasons in the semla@grid_plots branch, although I'm not entirely certain.

image

jemorlanes commented 2 months ago

I see, thanks for noticing it! MapLabels() was inheriting some features from other functions that prevented it to work properly. I have made a new push doing a workaround to avoid that issue. You should reinstall the package from the grid_plots branch to get the latest changes.

We haven't implemented the square plotting for MapLabels(), MapMultipleFeatures() or MapFeaturesSummary(), and there might appear some bugs when using those functions even without the square plotting. If you encounter any other issues, it would be super if you let us know :))

Hope it works now :)

NiklausZZZ commented 2 months ago

Many thanks for your quick response!

jemorlanes commented 2 months ago

Quick follow up, if you reinstall the current version of the branch, you should be able to use MapLabels and MapMultipleFeatures with the square-spot options! We are still developing the plotting options and working on a tutorial for the website, so it is quite likely that you will find some bugs. For example, when subsetting the data it is possible that the y-axis will be flipped in the output. If you encounter any issues, please let us know! That way we can work to address them