DefaultAssay(data) <- “RNA” counts <- GetAssayData(data) rownames(counts) -> rowname rowname[grep(“IGH”, rowname)] -> H rowname[grep(“IGL”, rowname)] -> L rowname[grep(“IGK”, rowname)] -> K rowname[grep(“TRA”, rowname)] -> TA rowname[grep(“TRB”, rowname)] -> TB rowname[grep(“MT-”, rowname)] -> mt immunegenes <- c(H, L, K, TA, TB, mt) setdiff(rowname,immunegenes) -> rownames counts[(which(rownames(counts) %in% rownames)),] -> counts2 data2 <- subset(data, features= rownames(counts2))