Skip to content

Commit

Permalink
address #75, #99, bump cell2cell, fix edgecase
Browse files Browse the repository at this point in the history
  • Loading branch information
dbdimitrov committed Nov 3, 2023
1 parent 86adaca commit 4c323df
Show file tree
Hide file tree
Showing 25 changed files with 37 additions and 61 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
@@ -1,7 +1,7 @@
Package: liana
Type: Package
Title: LIANA: a LIgand-receptor ANalysis frAmework
Version: 0.1.12
Version: 0.1.13
Authors@R: c(
person(
given = "Daniel",
Expand Down Expand Up @@ -91,5 +91,5 @@ Suggests:
broom
biocViews: scater, scran, SingleCellExperiment, ComplexHeatmap, muscData, ExperimentHub
Remotes: sqjin/CellChat, saezlab/OmnipathR, saezlab/decoupleR, LTLA/basilisk.utils, LTLA/basilisk
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
Config/testthat/edition: 3
18 changes: 15 additions & 3 deletions NEWS.md
@@ -1,4 +1,16 @@
# LIANA 0.1.12 (24.02.22)
# LIANA 0.1.13 (03.11.23)

- Changed the way that `max` rank is imputed when NAs are presented, or when `return_all` is true.
Essentially, `RobustRankAggregate` will use the max rank in the matrix, rather than the size of the dataframe.

- Fixed a bug related to newer versions of CellChat with unused argument #75

- Bumped `cell2cell` to its latest `0.6.8` version.

- LIANA's `source` and `target` will not inherit the levels of `idents_col` #99


# LIANA 0.1.12 (24.02.23)

- Added `rank_aggregate` to generate both specificity and magnitude rank
aggregates. Essentially runs `liana_aggregate` twice with different `aggregate_how`
Expand All @@ -14,7 +26,7 @@ scores to Tensor format.
- Added additional tests related to Tensor-cell2cell


# LIANA 0.1.11 (06.02.22)
# LIANA 0.1.11 (06.02.23)

- Fixed issue with sample_col in `liana_tensor` functions
- Removed redundant scconnect code
Expand All @@ -23,7 +35,7 @@ scores to Tensor format.
- passing "all" to `select_resource` will now only return human resources.
- add minor condition improvements to `liana_wrap` PR#92

# LIANA 0.1.10 (23.01.22)
# LIANA 0.1.10 (23.01.23)

- Fixed issues in the `generate_lr_geneset` function, and other typos and
by mistake hardcoded values.
Expand Down
1 change: 0 additions & 1 deletion R/cellchat_pipe.R
Expand Up @@ -120,7 +120,6 @@ call_cellchat <- function(sce,
cellchat.omni <- CellChat::computeCommunProb(cellchat.omni,
raw.use = .raw_use,
seed.use = .seed,
do.fast = TRUE,
nboot = nboot)

# Filter out the cell-cell communication if there are only few number of cells in certain cell groups
Expand Down
61 changes: 11 additions & 50 deletions R/liana_aggregate.R
Expand Up @@ -276,71 +276,32 @@ rank_aggregate <- function(liana_res, ...){
.aggregate_rank <- function(liana_mlist, join_cols, verbose, ...){
liana_message("Aggregating Ranks", output = "message", verbose = verbose)

liana_mlist %>%
rankmat <- liana_mlist %>%
map(function(res){
# bad practice, but almost unavoidable here...
res %>%
unite(join_cols,
col = "interaction",
sep = "") %>%
pull("interaction")
select(interaction, ends_with("rank"))
}) %>%
.rank_matrix %>%
reduce(full_join, by="interaction") %>%
column_to_rownames(var = "interaction") %>%
as.matrix()

rankmat[is.na(rankmat)] <- max(rankmat, na.rm=TRUE)

rankmat %>%
{. / max(.)} %>%
.robust_rank_agg(.,
...) %>%
separate(col = "interaction", sep = "",
into = join_cols)
}



#' Function to convert a list of characters to a ranked matrix [0,1]
#'
#' @param glist a list of ranked/ordered characters
#'
#' @return a matrix filled with 0-1 values depending on the position order
#' of the characters.
#'
#' @details Adated from Kolde et al., 2012.
#' Required due to the removal of the RobustRankAggregate package from CRAN.
#'
#' @references Kolde, R., Laur, S., Adler, P. and Vilo, J., 2012.
#' Robust rank aggregation for gene list integration and meta-analysis.
#' Bioinformatics, 28(4), pp.573-580.
#'
#' @keywords internal
.rank_matrix <- function(glist, ...){

# Get unique entities
u.ents <- unique(c(glist, recursive = TRUE))

# num of entities per col
num.ents <- length(u.ents)

# get position for each vect
pos.mat <- sapply(FUN = match,
X = glist,
x = u.ents,
nomatch = num.ents) %>%
matrix(nrow = num.ents,
ncol = length(glist),
dimnames = list(u.ents, names(glist)))

# Fill mat /w total ents
rank.mat <- matrix(num.ents,
nrow = num.ents,
ncol = length(glist),
dimnames = list(u.ents, names(glist)))

# return rank/total_rank by pos
return(pos.mat / rank.mat)

}


#' Function to calculate and format aggregate ranks
#'
#' @param rmat ranked matrix formated with `.rank_matrix`
#' @param rmat a ranked matrix [0,1]
#'
#' @details Adated from Kolde et al., 2012.
#' Required due to the removal of the RobustRankAggregate package from CRAN.
Expand Down
5 changes: 4 additions & 1 deletion R/liana_pipe.R
Expand Up @@ -196,7 +196,6 @@ liana_pipe <- function(sce,
.sp_costrain(cell.adj)
}


# Join complexes (recomplexify) to lr_res
cmplx <- op_resource %>%
select(
Expand All @@ -211,6 +210,10 @@ liana_pipe <- function(sce,
by=c("ligand", "receptor")) %>%
distinct()

# Inherit levels of idents
levels(lr_res$source) <- levels(colLabels(sce))
levels(lr_res$target) <- levels(colLabels(sce))

return(lr_res)
}

Expand Down
2 changes: 1 addition & 1 deletion R/liana_tensor.R
Expand Up @@ -902,5 +902,5 @@ decompose_tensor <- function(tensor,
"pandas==1.4.2",
"rpy2==3.4.5")

.liana_pips <- c("cell2cell==0.6.3",
.liana_pips <- c("cell2cell==0.6.8",
"anndata2ri==1.0.6")
Binary file modified inst/testdata/input/sce_conv.rds
Binary file not shown.
Binary file modified inst/testdata/input/wrap_sce.rds
Binary file not shown.
Binary file modified inst/testdata/output/conn_score.RDS
Binary file not shown.
Binary file modified inst/testdata/output/liana_aggr.RDS
Binary file not shown.
Binary file modified inst/testdata/output/liana_constrained.RDS
Binary file not shown.
Binary file modified inst/testdata/output/liana_cpdb.RDS
Binary file not shown.
Binary file modified inst/testdata/output/liana_cytotalk.RDS
Binary file not shown.
Binary file modified inst/testdata/output/liana_house_aggr.RDS
Binary file not shown.
Binary file modified inst/testdata/output/liana_pipe.RDS
Binary file not shown.
Binary file modified inst/testdata/output/liana_res.RDS
Binary file not shown.
Binary file modified inst/testdata/output/logfc_score.RDS
Binary file not shown.
Binary file modified inst/testdata/output/natmi_score.RDS
Binary file not shown.
Binary file modified inst/testdata/output/rank_mag_example.RDS
Binary file not shown.
Binary file modified inst/testdata/output/rank_spec_example.RDS
Binary file not shown.
Binary file modified inst/testdata/output/recomplex.RDS
Binary file not shown.
Binary file modified inst/testdata/output/sca_score.RDS
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/testthat/test-liana_aggr.R
Expand Up @@ -10,7 +10,7 @@ test_that("Test liana aggregate", {
"output", "liana_res.RDS")) %>%
liana_aggregate()

expect_equal(exp1, res1)
expect_equal(res1, exp1)
})


Expand All @@ -27,7 +27,7 @@ test_that("Test liana aggregate (housekeep)", {
)


expect_equal(exp2, res2)
expect_equal(res2, exp2)
})


Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-liana_cpdb.R
Expand Up @@ -14,3 +14,4 @@ test_that("Test liana cpdb", {

expect_equal(exp1, res1)
})

2 changes: 1 addition & 1 deletion tests/testthat/test-liana_cytotalk.R
Expand Up @@ -12,5 +12,5 @@ test_that("Test Cytotalk Wrap", {
method = c('cytotalk'),
resource = c('OmniPath'))

expect_equal(exp1, res1)
expect_equal(res1, exp1)
})

0 comments on commit 4c323df

Please sign in to comment.