ludvigla / semla

Other
56 stars 5 forks source link

Problem with `override_plot_dims` #25

Closed liuxiawei closed 5 months ago

liuxiawei commented 6 months ago

Semla is wonderful tools ! but When I used it I met some problem. I have a seurat object (S4). Which is consist with two sample in one slice. 图片

I split it in two object by code folloed:

t<-pbmc@meta.data

t$orig.ident<-ifelse(t$x > 8000 &t$y>5000, "A", "B")
pbmc@meta.data<-t
tA<-subset(pbmc, orig.ident=="A" )
tB<-subset(pbmc, orig.ident=="B" )
ggplot(tA@meta.data, aes(x= x, y = -y))+
        geom_point(size = 0.1, color = "grey") +
        theme_classic()
ggplot(tB@meta.data, aes(x= x, y = -y))+
        geom_point(size = 0.1, color = "grey") +
        theme_classic()

It could show rightly with any plot function in seurat ( center and scaled) 图片 Then I tansformed it into semla by UpdateSeuratForSemla function It showed with raw coordinate and part object 图片 I tried to use override_plot_dims to auto scale the image area, But it error:

> MapLabelsSummary(brain_semla, 
+                  column_name = "seurat_clusters", 
+                  ncol = 1, 
+                  override_plot_dims = TRUE, 
+                  section_number = 1) &
+   theme(legend.position = "none")
Error in `MapLabels()`:
! 'crop_area' can only take values between 0-1
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Error in `MapLabels()`:
! 'crop_area' can only take values between 0-1
---
Backtrace:
    ▆
 1. └─semla::MapLabelsSummary(...)
 2.   ├─semla::MapLabels(...)
 3.   └─semla:::MapLabels.Seurat(...)
Run rlang::last_trace(drop = FALSE) to see 1 hidden frame.

I tried with merged object( by brain.merge <- merge(tA, tB)) and split object (only tA or tB), it always wrong. What should I do to correct the visualization? and is there any method to use crop_area to merged object?

And Thanks for any help!

lfranzen commented 5 months ago

Hello @liuxiawei – first of all, sorry for the late response to your issue! I know there seems to be some bugs appearing around the spatial properties when converting back and forth between Seurat and semla objects.

As a workaround for now I'd recommend to,

  1. Create a new semla object directly from scratch
  2. Split your two sections using SubsetSTData() (if you want, you can also use the FeatureViewer to annotate your two sections using an interactive lasso tool and create a metadata column by which you can split your objects – this could be handy if your sections aren't directly separable by single x/y coordinates),
  3. Extract the Staffli objects (with GetStaffli()) from your two new subsetted semla objects,
  4. Then you can try to attach the corresponding Staffli objects to your semla-from-Seurat objects (like tA@tools$Staffli <- staffli_A).

Hopefully that should solve your plotting issues, but I know it's not an ideal solution. If that works we would however know that the issue is related to the transfer of the spatial coordinates, especially when subsetting has been applied to the original seurat object.

Let me know if this seems to help somewhat or if your issues still persists!

Kind regards, Lovisa

liuxiawei commented 5 months ago

I am very pleased that you have replied to me. I will try to manually correct the coordinates and carry on with my research using the method you mentioned. Thank you for your support!