我遵循在线scTensor教程来分析来自猪的10倍基因组数据。在将“符号”转换为“NCBI ID”之后,我无法创建SingleCellExperiment对象。如果我不做转换,就没有问题了。你能帮我弄清楚吗?谢谢。
R版本3.6.2 scTensor版本1.2.1
pc.data <- Read10X(data.dir = ".\filtered_feature_bc_matrix\")
for_sc <- as.matrix(pc.data)
rowID <- rownames(for_sc)
LefttoRight <- select(org.Ss.eg.db, column=c("SYMBOL", "ENTREZID"), keytype="SYMBOL", keys=rowID)
##'select()' returned 1:many mapping between keys and columns
for_sc <- convertToNCBIGeneID(for_sc, rowID, LefttoRight)
11563 of genes are removed from input matrix (25880*3011),
and only 14317 of genes are kept.
pc <- CreateSeuratObject(counts = for_sc, project = "pc", min.cells = 3, min.features = 200)
pc <- NormalizeData(pc, normalization.method = "LogNormalize", scale.factor = 10000)
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
pc <- data.matrix(pc, rownames.force = NA)
Error in as.vector(data) :
no method for coercing this S4 class to a vector
pc <- as.matrix(GetAssayData(pc, slot = "counts"))
sce <- SingleCellExperiment(assays=list(counts = pc))
Error in validObject(.Object) :
invalid class "SummarizedExperiment" object:
'names(x)' must be NULL or a character vector with no attributes
names(pc)
NULL
sce <- as.SingleCellExperiment(pc)
Error in UseMethod(generic = "as.SingleCellExperiment", object = x) :
no applicable method for 'as.SingleCellExperiment' applied to an object of class "c('matrix', 'double', 'numeric')"发布于 2020-01-31 13:32:11
您有此错误,因为当您映射名称时,它是作为矩阵的行名分配的命名向量。下面试一试:
因此,假设我们有一个如下所示的计数表:
library(SingleCellExperiment)
library(Seurat)
library(org.Ss.eg.db)
set.seed(100)
GENES = sample(keys(org.Ss.eg.db,keytype="SYMBOL"),1000)
counts = matrix(rpois(1000*20,100),ncol=20,nrow=1000)
rownames(counts) = GENES
colnames(counts) = paste0("cell",1:20)
head(counts)我们将行名转换为convert:
ENTREZIDS = mapIds(org.Hs.eg.db,rownames(counts),keytype = "SYMBOL",column = "ENTREZID")
ENTREZIDS = as.character(ENTREZIDS)
table(is.na(ENTREZIDS))
FALSE TRUE
527 473 有时,你的基因不在主语中,这就返回了NA。所以你要么把你的矩阵子集成只有转子基因,然后创建Seurat:
newcounts = counts[!is.na(ENTREZIDS),]
rownames(newcounts) = ENTREZIDS
sboj = CreateSeuratObject(newcounts)
sexpr = SingleCellExperiment(assays=list(counts = newcounts))或者,你留着它们
newcounts = counts
rownames(newcounts) = ENTREZIDS
rownames(newcounts)[is.na(ENTREZIDS)] = rownames(counts)[is.na(ENTREZIDS)]
sboj = CreateSeuratObject(newcounts)
sexpr = SingleCellExperiment(assays=list(counts = newcounts))https://stackoverflow.com/questions/59922402
复制相似问题