Skip to content

Problem with plotting scale.data when DefaultAssay is set to RNA #9796

Open
@dizhengao

Description

@dizhengao

Dear Seurat Team,

When DefaultAssay of a Seurat object is set to RNA, then even when assay = "SCT", layer = "scale.data" are passed to VlnPlot, it will still try to find scale.data in the RNA assay and return an error message

layer "scale.data" is not found in assay: "RNA"

I think the problem comes from how VlnPlot arguments are used in the function, especially in L644 where layer.set is searched in the Default assay of the object instead of the assay that is passed to the function, therefore when DefaultAssay is set to RNA and layer = scale.data, nothing can be found and layer.set will be set to NULL.

layer.set <- suppressWarnings(
    Layers(
      object = object,
      search = layer %||% 'data'
    )
)

And then in L662, it will find layer.set as NULL and return the error message.

if (is.null(layer.set)) {
  stop('layer "', layer,'" is not found in assay: "', assay.name, '"')
} else {
  layer <- layer.set
}

Though this is not a big issue as we can always set default assay before plotting, but I find it more convenient if VlnPlot can search for layer in the assay that is passed to the function. This will be especially useful when one wants to plot data from multiple assays&layers in the same plot such as below. Unless this was intended by the developers to stop people from plotting scale.data unintentionally?

#this will not work when DefaultAssay is set to RNA
(VlnPlot(col.23, features = c("AT1G77450"),assay = "RNA",layer = "data") + ggtitle("RNA data") + theme(legend.position = "none")) +
  (VlnPlot(col.23, features = c("AT1G77450"),assay = "SCT",layer = "data") + ggtitle("SCT data") + theme(legend.position = "none")) +
  (VlnPlot(col.23, features = c("AT1G77450"),assay = "SCT",layer = "scale.data") + ggtitle("SCT scale.data") + theme(legend.position = "none"))
  plot_layout(guides = "collect")

Demonstration

Below is an example of the issue. I have an object that has been SCTransformed. It has counts and data layers in the RNA assay, and counts, data, scale.data in the SCT assay.

DefaultAssay(col.23) <- "RNA"
col.23
An object of class Seurat 
50381 features across 35037 samples within 2 assays 
Active assay: RNA (27420 features, 0 variable features)
 2 layers present: counts, data
 1 other assay present: SCT
 3 dimensional reductions calculated: pca, umap, integrated.dr
VlnPlot(col.23, features = c("AT1G77450"),assay = "SCT",layer = "scale.data") + ggtitle("SCT scale.data") + theme(legend.position = "none")

Error in VlnPlot(col.23, features = c("AT1G77450"), assay = "SCT", layer = "scale.data") : 
  layer "scale.data" is not found in assay: "RNA"

When DefaultAssay is set to SCT, VlnPlot works (plot is not included here, but everything works).

DefaultAssay(col.23) <- "SCT"
col.23
An object of class Seurat 
50381 features across 35037 samples within 2 assays 
Active assay: SCT (22961 features, 3000 variable features)
 3 layers present: counts, data, scale.data
 1 other assay present: RNA
 3 dimensional reductions calculated: pca, umap, integrated.dr
VlnPlot(col.23, features = c("AT1G77450"),assay = "SCT",layer = "scale.data") + ggtitle("SCT scale.data") + theme(legend.position = "none")
#This works but I will drop the actual plot as it doesn't matter here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions