Open alosdiallo opened 1 month ago
Here is the updated function that should be compatible:
STPreProcess_mod <- function(InDir = InDir, Sample = Sample, OutDir = NULL) {
if (is.null(OutDir) == TRUE) {
OutDir <- paste(getwd(), "/", Sample, "/", sep = "")
dir.create(OutDir)
}
# read files------
aa_try <- try(
Xdata <- Seurat::Read10X(data.dir = paste(InDir, "filtered_feature_bc_matrix", sep = "")),
silent = T
)
if (is(aa_try, "try-error")) {
Xdata <- Seurat::Read10X_h5(filename = paste(InDir, "filtered_feature_bc_matrix.h5", sep = ""))
} else {
Xdata <- Xdata
}
# Modify the line below by removing 'min.spots = 0'
XF <- CreateSeuratObject(counts = Xdata, project = Sample, assay = "Spatial")
# ... rest of the function remains the same
# read image files
Ximage <- Read10X_Image(image.dir = paste(InDir, "spatial", sep = ""))
Seurat::DefaultAssay(Ximage) <- "Spatial"
Ximage <- Ximage[colnames(XF)]
XF[["image"]] <- Ximage
TumorST <- XF
# QC----
dir.create(paste(OutDir, "QC", sep = ""))
TumorST[["Mito.percent"]] <- PercentageFeatureSet(TumorST, pattern = "^MT-")
pdf(paste(OutDir, "QC/Vlnplot.pdf", sep = ""), width = 6, height = 4)
p <- VlnPlot(TumorST, features = c("nFeature_Spatial", "nCount_Spatial", "Mito.percent"), pt.size = 0, combine = F)
for (i in 1:length(p)) {
p[[i]] <- p[[i]] + NoLegend() + theme(axis.title.x = element_blank(), axis.text.x = element_text(angle = 0))
}
p <- cowplot::plot_grid(plotlist = p, ncol = 3)
print(p)
dev.off()
pdf(paste(OutDir, "QC/featurplot.pdf", sep = ""), width = 7, height = 7)
p <- SpatialFeaturePlot(TumorST, features = c("nFeature_Spatial", "nCount_Spatial", "Mito.percent"), combine = F)
for (i in 1:length(p)) {
p[[i]] <- p[[i]] + theme(axis.title.x = element_blank(), axis.text.x = element_text(angle = 0))
}
print(cowplot::plot_grid(plotlist = p, ncol = 3))
dev.off()
QCData <- TumorST@meta.data[, c("nCount_Spatial", "nFeature_Spatial", "Mito.percent")]
openxlsx::write.xlsx(QCData, paste(OutDir, "QC/QCData.xlsx", sep = ""), overwrite = T)
return(TumorST)
}
When I run
STPreProcess(InDir = InDir, OutDir = OutDir, Sample = Sample)
It throws the following error:
Looking at the code for the STPreProcess function we can see:
XF <- CreateSeuratObject(counts = Xdata, project = Sample, min.spots = 0, assay = "Spatial")
CreateSeuratObject Function Call: CreateSeuratObject passing min.spots = 0 as an argument. In Seurat version 5.x, the CreateSeuratObject function does not have a min.spots parameter. The function expects parameters like min.cells and min.features.Is there a workaround that you have?