bug千千萬,改完又忘,忘了又出……
記錄在Seurat分析中各種各樣的花式bug們????
1. FindVariableFeatures()報錯
Error: Cannot add more or fewer meta.features information without values being named with feature names
這個是RNA這個assays下面meta.features的名字里面有NA值,我推測是我在修改基因名或者是取子集的時候導致的bug,正常不會遇到,所以只要重新指定一下就好
data[["RNA"]]@meta.features <- data.frame(row.names = rownames(data[["RNA"]]))
參見 https://github.com/satijalab/seurat/issues/2317
當然,核心問題還是矩陣命名的問題導致的,想辦法把基因名重新命名就好了,不能有一些特殊符號,例如‘-’之類的(github垃圾 都沒有具體解決方法)
2. FeaturePlot() 顯示不是很明顯
這個問題其實不算一個bug(你用錯了assay導致的彌散另說),其實是需要手動處理一下,把上下限的極值去除掉
If there are expression outliers in the FeaturePlot this can sometimes make it hard to visualize the full range of expression. You can set the min.cutoff and max.cutoff values in FeaturePlot to change the minimum and maximum values displayed. You can set this to a quantile by using for example “q5” for the lower 5%.
3.整合報錯
Finding integration vector weights
Error in Embeddings(reduction)[nn.cells2, dims] : subscript out of bounds
這個意思基本就是一個整合要用到的anchor都沒找到
至于為啥會這樣呢?大概率是交集的基因沒有(就是基因名不對應),例如一個是小鼠的(Gad1)一個對象是人類的基因(GAD1),這就不對應,把小鼠的所有基因名轉為人的同源基因名再整合就可以了。
4. SplitObject報錯
Error: No cells found
檢查:
- metadata的行名是不是和Seurat object的列名一致(一般都是這個原因,基本上就出現在自己手動構建的對象里面,按正常的方式構建的對象不會有這個問題)
解決:rownames(data@meta.data)=colnames(data) - 檢查對象/metadata里面有沒有NA
5. SCTranform()報錯
報錯是這樣子的
Error in .GetSeuratCompat() : could not find function ".GetSeuratCompat"
主要是因為版本問題,GetSeuratCompat是SeuratObject V5的函數,如果用對應的V5 Seurat和SeuratObject是沒有問題的。但是我用的是SeuratV4+SeuratObjectV5所以會出現這個問題。解決辦法就是卸SeuratObject V5,重裝SeuratObject V4。
if (!requireNamespace("remotes", quietly = TRUE)) {
install.packages("remotes")
}
options(repos = c("https://satijalab.r-universe.dev", getOption("repos")))
remotes::install_version("SeuratObject", "4.1.4")
remotes::install_version("Seurat", "4.4.0", upgrade = FALSE) # remotes will try to upgrade SeuratObject to v5, we need to tell it no
最佳版本配方是:sctransform 0.4.0, seurat 4.4.0, seuratobject 4.1.4
不過實際上是,其實我的R里面版本是沒問題的(即,SeuratObject 是4.1.4),但是還是報錯了。結果我發(fā)現我的conda list下面SeuratObject是5.0,在R里面用remove.package()是刪不掉的。所以必須在conda里面強制刪除conda remove r-seuratobject --force。這個--force是必須的,因為如果不加,conda下面所有依賴seuratobject的包都會被刪個干凈。
然后用上面的辦法重裝,或者直接用CRAN指定版本重裝seuratobject v4也行,如下:
install.packages('https://cran.r-project.org/src/contrib/Archive/SeuratObject/SeuratObject_4.1.4.tar.gz',repos=NULL, type = 'source')
同bug可以參考github上的討論:https://github.com/satijalab/seurat-object/issues/165
最后實測,還是得Seurat V4/V5 + SeuratObject V5, 上面說SeuratObject V4可以都是假的 要么就是Seurat的版本還得再降低??
6. 找不到細胞
# 1.
Error in `fn()`: ! Cannot add new cells with [[<-
# 2.
Error in validObject(object = .Object) : invalid class “Seurat” object: all cells in assays must be present in the Seurat object
這些報錯會出現在各個分析環(huán)節(jié),包括最開始的NormalizationData等等。
主要原因是前面要么重構對象,要么手動修改了結構里面的一些部分,然后導致,一旦對對象取了子集(例如 刪除或者是subset了)就會開始報錯。
主要是原因就是因為data@assays$RNA@cells沒法跟著你取子集的操作自動開始執(zhí)行,然后就導致了它里面存儲的細胞數目和counts/data/scale.data里面的不一樣,所以手動調整一下就搞定了。
data@assays$RNA@cells=data@assays$RNA@cells[colnames(data),]
但后面再取子集還是一樣的,得手動調整,所以我建議還是干脆全面重構得了:
data_new <- CreateSeuratObject(data[['RNA']]$counts,meta.data = data@meta.data)
data_new@graphs <- data@graphs
data_new@reductions <- data@reductions # 把原本的其它降維都拿過來 就不用重復做了
data_new@commands <- data@commands
data=data_new
rm(data_new);gc() #釋放內存
持續(xù)更新……