scverse / scanpy

Single-cell analysis in Python. Scales to >1M cells.
https://scanpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.81k stars 586 forks source link

using fullres image in scanpy.pl.spatial #1436

Open vitkl opened 3 years ago

vitkl commented 3 years ago

Hi, scanpy team!

I am trying to understand if scanpy.pl.spatial would support using the fullres histology image. E.i. if it supports img_key = 'fullres where it would pull the image from 'fullres' slot in adata.uns['spatial'] and use the coordinates in adata.obsm['spatial'] as is with no transformation.

I hope this is the right space to ask my question. Thanks a lot!

giovp commented 3 years ago

Hi @vitkl , by fullres you mean the tiff image yes? This is not supported for now unfortunately, but we are working toward some extensions to make this possible (cc @hspitzer ). One hacky way to go about this for now could be to:

vitkl commented 3 years ago

Hi @geovp!

Yes, I mean the original image that was supplied to SpaceRanger pipeline. It doesn't have to be a TIFF image - in my experience slide scanners save JPEG images internally, so there is no value in converting that to TIFF. Also, it would be cool to use sc.pl.spatial for other technologies - say to overlay single cell spatial over the microscopy image image.

Nice, I was using this hacky way before (if I remember correctly I also changed spot size in the respective slot) - so it does work.

I am wondering if you could add support for a fullres slot with size factor 1 and explain which variables need to be set for it to work in the tutorial.

On Thu, Oct 1, 2020 at 8:32 PM giovp notifications@github.com wrote:

Hi @vitkl https://github.com/vitkl , by fullres you mean the tiff image yes? This is not supported for now unfortunately, but we are working toward some extensions to make this possible (cc @hspitzer https://github.com/hspitzer ). One hacky way to go about this for now could be to:

  • assign the tiff to the hires slot in adata.uns['spatial]['library_id']['images']['hires']
  • change the hires scalefactor value to 1 in the respective slot This should work. also for plotting the spots in the right size. Of course, this is also possible if you replace the "lowres" instead. Let me know what you think about it and if it works.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/theislab/scanpy/issues/1436#issuecomment-702351783, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFMFTV5FBT2DB4GKUIZUVNTSITKMBANCNFSM4R5XDYSQ .

giovp commented 3 years ago

It doesn't have to be a TIFF image - in my experience slide scanners save JPEG images internally, so there is no value in converting that to TIFF.

This is interesting to know.

Also, it would be cool to use sc.pl.spatial for other technologies - say to overlay single cell spatial over the microscopy image image.

Can you elaborate on this? What tipe of technology and plot do you have in mind?

I am wondering if you could add support for a fullres slot with size factor 1 and explain which variables need to be set for it to work in the tutorial.

Mmh, I still think that the added value for looking at the fullres instead of the png in the context of overlaying spots to image is very little. In the hires png, even when cropping, the underlying resulting image is still quite good. Maybe not enough for analysis purpose, but for visualization should do the job no? I'm interested to hear your thoughts on this.

The reason for not supporting it in the same way it's done now is that the image can be quite big (several GBs for fluorescent visium for instance) and so maybe it's not a good idea to load it in the anndata. I'll think about including a small section on this in the tutorial.

vitkl commented 3 years ago

I mean any smFISH or highly-multiplexed protein technology. The plot I have in mind is this: This visualisation is implemented in our package (in active development - we haven't released yet): https://cell2location.readthedocs.io/en/latest/cell2location.plt.html#cell2location.plt.mapping_video.plot_spatial download-20

I agree that the original images can be quite large so it is probably better to not load them by default. However, it is useful to have an option to load. For the Visium data, the utility of using fullres depends on image quality and the goals. Generally, cell diameter in highres images is just 1-4 pixels meaning that a cropped image with, say 10*10 spots will look pixelated and may not be enough to recognise small structures like a gland or a blood vessel, not mentioning cell morphologies or staining (e.g. eosinophils containing red granules). For single-cell resolution data, it is often useful to zoom in to see if only cells of specific morphology express the gene, like Agt below. download-19

giovp commented 3 years ago

Hi @vitkl

thanks a lot for the feedback, all noted, we'll work toward enabling large tissue image available for storing+plotting. Will keep this open for reference!