Dear All fellows,
I'm using SCTtransform to normalize data and try to run various resolutions to determine which one is good for clustering. However, once it comes to for loop sections, it shows me the clustering plot of resolution 0, but the rest was terminated with error saying that Error: Not an S4 object. Not sure anyone could have a look at my script and give some suggestions. I read the error description, but it was beyond what I could understand.
#Set the bar!
Filtered.cells <- subset(Arthritis.merge, subset = nFeature_RNA >500
& nFeature_RNA <5500 & nCount_RNA>800 & nCount_RNA <39000 & percent.mt < 10)
#SCTransform
seuraobj<- SCTransform(Filtered.cells, vars.to.regress = "percent.mt", verbose = FALSE)
#Determine # of PCs
seuraobj<- RunPCA(seuraobj, seed.use = 12345, verbose = FALSE)
#Integration
library(harmony)
set.seed(12345)
seuraobj<- RunHarmony(seuraobj ,group.by.vars = "orig.ident")
seuraobj<- FindNeighbors(seuraobj, reduction = "harmony", dims = 1:30, verbose = FALSE)
#Testing various resolution
# Create a directory to save the plots
dir.create("resolution_plots", showWarnings = FALSE)
#Iterate through the resolutions and create plots
for(res in c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1)) {
seuraobj<- FindClusters(seuraobj, random.seed = 12345, verbose = FALSE, resolution = res)
seuraobj<- RunUMAP(seuraobj, dims = 1:30, reduction = "harmony", verbose = FALSE)
#plot umaps
seuraobj<- DimPlot(seuraobj, reduction= "umap",label = TRUE, label.size = 3, plot.title=paste0('res', res)) +
theme_minimal() +
NoLegend()
#Display plots
print( seuraobj)
#Save plots
ggsave(filename = paste0("resolution_plots/plot_resolution_", res, ".png"), plot = seuraobj)
Error: Not an S4 object.
Thank you brother for your help. Since you are an expert, I would like to ask another question. Hope you do not mind me.
I am trying to test different values of min.dist and trying to test your code, but I got error again. I did not have a sequence of value this time and some number are random. Therefore, I replaced sth like this
I got error at
group.by
. Not sure if you could kindly check it for me.Thanks in advance