Skip to content

Commit

Permalink
fix for multi-sct merges
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewwbutler committed Feb 18, 2020
1 parent 6828853 commit d489b48
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions R/objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -5667,19 +5667,24 @@ merge.Assay <- function(
if (all(IsSCT(assay = assays))) {
vst.set.new <- list()
idx <- 1
umi.assay.new <- list()
for (i in 1:length(x = assays)) {
vst.set.old <- Misc(object = assays[[i]], slot = "vst.set")
umi.assay.old <- Misc(object = assays[[i]], slot = "umi.assay")
if (!is.null(x = vst.set.old)) {
for (j in 1:length(x = vst.set.old)) {
vst.set.new[[idx]] <- vst.set.old[[j]]
umi.assay.new[[idx]] <- umi.assay.old[[j]]
idx <- idx + 1
}
} else if (!is.null(x = Misc(object = assays[[i]], slot = "vst.out"))) {
vst.set.new[[idx]] <- Misc(object = assays[[i]], slot = "vst.out")
umi.assay.new[[idx]] <- Misc(object = assays[[i]], slot = "umi.assay")
idx <- idx + 1
}
}
Misc(object = combined.assay, slot = "vst.set") <- vst.set.new
Misc(object = combined.assay, slot = "umi.assay") <- umi.assay.new
scale.data <- do.call(
what = cbind,
args = lapply(X = assays, FUN = function(x) GetAssayData(object = x, slot = "scale.data"))
Expand Down
7 changes: 5 additions & 2 deletions R/preprocessing.R
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,16 @@ GetResidual <- function(
object,
features,
assay = "SCT",
umi.assay = "RNA",
umi.assay = NULL,
clip.range = NULL,
replace.value = FALSE,
verbose = TRUE
) {
if (!IsSCT(assay = object[[assay]])) {
stop(assay, " assay was not generated by SCTransform")
}
umi.assay <- umi.assay %||% Misc(object = object[[assay]], slot = "umi.assay")
umi.assay <- umi.assay %||% "RNA" # for object created in 3.1.1 or earlier, default to RNA
if (replace.value) {
new_features <- features
} else {
Expand Down Expand Up @@ -534,7 +536,7 @@ GetResidual <- function(
object.v <- GetResidualVstOut(
object = object.v,
assay = assay,
umi.assay = umi.assay,
umi.assay = umi.assay[[v]],
new_features = new_features,
vst_out = vst_out,
clip.range = clip.range,
Expand Down Expand Up @@ -1353,6 +1355,7 @@ SCTransform <- function(
# save clip.range into vst model
vst.out$arguments$sct.clip.range <- clip.range
Misc(object = assay.out, slot = 'vst.out') <- vst.out
Misc(object = assay.out, slot = 'umi.assay') <- assay
# also put gene attributes in meta.features
assay.out[[paste0('sct.', names(x = vst.out$gene_attr))]] <- vst.out$gene_attr
assay.out[['sct.variable']] <- rownames(x = assay.out[[]]) %in% top.features
Expand Down
2 changes: 1 addition & 1 deletion man/GetResidual.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d489b48

Please sign in to comment.