Skip to content

Commit

Permalink
fix issue with for liana_tensor
Browse files Browse the repository at this point in the history
  • Loading branch information
dbdimitrov committed Feb 6, 2023
1 parent 9ee9903 commit 10d8177
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion R/liana_tensor.R
Expand Up @@ -322,7 +322,8 @@ get_c2c_factors <- function(sce, group_col=NULL, sample_col){
factors$contexts <- .join_meta(sce,
factors$contexts,
sample_col = sample_col,
group_col = group_col)
group_col = group_col,
.left_col="context")
return(factors)

}
Expand Down
15 changes: 12 additions & 3 deletions R/liana_utils.R
Expand Up @@ -67,20 +67,29 @@ liana_bysample <- function(sce,

#' Join sample descriptor column from SCE to another table
#' @param sce SingleCellExperiment
#' @param right (df) to join to colData per sample
#' @param left (df) to join to colData per sample
#' @param sample_col unique identifier column from colData
#' @param group_col sample_col descriptor column
#' @param .left_col The columns by which we map `sample_col` if NULL, its set to
#' the same as `sample_col`.
#'
#' @noRd
.join_meta <- function(sce, right, sample_col, group_col){
.join_meta <- function(sce, left, sample_col, group_col, .left_col=NULL){

if(is.null(.left_col)){
.left_col <- sample_col
}

meta <- colData(sce) %>%
as_tibble() %>%
dplyr::select(!!sample_col, !!group_col) %>%
distinct() %>%
mutate( {{ group_col }} := as.factor(.data[[group_col]]))

left_join(right, meta, by=sample_col)
by <- sample_col
names(by) <- .left_col

left_join(left, meta, by=by)
}


Expand Down

0 comments on commit 10d8177

Please sign in to comment.