Skip to content

Commit

Permalink
Merge pull request satijalab#42 from satijalab/integration-bugfix
Browse files Browse the repository at this point in the history
Fix error when using projected loadings
  • Loading branch information
mojaveazure authored Apr 10, 2019
2 parents 1a36031 + ad5a94f commit d9bffe5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions R/dimensional_reduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ L2Dim <- function(object, reduction, new.dr = NULL, new.key = NULL){
colnames(x = l2.norm) <- paste0(new.key, 1:ncol(x = l2.norm))
l2.dr <- CreateDimReducObject(
embeddings = l2.norm,
loadings = Loadings(object = object[[reduction]]),
projected = Loadings(object = object[[reduction]]),
loadings = Loadings(object = object[[reduction]], projected = FALSE),
projected = Loadings(object = object[[reduction]], projected = TRUE),
assay = DefaultAssay(object = object),
stdev = slot(object = object[[reduction]], name = 'stdev'),
key = new.key,
Expand Down
18 changes: 14 additions & 4 deletions R/integration.R
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ FindTransferAnchors <- function(
if (!reduction %in% c("pcaproject", "cca", "pcaqueryproject")) {
stop("Please select either pcaproject, cca, or pcaqueryproject for the reduction parameter.")
}
if (reduction %in% c('pcaproject', 'pcaqueryproject')) {
projected = TRUE
} else {
projected = FALSE
}
query <- RenameCells(
object = query,
new.names = paste0(Cells(x = query), "_", "query")
Expand Down Expand Up @@ -326,6 +331,7 @@ FindTransferAnchors <- function(
k.score = k.score,
max.features = max.features,
eps = eps,
projected = projected,
verbose = verbose
)
command <- LogSeuratCommand(object = combined.ob, return.command = TRUE)
Expand Down Expand Up @@ -1249,6 +1255,7 @@ FindAnchors <- function(
k.score = 30,
max.features = 200,
eps = 0,
projected = FALSE,
verbose = TRUE
) {
# compute local neighborhoods, use max of k.anchor and k.score if also scoring to avoid
Expand Down Expand Up @@ -1279,7 +1286,8 @@ FindAnchors <- function(
reduction = reduction,
dims = dims,
features.per.dim = 100,
max.features = max.features
max.features = max.features,
projected = projected
)
object.pair <- FilterAnchors(
object = object.pair,
Expand Down Expand Up @@ -1797,24 +1805,26 @@ ScoreAnchors <- function(
# @param dims Which dimensions to use
# @param features.per.dim How many features to consider per dimension
# @param max.features Number of features to return at most
# @param projected Use projected loadings
#
TopDimFeatures <- function(
object,
reduction,
dims = 1:10,
features.per.dim = 100,
max.features = 200
max.features = 200,
projected = FALSE
) {
dim.reduction <- object[[reduction]]
max.features <- max(length(x = dims) * 2, max.features)
num.features <- sapply(X = 1:features.per.dim, FUN = function(y) {
length(x = unique(x = as.vector(x = sapply(X = dims, FUN = function(x) {
unlist(x = TopFeatures(object = dim.reduction, dim = x, nfeatures = y, balanced = TRUE))
unlist(x = TopFeatures(object = dim.reduction, dim = x, nfeatures = y, balanced = TRUE, projected = projected))
}))))
})
max.per.pc <- which.max(x = num.features[num.features < max.features])
features <- unique(x = as.vector(x = sapply(X = dims, FUN = function(x) {
unlist(x = TopFeatures(object = dim.reduction, dim = x, nfeatures = max.per.pc, balanced = TRUE))
unlist(x = TopFeatures(object = dim.reduction, dim = x, nfeatures = max.per.pc, balanced = TRUE, projected = projected))
})))
features <- unique(x = features)
return(features)
Expand Down

0 comments on commit d9bffe5

Please sign in to comment.