No applicable method for 'DefaultAssay' applied to an object of class "list"

1.7k Views Asked by At

I'm using "seurat" to process some data that my instructor handed me. I first extracted the part of B Cells and defined it as pbmc. Then I tried to analyze the mitochondria in it. But then I got the following error and I don't know how to fix it.

 pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^mt-")
   Error in UseMethod(generic = "DefaultAssay", object = object) : 
   no applicable method for 'DefaultAssay' applied to an object of class "list"

Here is the code involved in my operation:

install.packages("Seurat")
install.packages("dplyr")
install.packages("patchwork")
library(dplyr)
library(Seurat)
library(patchwork)
library(ggplot2)
setwd('E:/YL')
rm(list=ls())
pbmc.data <- readRDS("E:/YL/BB.rds")
pbmc <- pbmc.data['B Cells']
pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^mt-")

Here is a picture of the data I am working with.

enter image description here enter image description here

1

There are 1 best solutions below

0
On

Probably a little too late to help you solve this problem, but the PBMC object is of type list, while the first element in the list (B Cells) is the actual seurat object that the the function is looking for. You'll want to extract the B Cells object out of the list object and use that.

Something like: b_cells <- pbmc[1][[1]] b_cells[["percent.mt"]] <- PercentageFeatureSet(b_cells, pattern = "^mt-")