ArchR
ArchR copied to clipboard
`addGeneIntegrationMatrix` Error in slot(object = object, name = "features")[[layer]] <- features: more elements supplied than there are to replace Traceback:
When run the tutorial in the document: https://www.archrproject.com/bookdown/cross-platform-linkage-of-scatac-seq-cells-with-scrna-seq-cells.html
projHeme2 <- addGeneIntegrationMatrix(
ArchRProj = projHeme2,
useMatrix = "GeneScoreMatrix",
matrixName = "GeneIntegrationMatrix",
reducedDims = "IterativeLSI",
seRNA = seRNA,
addToArrow = FALSE,
groupRNA = "BioClassification",
nameCell = "predictedCell_Un",
nameGroup = "predictedGroup_Un",
nameScore = "predictedScore_Un"
)
How should I solve this error:
ArchR logging to : ArchRLogs/ArchR-addGeneIntegrationMatrix-3af203550d8-Date-2024-09-30_Time-11-49-57.128984.log
If there is an issue, please report to github with logFile!
2024-09-30 11:49:57.233178 : Running Seurat's Integration Stuart* et al 2019, 0.002 mins elapsed.
2024-09-30 11:49:57.449474 : Checking ATAC Input, 0.005 mins elapsed.
2024-09-30 11:49:58.36637 : Checking RNA Input, 0.021 mins elapsed.
2024-09-30 11:50:14.923285 : Found 18601 overlapping gene names from gene scores and rna matrix!, 0.297 mins elapsed.
2024-09-30 11:50:14.929036 : Creating Integration Blocks, 0.297 mins elapsed.
2024-09-30 11:50:15.271016 : Prepping Interation Data, 0.302 mins elapsed.
2024-09-30 11:50:16.786384 : Computing Integration in 1 Integration Blocks!, 0 mins elapsed.
2024-09-30 11:50:16.799628 : Block (1 of 1) : Computing Integration, 0 mins elapsed.
2024-09-30 11:50:21.25633 : Block (1 of 1) : Identifying Variable Genes, 0.075 mins elapsed.
2024-09-30 11:50:25.130431 : Block (1 of 1) : Getting GeneScoreMatrix, 0.139 mins elapsed.
2024-09-30 11:50:30.740624 : Block (1 of 1) : Imputing GeneScoreMatrix, 0.233 mins elapsed.
Getting ImputeWeights
Warning message:
“Data is of class dgeMatrix. Coercing to dgCMatrix.”
Error in slot(object = object, name = "features")[[layer]] <- features: more elements supplied than there are to replace
Traceback:
1. .safelapply(seq_along(blockList), function(i) {
. prefix <- sprintf("Block (%s of %s) :", i, length(blockList))
. .logDiffTime(sprintf("%s Computing Integration", prefix),
. tstart, verbose = verbose, logFile = logFile)
. blocki <- blockList[[i]]
. subProj@cellColData <- subProj@cellColData[blocki$ATAC, ]
. subProj@sampleColData <- subProj@sampleColData[unique(subProj$Sample),
. , drop = FALSE]
. subRNA <- seuratRNA[, blocki$RNA]
. subRNA <- subRNA[rownames(subRNA) %in% geneDF$name, ]
. .logDiffTime(sprintf("%s Identifying Variable Genes", prefix),
. tstart, verbose = verbose, logFile = logFile)
. subRNA <- FindVariableFeatures(object = subRNA, nfeatures = nGenes,
. verbose = FALSE)
. subRNA <- ScaleData(object = subRNA, verbose = FALSE)
. if (is.null(genesUse)) {
. genesUse <- VariableFeatures(object = subRNA)
. }
. .logDiffTime(sprintf("%s Getting GeneScoreMatrix", prefix),
. tstart, verbose = verbose, logFile = logFile)
. mat <- .getPartialMatrix(getArrowFiles(subProj), featureDF = geneDF[geneDF$name %in%
. genesUse, ], threads = 1, cellNames = subProj$cellNames,
. useMatrix = useMatrix, verbose = FALSE)
. rownames(mat) <- geneDF[geneDF$name %in% genesUse, "name"]
. .logThis(mat, paste0("GeneScoreMat-Block-", i), logFile = logFile)
. if (useImputation) {
. .logDiffTime(sprintf("%s Imputing GeneScoreMatrix", prefix),
. tstart, verbose = verbose, logFile = logFile)
. imputeParams <- list()
. imputeParams$ArchRProj <- subProj
. imputeParams$randomSuffix <- TRUE
. imputeParams$reducedDims <- reducedDims
. imputeParams$dimsToUse <- dimsToUse
. imputeParams$scaleDims <- scaleDims
. imputeParams$corCutOff <- corCutOff
. imputeParams$threads <- 1
. imputeParams$logFile <- logFile
. subProj <- suppressMessages(do.call(addImputeWeights,
. imputeParams))
. mat <- suppressMessages(imputeMatrix(mat = mat, imputeWeights = getImputeWeights(subProj),
. verbose = FALSE, logFile = logFile))
. o <- suppressWarnings(file.remove(unlist(getImputeWeights(subProj)[[1]])))
. .logThis(mat, paste0("GeneScoreMat-Block-Impute-", i),
. logFile = logFile)
. }
. mat <- log(mat + 1)
. seuratATAC <- Seurat::CreateSeuratObject(counts = mat[head(seq_len(nrow(mat)),
. 5), , drop = FALSE])
. seuratATAC[["GeneScore"]] <- Seurat::CreateAssayObject(counts = mat)
. rm(mat)
. DefaultAssay(seuratATAC) <- "GeneScore"
. seuratATAC <- Seurat::ScaleData(seuratATAC, verbose = FALSE)
. .logDiffTime(sprintf("%s Seurat FindTransferAnchors", prefix),
. tstart, verbose = verbose, logFile = logFile)
. transferAnchors <- .retryCatch({
. gc()
. Seurat::FindTransferAnchors(reference = subRNA, query = seuratATAC,
. reduction = reduction, features = genesUse, verbose = FALSE,
. ...)
. }, maxAttempts = 2, logFile = logFile)
. .logThis(paste0(utils::capture.output(transferAnchors), collapse = "\n"),
. paste0("transferAnchors-", i), logFile = logFile)
. rDSub <- rD[colnames(seuratATAC), , drop = FALSE]
. .logThis(rDSub, paste0("rDSub-", i), logFile = logFile)
. transferParams$anchorset <- transferAnchors
. transferParams$weight.reduction <- CreateDimReducObject(embeddings = rDSub,
. key = "LSI_", assay = DefaultAssay(seuratATAC))
. transferParams$verbose <- FALSE
. transferParams$dims <- seq_len(ncol(rDSub))
. .logDiffTime(sprintf("%s Seurat TransferData Cell Group Labels",
. prefix), tstart, verbose = verbose, logFile = logFile)
. transferParams$refdata <- subRNA$Group
. rnaLabels <- do.call(Seurat::TransferData, transferParams)
. .logDiffTime(sprintf("%s Seurat TransferData Cell Names Labels",
. prefix), tstart, verbose = verbose, logFile = logFile)
. transferParams$refdata <- colnames(subRNA)
. rnaLabels2 <- do.call(Seurat::TransferData, transferParams)[,
. 1]
. if (addToArrow) {
. .logDiffTime(sprintf("%s Seurat TransferData GeneMatrix",
. prefix), tstart, verbose = verbose, logFile = logFile)
. transferParams$refdata <- GetAssayData(subRNA, assay = "RNA",
. slot = "data")
. gc()
. matchedRNA <- do.call(Seurat::TransferData, transferParams)
. matchedRNA <- matchedRNA@data
. }
. matchDF <- DataFrame(cellNames = colnames(seuratATAC), predictionScore = rnaLabels$prediction.score.max,
. predictedGroup = rnaLabels$predicted.id, predictedCell = rnaLabels2)
. rownames(matchDF) <- matchDF$cellNames
. .logDiffTime(sprintf("%s Saving TransferAnchors Joint CCA",
. prefix), tstart, verbose = verbose, logFile = logFile)
. jointCCA <- DataFrame([email protected][[1]]@[email protected])
. jointCCA$Assay <- ifelse(endsWith(rownames(jointCCA), "_reference"),
. "RNA", "ATAC")
. jointCCA$Group <- NA
. jointCCA$Score <- NA
. jointCCA[paste0(colnames(subRNA), "_reference"), "Group"] <- subRNA$Group
. jointCCA[paste0(matchDF$cellNames, "_query"), "Group"] <- matchDF$predictedGroup
. jointCCA[paste0(matchDF$cellNames, "_query"), "Score"] <- matchDF$predictionScore
. .safeSaveRDS(object = jointCCA, file = file.path(outDir3,
. paste0("Save-Block", i, "-JointCCA.rds")))
. rm(transferParams, transferAnchors)
. gc()
. if (addToArrow) {
. .logDiffTime(sprintf("%s Transferring Paired RNA to Temp File",
. prefix), tstart, verbose = verbose, logFile = logFile)
. tmpFilei <- paste0(tmpFile, "-IntegrationBlock-", i,
. ".h5")
. o <- h5createFile(tmpFilei)
. sampleNames <- getCellColData(subProj, "Sample")[matchDF$cellNames,
. ]
. uniqueSamples <- unique(sampleNames)
. matchedRNA <- .safeSubset(mat = matchedRNA, subsetRows = paste0(featureDF$name),
. subsetCols = matchDF$cellNames)
. for (z in seq_along(uniqueSamples)) {
. mat <- matchedRNA[, which(sampleNames == uniqueSamples[z]),
. drop = FALSE]
. Group <- uniqueSamples[z]
. o <- tryCatch({
. h5delete(tmpFilei, paste0(Group))
. }, error = function(x) {
. })
. o <- h5createGroup(tmpFilei, paste0(Group))
. j <- Rle(findInterval(seq(mat@x) - 1, mat@p[-1]) +
. 1)
. lengthRle <- length(j@lengths)
. lengthI <- length(mat@i)
. o <- .suppressAll(h5createDataset(tmpFilei, paste0(Group,
. "/i"), storage.mode = "integer", dims = c(lengthI,
. 1), level = 0))
. o <- .suppressAll(h5createDataset(tmpFilei, paste0(Group,
. "/jLengths"), storage.mode = "integer", dims = c(lengthRle,
. 1), level = 0))
. o <- .suppressAll(h5createDataset(tmpFilei, paste0(Group,
. "/jValues"), storage.mode = "integer", dims = c(lengthRle,
. 1), level = 0))
. o <- .suppressAll(h5createDataset(tmpFilei, paste0(Group,
. "/x"), storage.mode = "double", dims = c(lengthI,
. 1), level = 0))
. o <- .suppressAll(h5write(obj = mat@i + 1, file = tmpFilei,
. name = paste0(Group, "/i")))
. o <- .suppressAll(h5write(obj = j@lengths, file = tmpFilei,
. name = paste0(Group, "/jLengths")))
. o <- .suppressAll(h5write(obj = j@values, file = tmpFilei,
. name = paste0(Group, "/jValues")))
. o <- .suppressAll(h5write(obj = mat@x, file = tmpFilei,
. name = paste0(Group, "/x")))
. o <- .suppressAll(h5write(obj = colnames(mat), file = tmpFilei,
. name = paste0(Group, "/cellNames")))
. }
. rm(matchedRNA, mat, j)
. }
. .logDiffTime(sprintf("%s Completed Integration", prefix),
. tstart, verbose = verbose, logFile = logFile)
. gc()
. matchDF$Block <- Rle(i)
. matchDF
. }, threads = threads2) %>% Reduce("rbind", .)
2. Reduce("rbind", .)
3. .safelapply(seq_along(blockList), function(i) {
. prefix <- sprintf("Block (%s of %s) :", i, length(blockList))
. .logDiffTime(sprintf("%s Computing Integration", prefix),
. tstart, verbose = verbose, logFile = logFile)
. blocki <- blockList[[i]]
. subProj@cellColData <- subProj@cellColData[blocki$ATAC, ]
. subProj@sampleColData <- subProj@sampleColData[unique(subProj$Sample),
. , drop = FALSE]
. subRNA <- seuratRNA[, blocki$RNA]
. subRNA <- subRNA[rownames(subRNA) %in% geneDF$name, ]
. .logDiffTime(sprintf("%s Identifying Variable Genes", prefix),
. tstart, verbose = verbose, logFile = logFile)
. subRNA <- FindVariableFeatures(object = subRNA, nfeatures = nGenes,
. verbose = FALSE)
. subRNA <- ScaleData(object = subRNA, verbose = FALSE)
. if (is.null(genesUse)) {
. genesUse <- VariableFeatures(object = subRNA)
. }
. .logDiffTime(sprintf("%s Getting GeneScoreMatrix", prefix),
. tstart, verbose = verbose, logFile = logFile)
. mat <- .getPartialMatrix(getArrowFiles(subProj), featureDF = geneDF[geneDF$name %in%
. genesUse, ], threads = 1, cellNames = subProj$cellNames,
. useMatrix = useMatrix, verbose = FALSE)
. rownames(mat) <- geneDF[geneDF$name %in% genesUse, "name"]
. .logThis(mat, paste0("GeneScoreMat-Block-", i), logFile = logFile)
. if (useImputation) {
. .logDiffTime(sprintf("%s Imputing GeneScoreMatrix", prefix),
. tstart, verbose = verbose, logFile = logFile)
. imputeParams <- list()
. imputeParams$ArchRProj <- subProj
. imputeParams$randomSuffix <- TRUE
. imputeParams$reducedDims <- reducedDims
. imputeParams$dimsToUse <- dimsToUse
. imputeParams$scaleDims <- scaleDims
. imputeParams$corCutOff <- corCutOff
. imputeParams$threads <- 1
. imputeParams$logFile <- logFile
. subProj <- suppressMessages(do.call(addImputeWeights,
. imputeParams))
. mat <- suppressMessages(imputeMatrix(mat = mat, imputeWeights = getImputeWeights(subProj),
. verbose = FALSE, logFile = logFile))
. o <- suppressWarnings(file.remove(unlist(getImputeWeights(subProj)[[1]])))
. .logThis(mat, paste0("GeneScoreMat-Block-Impute-", i),
. logFile = logFile)
. }
. mat <- log(mat + 1)
. seuratATAC <- Seurat::CreateSeuratObject(counts = mat[head(seq_len(nrow(mat)),
. 5), , drop = FALSE])
. seuratATAC[["GeneScore"]] <- Seurat::CreateAssayObject(counts = mat)
. rm(mat)
. DefaultAssay(seuratATAC) <- "GeneScore"
. seuratATAC <- Seurat::ScaleData(seuratATAC, verbose = FALSE)
. .logDiffTime(sprintf("%s Seurat FindTransferAnchors", prefix),
. tstart, verbose = verbose, logFile = logFile)
. transferAnchors <- .retryCatch({
. gc()
. Seurat::FindTransferAnchors(reference = subRNA, query = seuratATAC,
. reduction = reduction, features = genesUse, verbose = FALSE,
. ...)
. }, maxAttempts = 2, logFile = logFile)
. .logThis(paste0(utils::capture.output(transferAnchors), collapse = "\n"),
. paste0("transferAnchors-", i), logFile = logFile)
. rDSub <- rD[colnames(seuratATAC), , drop = FALSE]
. .logThis(rDSub, paste0("rDSub-", i), logFile = logFile)
. transferParams$anchorset <- transferAnchors
. transferParams$weight.reduction <- CreateDimReducObject(embeddings = rDSub,
. key = "LSI_", assay = DefaultAssay(seuratATAC))
. transferParams$verbose <- FALSE
. transferParams$dims <- seq_len(ncol(rDSub))
. .logDiffTime(sprintf("%s Seurat TransferData Cell Group Labels",
. prefix), tstart, verbose = verbose, logFile = logFile)
. transferParams$refdata <- subRNA$Group
. rnaLabels <- do.call(Seurat::TransferData, transferParams)
. .logDiffTime(sprintf("%s Seurat TransferData Cell Names Labels",
. prefix), tstart, verbose = verbose, logFile = logFile)
. transferParams$refdata <- colnames(subRNA)
. rnaLabels2 <- do.call(Seurat::TransferData, transferParams)[,
. 1]
. if (addToArrow) {
. .logDiffTime(sprintf("%s Seurat TransferData GeneMatrix",
. prefix), tstart, verbose = verbose, logFile = logFile)
. transferParams$refdata <- GetAssayData(subRNA, assay = "RNA",
. slot = "data")
. gc()
. matchedRNA <- do.call(Seurat::TransferData, transferParams)
. matchedRNA <- matchedRNA@data
. }
. matchDF <- DataFrame(cellNames = colnames(seuratATAC), predictionScore = rnaLabels$prediction.score.max,
. predictedGroup = rnaLabels$predicted.id, predictedCell = rnaLabels2)
. rownames(matchDF) <- matchDF$cellNames
. .logDiffTime(sprintf("%s Saving TransferAnchors Joint CCA",
. prefix), tstart, verbose = verbose, logFile = logFile)
. jointCCA <- DataFrame([email protected][[1]]@[email protected])
. jointCCA$Assay <- ifelse(endsWith(rownames(jointCCA), "_reference"),
. "RNA", "ATAC")
. jointCCA$Group <- NA
. jointCCA$Score <- NA
. jointCCA[paste0(colnames(subRNA), "_reference"), "Group"] <- subRNA$Group
. jointCCA[paste0(matchDF$cellNames, "_query"), "Group"] <- matchDF$predictedGroup
. jointCCA[paste0(matchDF$cellNames, "_query"), "Score"] <- matchDF$predictionScore
. .safeSaveRDS(object = jointCCA, file = file.path(outDir3,
. paste0("Save-Block", i, "-JointCCA.rds")))
. rm(transferParams, transferAnchors)
. gc()
. if (addToArrow) {
. .logDiffTime(sprintf("%s Transferring Paired RNA to Temp File",
. prefix), tstart, verbose = verbose, logFile = logFile)
. tmpFilei <- paste0(tmpFile, "-IntegrationBlock-", i,
. ".h5")
. o <- h5createFile(tmpFilei)
. sampleNames <- getCellColData(subProj, "Sample")[matchDF$cellNames,
. ]
. uniqueSamples <- unique(sampleNames)
. matchedRNA <- .safeSubset(mat = matchedRNA, subsetRows = paste0(featureDF$name),
. subsetCols = matchDF$cellNames)
. for (z in seq_along(uniqueSamples)) {
. mat <- matchedRNA[, which(sampleNames == uniqueSamples[z]),
. drop = FALSE]
. Group <- uniqueSamples[z]
. o <- tryCatch({
. h5delete(tmpFilei, paste0(Group))
. }, error = function(x) {
. })
. o <- h5createGroup(tmpFilei, paste0(Group))
. j <- Rle(findInterval(seq(mat@x) - 1, mat@p[-1]) +
. 1)
. lengthRle <- length(j@lengths)
. lengthI <- length(mat@i)
. o <- .suppressAll(h5createDataset(tmpFilei, paste0(Group,
. "/i"), storage.mode = "integer", dims = c(lengthI,
. 1), level = 0))
. o <- .suppressAll(h5createDataset(tmpFilei, paste0(Group,
. "/jLengths"), storage.mode = "integer", dims = c(lengthRle,
. 1), level = 0))
. o <- .suppressAll(h5createDataset(tmpFilei, paste0(Group,
. "/jValues"), storage.mode = "integer", dims = c(lengthRle,
. 1), level = 0))
. o <- .suppressAll(h5createDataset(tmpFilei, paste0(Group,
. "/x"), storage.mode = "double", dims = c(lengthI,
. 1), level = 0))
. o <- .suppressAll(h5write(obj = mat@i + 1, file = tmpFilei,
. name = paste0(Group, "/i")))
. o <- .suppressAll(h5write(obj = j@lengths, file = tmpFilei,
. name = paste0(Group, "/jLengths")))
. o <- .suppressAll(h5write(obj = j@values, file = tmpFilei,
. name = paste0(Group, "/jValues")))
. o <- .suppressAll(h5write(obj = mat@x, file = tmpFilei,
. name = paste0(Group, "/x")))
. o <- .suppressAll(h5write(obj = colnames(mat), file = tmpFilei,
. name = paste0(Group, "/cellNames")))
. }
. rm(matchedRNA, mat, j)
. }
. .logDiffTime(sprintf("%s Completed Integration", prefix),
. tstart, verbose = verbose, logFile = logFile)
. gc()
. matchDF$Block <- Rle(i)
. matchDF
. }, threads = threads2)
4. mclapply(..., mc.cores = threads, mc.preschedule = preschedule)
5. lapply(X = X, FUN = FUN, ...)
6. FUN(X[[i]], ...)
7. Seurat::CreateSeuratObject(counts = mat[head(seq_len(nrow(mat)),
. 5), , drop = FALSE])
8. CreateSeuratObject.default(counts = mat[head(seq_len(nrow(mat)),
. 5), , drop = FALSE])
9. CreateAssay5Object(counts = counts, min.cells = min.cells, min.features = min.features,
. ...)
10. .CreateStdAssay(counts = counts, min.cells = min.cells, min.features = min.features,
. transpose = transpose, type = type, csum = csum, fsum = fsum,
. ...)
11. .CreateStdAssay.list(counts = counts, min.cells = min.cells,
. min.features = min.features, transpose = transpose, type = type,
. csum = csum, fsum = fsum, ...)
12. `LayerData<-`(object = `*tmp*`, layer = layer, features = features[[layer]],
. cells = cells[[layer]], transpose = transpose, value = counts[[layer]])
13. `LayerData<-.Assay5`(object = `*tmp*`, layer = layer, features = features[[layer]],
. cells = cells[[layer]], transpose = transpose, value = counts[[layer]])
14. .handleSimpleError(function (cnd)
. {
. watcher$capture_plot_and_output()
. cnd <- sanitize_call(cnd)
. watcher$push(cnd)
. switch(on_error, continue = invokeRestart("eval_continue"),
. stop = invokeRestart("eval_stop"), error = invokeRestart("eval_error",
. cnd))
. }, "more elements supplied than there are to replace", base::quote(slot(object = object,
. name = "features")[[layer]] <- features))
Thanks a lot