Below is the code I ran and the error I got: I think it might be having to rescale the subs object lead to two scale data that might cause the problem but i still couldn't fix the problem:
lapply(COI, function(x){
+
-
subset
- subs <- subset(scc.sub, subset = ReceivingType == x)
-
print number of cells per condition
- print(paste0(x , ": Normal:", sum(subs@meta.data$Condition == "Normal")))
- print(paste0(x , ": Tumor:", sum(subs@meta.data$Condition == "Tumor")))
- subs <- SetAssayData(subs, assay = "SystemToCell", slot = "scale.data", new.data = matrix())
- #set idents
- Idents(subs) <- subs@meta.data$Condition
-
scale the subsetted data
- FindVariableFeatures(subs, assay = 'SystemToCell', selection.method = "disp")
- ScaleData(subs, assay = 'SystemToCell')
-
find markers (here we use ROC)
- markers <- FindAllMarkers(subs, test.use = "roc", assay = 'SystemToCell',
-
min.pct = 0.1, logfc.threshold = 0.25,
-
return.thresh = 0.1, only.pos = T)
-
subset to top 10 markers per condition
- top10 <- markers %>% group_by(cluster) %>% top_n(n = 10, wt = myAUC)
-
Make a heatmap
- DoHeatmap(subs, features = top10$gene, assay = "SystemToCell",
-
group.by = "ident", size = 3) +
-
ggtitle(paste("Top DE SystemToCell Mechanisms, Normal vs Tumor:", x))
- })
[1] "Ductal: Normal:496"
[1] "Ductal: Tumor:1646"
Warning: Different features in new layer data than already exists for scale.data
Warning: Different cells in new layer data than already exists for scale.data
Error in validObject(object = object) :
invalid class “Assay5” object: Layers must be two-dimensional objects
Called from: validObject(object = object)
Below is the validObject code that popped up:
function (object, test = FALSE, complete = FALSE)
{
Class <- class(object)
classDef <- getClassDef(Class)
where <- .classEnv(classDef)
anyStrings <- function(x) if (isTRUE(x))
character()
else x
errors <- character()
slotTypes <- classDef@slots
slotNames <- names(slotTypes)
attrNames <- c(".Data", ".S3Class", names(attributes(object)))
if (anyNA(idx <- match(slotNames, attrNames))) {
badSlots <- is.na(idx)
errors <- c(errors, paste("slots in class definition but not in object:",
paste0(""", slotNames[badSlots], """, collapse = ", ")))
slotTypes <- slotTypes[!badSlots]
slotNames <- slotNames[!badSlots]
}
for (i in seq_along(slotTypes)) {
classi <- slotTypes[[i]]
classDefi <- getClassDef(classi, where = where)
if (is.null(classDefi)) {
errors <- c(errors, paste0("undefined class for slot "",
slotNames[[i]], "" ("", classi, "")"))
next
}
namei <- slotNames[[i]]
sloti <- try(switch(namei, .S3Class = S3Class(object),
slot(object, namei)), silent = TRUE)
if (inherits(sloti, "try-error")) {
errors <- c(errors, sloti)
next
}
ok <- possibleExtends(class(sloti), classi, ClassDef2 = classDefi)
if (isFALSE(ok)) {
errors <- c(errors, paste0("invalid object for slot "",
slotNames[[i]], "" in class "", Class, "": got class "",
class(sloti)[[1L]], "", should be or extend class "",
classi, """))
next
}
if (!complete)
next
errori <- anyStrings(Recall(sloti, TRUE, TRUE))
if (length(errori)) {
errori <- paste0("In slot "", slotNames[[i]], "" of class "",
class(sloti), "": ", errori)
errors <- c(errors, errori)
}
}
extends <- rev(classDef@contains)
for (i in seq_along(extends)) {
exti <- extends[[i]]
superClass <- exti@superClass
if (!exti@simple && !is(object, superClass))
next
superDef <- getClassDef(superClass)
if (is.null(superDef)) {
errors <- c(errors, paste0("superclass "", superClass,
"" not defined in the environment of the object's class"))
break
}
validityMethod <- superDef@validity
if (is.function(validityMethod)) {
errors <- c(errors, anyStrings(validityMethod(as(object,
superClass))))
if (length(errors))
break
}
}
validityMethod <- classDef@validity
if (length(errors) == 0L && is.function(validityMethod)) {
errors <- c(errors, anyStrings(validityMethod(object)))
}
if (length(errors)) {
if (test)
errors
else {
msg <- gettextf("invalid class %s object", dQuote(Class))
if (length(errors) > 1L)
stop(paste(paste0(msg, ":"), paste(seq_along(errors),
errors, sep = ": "), collapse = "\n"), domain = NA)
else stop(msg, ": ", errors, domain = NA)
}
}
else TRUE
}
sessionInfo()
R version 4.4.0 (2024-04-24)
Platform: x86_64-pc-linux-gnu
Running under: Rocky Linux 9.6 (Blue Onyx)
Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblas-r0.3.26.so; LAPACK version 3.12.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8
[6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
time zone: America/New_York
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_4.0.0 cowplot_1.1.3 presto_1.0.0 data.table_1.17.0 Rcpp_1.0.14 lubridate_1.9.4 forcats_1.0.0
[8] purrr_1.0.4 readr_2.1.5 tidyr_1.3.1 tibble_3.2.1 tidyverse_2.0.0 reshape2_1.4.4 stringr_1.5.1
[15] NICHES_1.1.0 scales_1.4.0 dplyr_1.1.4 Seurat_5.2.1 SeuratObject_5.0.2 sp_2.2-0
loaded via a namespace (and not attached):
[1] RColorBrewer_1.1-3 rstudioapi_0.17.1 jsonlite_2.0.0 magrittr_2.0.3 spatstat.utils_3.1-3
[6] ggbeeswarm_0.7.2 farver_2.1.2 ragg_1.4.0 vctrs_0.6.5 ROCR_1.0-11
[11] spatstat.explore_3.4-2 htmltools_0.5.8.1 sctransform_0.4.1 parallelly_1.43.0 KernSmooth_2.23-26
[16] htmlwidgets_1.6.4 ica_1.0-3 plyr_1.8.9 plotly_4.10.4 zoo_1.8-14
[21] igraph_2.1.4 mime_0.13 lifecycle_1.0.4 pkgconfig_2.0.3 Matrix_1.7-3
[26] R6_2.6.1 fastmap_1.2.0 fitdistrplus_1.2-2 future_1.40.0 shiny_1.10.0
[31] digest_0.6.37 colorspace_2.1-1 patchwork_1.3.0 tensor_1.5 RSpectra_0.16-2
[36] irlba_2.3.5.1 pkgload_1.4.0 textshaping_1.0.0 labeling_0.4.3 progressr_0.15.1
[41] spatstat.sparse_3.1-0 timechange_0.3.0 httr_1.4.7 polyclip_1.10-7 abind_1.4-8
[46] compiler_4.4.0 withr_3.0.2 S7_0.2.0 fastDummies_1.7.5 MASS_7.3-65
[51] tools_4.4.0 vipor_0.4.7 lmtest_0.9-40 beeswarm_0.4.0 httpuv_1.6.15
[56] future.apply_1.11.3 goftest_1.2-3 glue_1.8.0 nlme_3.1-168 promises_1.3.2
[61] grid_4.4.0 Rtsne_0.17 cluster_2.1.8.1 generics_0.1.3 gtable_0.3.6
[66] spatstat.data_3.1-6 tzdb_0.5.0 hms_1.1.3 spatstat.geom_3.3-6 RcppAnnoy_0.0.22
[71] ggrepel_0.9.6 RANN_2.6.2 pillar_1.10.2 spam_2.11-1 RcppHNSW_0.6.0
[76] later_1.4.2 splines_4.4.0 lattice_0.22-7 survival_3.8-3 deldir_2.0-4
[81] tidyselect_1.2.1 miniUI_0.1.1.1 pbapply_1.7-2 gridExtra_2.3 scattermore_1.2
[86] matrixStats_1.5.0 stringi_1.8.7 lazyeval_0.2.2 codetools_0.2-20 cli_3.6.4
[91] uwot_0.2.3 xtable_1.8-4 reticulate_1.42.0 systemfonts_1.2.2 dichromat_2.0-0.1
[96] globals_0.16.3 spatstat.random_3.3-3 png_0.1-8 ggrastr_1.0.2 spatstat.univar_3.1-2
[101] parallel_4.4.0 dotCall64_1.2 listenv_0.9.1 viridisLite_0.4.2 ggridges_0.5.6
[106] crayon_1.5.3 rlang_1.1.5
Below is the code I ran and the error I got: I think it might be having to rescale the subs object lead to two scale data that might cause the problem but i still couldn't fix the problem:
lapply(COI, function(x){
+
subset
print number of cells per condition
scale the subsetted data
find markers (here we use ROC)
subset to top 10 markers per condition
Make a heatmap
[1] "Ductal: Normal:496"
[1] "Ductal: Tumor:1646"
Warning: Different features in new layer data than already exists for scale.data
Warning: Different cells in new layer data than already exists for scale.data
Error in validObject(object = object) :
invalid class “Assay5” object: Layers must be two-dimensional objects
Called from: validObject(object = object)
Below is the validObject code that popped up:
function (object, test = FALSE, complete = FALSE)
{
Class <- class(object)
classDef <- getClassDef(Class)
where <- .classEnv(classDef)
anyStrings <- function(x) if (isTRUE(x))
character()
else x
errors <- character()
slotTypes <- classDef@slots
slotNames <- names(slotTypes)
attrNames <- c(".Data", ".S3Class", names(attributes(object)))
if (anyNA(idx <- match(slotNames, attrNames))) {
badSlots <- is.na(idx)
errors <- c(errors, paste("slots in class definition but not in object:",
paste0(""", slotNames[badSlots], """, collapse = ", ")))
slotTypes <- slotTypes[!badSlots]
slotNames <- slotNames[!badSlots]
}
for (i in seq_along(slotTypes)) {
classi <- slotTypes[[i]]
classDefi <- getClassDef(classi, where = where)
if (is.null(classDefi)) {
errors <- c(errors, paste0("undefined class for slot "",
slotNames[[i]], "" ("", classi, "")"))
next
}
namei <- slotNames[[i]]
sloti <- try(switch(namei, .S3Class = S3Class(object),
slot(object, namei)), silent = TRUE)
if (inherits(sloti, "try-error")) {
errors <- c(errors, sloti)
next
}
ok <- possibleExtends(class(sloti), classi, ClassDef2 = classDefi)
if (isFALSE(ok)) {
errors <- c(errors, paste0("invalid object for slot "",
slotNames[[i]], "" in class "", Class, "": got class "",
class(sloti)[[1L]], "", should be or extend class "",
classi, """))
next
}
if (!complete)
next
errori <- anyStrings(Recall(sloti, TRUE, TRUE))
if (length(errori)) {
errori <- paste0("In slot "", slotNames[[i]], "" of class "",
class(sloti), "": ", errori)
errors <- c(errors, errori)
}
}
extends <- rev(classDef@contains)
for (i in seq_along(extends)) {
exti <- extends[[i]]
superClass <- exti@superClass
if (!exti@simple && !is(object, superClass))
next
superDef <- getClassDef(superClass)
if (is.null(superDef)) {
errors <- c(errors, paste0("superclass "", superClass,
"" not defined in the environment of the object's class"))
break
}
validityMethod <- superDef@validity
if (is.function(validityMethod)) {
errors <- c(errors, anyStrings(validityMethod(as(object,
superClass))))
if (length(errors))
break
}
}
validityMethod <- classDef@validity
if (length(errors) == 0L && is.function(validityMethod)) {
errors <- c(errors, anyStrings(validityMethod(object)))
}
if (length(errors)) {
if (test)
errors
else {
msg <- gettextf("invalid class %s object", dQuote(Class))
if (length(errors) > 1L)
stop(paste(paste0(msg, ":"), paste(seq_along(errors),
errors, sep = ": "), collapse = "\n"), domain = NA)
else stop(msg, ": ", errors, domain = NA)
}
}
else TRUE
}
sessionInfo()
R version 4.4.0 (2024-04-24)
Platform: x86_64-pc-linux-gnu
Running under: Rocky Linux 9.6 (Blue Onyx)
Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblas-r0.3.26.so; LAPACK version 3.12.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8
[6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
time zone: America/New_York
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_4.0.0 cowplot_1.1.3 presto_1.0.0 data.table_1.17.0 Rcpp_1.0.14 lubridate_1.9.4 forcats_1.0.0
[8] purrr_1.0.4 readr_2.1.5 tidyr_1.3.1 tibble_3.2.1 tidyverse_2.0.0 reshape2_1.4.4 stringr_1.5.1
[15] NICHES_1.1.0 scales_1.4.0 dplyr_1.1.4 Seurat_5.2.1 SeuratObject_5.0.2 sp_2.2-0
loaded via a namespace (and not attached):
[1] RColorBrewer_1.1-3 rstudioapi_0.17.1 jsonlite_2.0.0 magrittr_2.0.3 spatstat.utils_3.1-3
[6] ggbeeswarm_0.7.2 farver_2.1.2 ragg_1.4.0 vctrs_0.6.5 ROCR_1.0-11
[11] spatstat.explore_3.4-2 htmltools_0.5.8.1 sctransform_0.4.1 parallelly_1.43.0 KernSmooth_2.23-26
[16] htmlwidgets_1.6.4 ica_1.0-3 plyr_1.8.9 plotly_4.10.4 zoo_1.8-14
[21] igraph_2.1.4 mime_0.13 lifecycle_1.0.4 pkgconfig_2.0.3 Matrix_1.7-3
[26] R6_2.6.1 fastmap_1.2.0 fitdistrplus_1.2-2 future_1.40.0 shiny_1.10.0
[31] digest_0.6.37 colorspace_2.1-1 patchwork_1.3.0 tensor_1.5 RSpectra_0.16-2
[36] irlba_2.3.5.1 pkgload_1.4.0 textshaping_1.0.0 labeling_0.4.3 progressr_0.15.1
[41] spatstat.sparse_3.1-0 timechange_0.3.0 httr_1.4.7 polyclip_1.10-7 abind_1.4-8
[46] compiler_4.4.0 withr_3.0.2 S7_0.2.0 fastDummies_1.7.5 MASS_7.3-65
[51] tools_4.4.0 vipor_0.4.7 lmtest_0.9-40 beeswarm_0.4.0 httpuv_1.6.15
[56] future.apply_1.11.3 goftest_1.2-3 glue_1.8.0 nlme_3.1-168 promises_1.3.2
[61] grid_4.4.0 Rtsne_0.17 cluster_2.1.8.1 generics_0.1.3 gtable_0.3.6
[66] spatstat.data_3.1-6 tzdb_0.5.0 hms_1.1.3 spatstat.geom_3.3-6 RcppAnnoy_0.0.22
[71] ggrepel_0.9.6 RANN_2.6.2 pillar_1.10.2 spam_2.11-1 RcppHNSW_0.6.0
[76] later_1.4.2 splines_4.4.0 lattice_0.22-7 survival_3.8-3 deldir_2.0-4
[81] tidyselect_1.2.1 miniUI_0.1.1.1 pbapply_1.7-2 gridExtra_2.3 scattermore_1.2
[86] matrixStats_1.5.0 stringi_1.8.7 lazyeval_0.2.2 codetools_0.2-20 cli_3.6.4
[91] uwot_0.2.3 xtable_1.8-4 reticulate_1.42.0 systemfonts_1.2.2 dichromat_2.0-0.1
[96] globals_0.16.3 spatstat.random_3.3-3 png_0.1-8 ggrastr_1.0.2 spatstat.univar_3.1-2
[101] parallel_4.4.0 dotCall64_1.2 listenv_0.9.1 viridisLite_0.4.2 ggridges_0.5.6
[106] crayon_1.5.3 rlang_1.1.5