@@ -749,7 +749,7 @@ could.be.connectivity.Matrix <- function(object, check.symmetry = T) {
749749# ' @importFrom methods slot
750750# ' @keywords internal
751751# ' @noRd
752- # ########### Copy-paste
752+ # ########### Adpated from
753753# https://github.com/satijalab/seurat/blob/1549dcb3075eaeac01c925c4b4bb73c73450fc50/R/integration5.R#L659-L677
754754CreateIntegrationGroups <- function (object , layers , scale.layer ) {
755755 groups <- if (inherits(x = object , what = ' SCTAssay' )) {
@@ -762,10 +762,18 @@ CreateIntegrationGroups <- function(object, layers, scale.layer) {
762762 df
763763 } else if (length(x = layers ) > 1L ) {
764764 cmap <- slot(object = object , name = ' cells' )[, layers ]
765- as.data.frame(x = labels(
766- object = cmap ,
767- values = Cells(x = object , layer = scale.layer )
768- ))
765+ n_layers_per_cell <- rowSums(cmap )
766+ if (all(n_layers_per_cell < 2 )) {
767+ cmap <- as.matrix(cmap )[n_layers_per_cell == 1 , ] # drop cell when rowsum is 0
768+ intmap <- cmap %*% matrix (seq_along(layers ), ncol = 1 )
769+ intmap <- intmap [match(Cells(x = object , layer = scale.layer ), rownames(intmap ), nomatch = 0 ), 1 , drop = TRUE ]
770+ setNames(as.data.frame(setNames(layers [intmap ], names(intmap ))), " group" )
771+ } else {
772+ as.data.frame(x = labels(
773+ object = cmap ,
774+ values = Cells(x = object , layer = scale.layer )
775+ ))
776+ }
769777 }
770778 names(x = groups ) <- ' group'
771779 return (groups )
0 commit comments