Skip to content

Commit

Permalink
Merge pull request #658 from satijalab/checkmatrix
Browse files Browse the repository at this point in the history
Add back check.matrix
  • Loading branch information
AustinHartman authored Sep 21, 2022
2 parents 38af263 + ef07a34 commit c53699b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 112 deletions.
4 changes: 1 addition & 3 deletions R/clustering.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,7 @@ PredictAssay <- function(
)
colnames(x = predicted) <- Cells(x = object)
if (return.assay) {
# TODO: restore once check.matrix is implemented in SeuratObject
# predicted.assay <- CreateAssayObject(data = predicted, check.matrix = FALSE)
predicted.assay <- CreateAssayObject(data = predicted)
predicted.assay <- CreateAssayObject(data = predicted, check.matrix = FALSE)
return (predicted.assay)
} else {
return (predicted)
Expand Down
72 changes: 18 additions & 54 deletions R/integration.R
Original file line number Diff line number Diff line change
Expand Up @@ -1461,19 +1461,12 @@ IntegrateData <- function(
} else {
active.assay <- DefaultAssay(object = ref[[1]])
reference.integrated[[active.assay]] <- NULL
# TODO: restore once check.matrix is in SeuratObject
# reference.integrated[[active.assay]] <- CreateAssayObject(
# data = GetAssayData(
# object = reference.integrated[[new.assay.name]],
# slot = 'data'
# ),
# check.matrix = FALSE
# )
reference.integrated[[active.assay]] <- CreateAssayObject(
data = GetAssayData(
object = reference.integrated[[new.assay.name]],
slot = 'data'
)
),
check.matrix = FALSE
)
DefaultAssay(object = reference.integrated) <- active.assay
reference.integrated[[new.assay.name]] <- NULL
Expand All @@ -1496,13 +1489,9 @@ IntegrateData <- function(
)

# Construct final assay object
# TODO: restore once check.matrix is in SeuratObject
# integrated.assay <- CreateAssayObject(
# data = integrated.data,
# check.matrix = FALSE
# )
integrated.assay <- CreateAssayObject(
data = integrated.data
data = integrated.data,
check.matrix = FALSE
)
if (normalization.method == "SCT") {
integrated.assay <- CreateSCTAssayObject(
Expand Down Expand Up @@ -1594,13 +1583,9 @@ IntegrateEmbeddings.IntegrationAnchorSet <- function(
embeddings <- t(x = Embeddings(object = reductions)[cell.names.map[Cells(x = object.list[[i]])], dims.to.integrate])
rownames(x = embeddings) <- dims.names
fake.assay <- suppressWarnings(
# TODO: restore once check.matrix is in SeuratObject
# expr = CreateAssayObject(
# data = embeddings,
# check.matrix = FALSE
# )
expr = CreateAssayObject(
data = embeddings
data = embeddings,
check.matrix = FALSE
)
)
object.list[[i]][['drtointegrate']] <- fake.assay
Expand Down Expand Up @@ -1636,18 +1621,11 @@ IntegrateEmbeddings.IntegrationAnchorSet <- function(
}
active.assay <- DefaultAssay(object = object.list[reference.datasets][[1]])
reference.integrated[[active.assay]] <- NULL
# TODO: restore once check.matrix is in SeuratObject
# reference.integrated[[active.assay]] <- CreateAssayObject(
# data = GetAssayData(
# object = reference.integrated[[new.reduction.name.safe]],
# slot = 'data',
# check.matrix = FALSE
# )
# )
reference.integrated[[active.assay]] <- CreateAssayObject(
data = GetAssayData(
object = reference.integrated[[new.reduction.name.safe]],
slot = 'data'
slot = 'data',
check.matrix = FALSE
)
)
DefaultAssay(object = reference.integrated) <- active.assay
Expand Down Expand Up @@ -1734,13 +1712,9 @@ IntegrateEmbeddings.TransferAnchorSet <- function(
)[ , dims.to.integrate])
rownames(x = embeddings) <- dims.names
fake.assay <- suppressWarnings(
# TODO restore once check.matrix is in SeuratObject
# expr = CreateAssayObject(
# data = embeddings,
# check.matrix = FALSE
# )
expr = CreateAssayObject(
data = embeddings
data = embeddings,
check.matrix = FALSE
)
)
object.list[[i]][['drtointegrate']] <- fake.assay
Expand Down Expand Up @@ -3014,9 +2988,9 @@ TransferData <- function(
stringsAsFactors = FALSE
)
if (prediction.assay || !is.null(x = query)) {
# TODO: restore once check.matrix is in SeuratObject
# predictions <- CreateAssayObject(data = t(x = as.matrix(x = prediction.scores)), check.matrix = FALSE)
predictions <- CreateAssayObject(data = t(x = as.matrix(x = prediction.scores)))
predictions <- CreateAssayObject(
data = t(x = as.matrix(x = prediction.scores)), check.matrix = FALSE
)
Key(object = predictions) <- paste0("predictionscore", rd.name, "_")
}
if (is.null(x = query)) {
Expand All @@ -3040,13 +3014,9 @@ TransferData <- function(
new.data <- as.sparse(x = new.data)
}
if (slot == "counts") {
# TODO: restore once check.matrix is in SeuratObject
# new.assay <- CreateAssayObject(counts = new.data, check.matrix = FALSE)
new.assay <- CreateAssayObject(counts = new.data)
new.assay <- CreateAssayObject(counts = new.data, check.matrix = FALSE)
} else if (slot == "data") {
# TODO: restore once check.matrix is in SeuratObject
# new.assay <- CreateAssayObject(data = new.data, check.matrix = FALSE)
new.assay <- CreateAssayObject(data = new.data)
new.assay <- CreateAssayObject(data = new.data, check.matrix = FALSE)
}
Key(object = new.assay) <- paste0(rd.name, "_")
if (is.null(x = query)) {
Expand Down Expand Up @@ -4096,13 +4066,9 @@ PairwiseIntegrateReference <- function(
features.to.integrate <- features.to.integrate %||% features
if (length(x = reference.objects) == 1) {
ref.obj <- object.list[[reference.objects]]
# TODO: restore once check.matrix is in SeuratObject
# ref.obj[[new.assay.name]] <- CreateAssayObject(
# data = GetAssayData(ref.obj, slot = 'data')[features.to.integrate, ],
# check.matrix = FALSE
# )
ref.obj[[new.assay.name]] <- CreateAssayObject(
data = GetAssayData(ref.obj, slot = 'data')[features.to.integrate, ]
data = GetAssayData(ref.obj, slot = 'data')[features.to.integrate, ],
check.matrix = FALSE
)
DefaultAssay(object = ref.obj) <- new.assay.name
return(ref.obj)
Expand Down Expand Up @@ -4225,9 +4191,7 @@ PairwiseIntegrateReference <- function(
verbose = verbose
)
integrated.matrix <- cbind(integrated.matrix, GetAssayData(object = object.1, slot = 'data')[features.to.integrate, ])
# TODO: restore once check.matrix is in SeuratObject
# merged.obj[[new.assay.name]] <- CreateAssayObject(data = integrated.matrix, check.matrix = FALSE)
merged.obj[[new.assay.name]] <- CreateAssayObject(data = integrated.matrix)
merged.obj[[new.assay.name]] <- CreateAssayObject(data = integrated.matrix, check.matrix = FALSE)
DefaultAssay(object = merged.obj) <- new.assay.name
object.list[[as.character(x = ii)]] <- merged.obj
object.list[[merge.pair[[1]]]] <- NULL
Expand Down
25 changes: 5 additions & 20 deletions R/mixscape.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,11 @@ CalcPerturbSig <- function(
slot(object = object, name = "tools")[[paste("CalcPerturbSig", assay, reduction, sep = ".")]] <- all_neighbors
all_diff <- do.call(what = cbind, args = all_diff)
prtb.assay <- suppressWarnings(
# TODO: restore once check.matrix is in SeuratObject
# expr = CreateAssayObject(
# data = all_diff[, colnames(x = object)],
# min.cells = -Inf,
# min.features = -Inf,
# check.matrix = FALSE
# )
expr = CreateAssayObject(
data = all_diff[, colnames(x = object)],
min.cells = -Inf,
min.features = -Inf
min.features = -Inf,
check.matrix = FALSE
)
)
object[[new.assay.name]] <- prtb.assay
Expand Down Expand Up @@ -1028,7 +1022,7 @@ PlotPerturbScore <- function(
gd <- setdiff(x = unique(x = prtb_score[, target.gene.class]), y = target.gene.ident)
colnames(x = prtb_score)[2] <- "gene"
prtb_score$cell.bc <- sapply(rownames(prtb_score), FUN = function(x) substring(x, regexpr("[.]", x) + 1))

if (isTRUE(x = before.mixscape)) {
cols <- setNames(
object = c("grey49", col),
Expand Down Expand Up @@ -1217,23 +1211,14 @@ GetMissingPerturb <- function(object, assay, features, verbose = TRUE) {
}
all_diff <- do.call(what = cbind, args = all_diff)
all_diff <- all_diff[, colnames(x = object[[assay]]), drop = FALSE]
# TODO: restore once check.matrix is in SeuratObject
# new.assay <- CreateAssayObject(
# data = rbind(
# GetAssayData(object = object[[assay]], slot = "data"),
# all_diff
# ),
# min.cells = 0,
# min.features = 0,
# check.matrix = FALSE
# )
new.assay <- CreateAssayObject(
data = rbind(
GetAssayData(object = object[[assay]], slot = "data"),
all_diff
),
min.cells = 0,
min.features = 0
min.features = 0,
check.matrix = FALSE
)
new.assay <- SetAssayData(
object = new.assay,
Expand Down
8 changes: 2 additions & 6 deletions R/preprocessing.R
Original file line number Diff line number Diff line change
Expand Up @@ -1790,14 +1790,10 @@ SCTransform <- function(
if (verbose) {
message('Place corrected count matrix in counts slot')
}
# TODO: restore once check.matrix is in SeuratObject
# assay.out <- CreateAssayObject(counts = vst.out$umi_corrected, check.matrix = FALSE)
assay.out <- CreateAssayObject(counts = vst.out$umi_corrected,)
assay.out <- CreateAssayObject(counts = vst.out$umi_corrected, check.matrix = FALSE)
vst.out$umi_corrected <- NULL
} else {
# TODO: restore once check.matrix is in SeuratObject
# assay.out <- CreateAssayObject(counts = umi, check.matrix = FALSE)
assay.out <- CreateAssayObject(counts = umi)
assay.out <- CreateAssayObject(counts = umi, check.matrix = FALSE)
}
# set the variable genes
VariableFeatures(object = assay.out) <- residual.features %||% top.features
Expand Down
36 changes: 7 additions & 29 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -1339,18 +1339,11 @@ PseudobulkExpression <- function(
if (slot[1] == 'scale.data') {
na.matrix <- data.return[[1]]
na.matrix[1:length(x = na.matrix)] <- NA
# TODO: restore once check.matrix is in SeuratObject
# toRet <- CreateSeuratObject(
# counts = na.matrix,
# project = if (pb.method == "average") "Average" else "Aggregate",
# assay = names(x = data.return)[1],
# check.matrix = FALSE,
# ...
# )
toRet <- CreateSeuratObject(
counts = na.matrix,
project = if (pb.method == "average") "Average" else "Aggregate",
assay = names(x = data.return)[1],
check.matrix = FALSE,
...
)
toRet <- SetAssayData(
Expand All @@ -1372,18 +1365,11 @@ PseudobulkExpression <- function(
new.data = data.return[[1]]
)
} else {
# TODO: restore once check.matrix is in SeuratObject
# toRet <- CreateSeuratObject(
# counts = data.return[[1]],
# project = if (pb.method == "average") "Average" else "Aggregate",
# assay = names(x = data.return)[1],
# check.matrix = FALSE,
# ...
# )
toRet <- CreateSeuratObject(
counts = data.return[[1]],
project = if (pb.method == "average") "Average" else "Aggregate",
assay = names(x = data.return)[1],
check.matrix = FALSE,
...
)
toRet <- SetAssayData(
Expand All @@ -1399,9 +1385,7 @@ PseudobulkExpression <- function(
if (slot[i] == 'scale.data') {
na.matrix <- data.return[[i]]
na.matrix[1:length(x = na.matrix)] <- NA
# TODO: restore once check.matrix is in SeuratObject
# toRet[[names(x = data.return)[i]]] <- CreateAssayObject(counts = na.matrix, check.matrix = FALSE)
toRet[[names(x = data.return)[i]]] <- CreateAssayObject(counts = na.matrix)
toRet[[names(x = data.return)[i]]] <- CreateAssayObject(counts = na.matrix, check.matrix = FALSE)
toRet <- SetAssayData(
object = toRet,
assay = names(x = data.return)[i],
Expand All @@ -1421,9 +1405,7 @@ PseudobulkExpression <- function(
new.data = as.matrix(x = data.return[[i]])
)
} else {
# TODO: restore once check.matrix is in SeuratObject
# toRet[[names(x = data.return)[i]]] <- CreateAssayObject(counts = data.return[[i]], check.matrix = FALSE)
toRet[[names(x = data.return)[i]]] <- CreateAssayObject(counts = data.return[[i]])
toRet[[names(x = data.return)[i]]] <- CreateAssayObject(counts = data.return[[i]], check.matrix = FALSE)
toRet <- SetAssayData(
object = toRet,
assay = names(x = data.return)[i],
Expand Down Expand Up @@ -1897,13 +1879,9 @@ CreateDummyAssay <- function(assay) {
cm <- as.sparse(x = cm)
rownames(x = cm) <- rownames(x = assay)
colnames(x = cm) <- colnames(x = assay)
# TODO: restore once check.matrix is in SeuratObject
# return(CreateAssayObject(
# counts = cm,
# check.matrix = FALSE
# ))
return(CreateAssayObject(
counts = cm
counts = cm,
check.matrix = FALSE
))
}

Expand Down Expand Up @@ -2336,7 +2314,7 @@ RowSumSparse <- function(mat) {
names(x = output) <- rownames(x = mat)
return(output)
}

# Calculate row variance of a sparse matrix
#
# @param mat sparse matrix
Expand Down

0 comments on commit c53699b

Please sign in to comment.