Skip to content

Commit

Permalink
add param
Browse files Browse the repository at this point in the history
  • Loading branch information
dbdimitrov committed Dec 13, 2022
1 parent 8600a75 commit ebe6351
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 17 deletions.
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# LIANA 0.1.9 (05.12.22)
# LIANA 0.1.9 (13.12.22)

## Changes
- `return_all` parameter was included to `liana_wrap`. `return_all` enables
Expand All @@ -17,7 +17,8 @@ This deals with edge cases with non-expression ligand/receptor scores (e.g. z-sc
the lower score subunit is the one with higher expression proportion. Hence,
this is intended to make all methods consistent according to which interactions
are returned, regardless of which subunit has the lower score.

- `aggregate_how` parameter added to `liana_aggregate` to allow the aggregation
by specificity and magnitude scores.


# LIANA 0.1.8 (08.11.22)
Expand Down
25 changes: 22 additions & 3 deletions R/liana_aggregate.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#' Function to Aggregate CCC Method Results
#'
#' @param liana_res LIANA results
#' @param aggregate_how way to aggregate, by default (NULL) will aggregate
#' all passed methods with the approach specified in `liana:::..score_specs`.
#' Alternative options are `magnitude` and `specificity`.
#' @param set_cap Function used to set ranked cap (i.e. the value that is
#' assigned to interactions with NA for scores);
#' By default, this is set to "max", which is the maximum number of interactions
Expand Down Expand Up @@ -49,6 +52,7 @@
#' # aggregate results from multiple methods
#' liana_res <- liana_aggregate(liana_res)
liana_aggregate <- function(liana_res,
aggregate_how=NULL,
resource = NULL,
set_cap = "max",
cap = NULL,
Expand All @@ -59,6 +63,21 @@ liana_aggregate <- function(liana_res,
join_cols = NULL,
...){

# define approach to aggregate
if(!is.null(aggregate_how)){
if(aggregate_how=="magnitude"){
score_mode = liana:::.score_housekeep()
} else if(aggregate_how=="specificity"){
specs <- liana:::.score_specs()
specs$sca <- NULL # remove SingleCellSignalR score
score_mode = specs
} else{
stop("Please specify an existing aggregate approach!")
}
} else{
score_mode <- .score_mode()
}

if(!is_tibble(liana_res[[1]]) && is.null(resource)){
stop("Please provide provide a name for the resource ",
"to be plucked and used to aggregate the method results!")
Expand Down Expand Up @@ -88,7 +107,7 @@ liana_aggregate <- function(liana_res,
liana_mlist <- liana_res %>%
map2(names(.), function(res, method_name){

if(is.null(.score_mode()[[method_name]])){
if(is.null(score_mode[[method_name]])){
liana_message(
str_glue(
"Unknown method name or missing specifics for: {method_name}"
Expand All @@ -100,8 +119,8 @@ liana_aggregate <- function(liana_res,
verbose = verbose)
}

method_score <- .score_mode()[[method_name]]@method_score
desc_order <- .score_mode()[[method_name]]@descending_order
method_score <- score_mode[[method_name]]@method_score
desc_order <- score_mode[[method_name]]@descending_order

.method = sym(as.character(str_glue("{method_name}.{method_score}")))
.rank_col = sym(as.character(str_glue("{method_name}.rank")))
Expand Down
4 changes: 2 additions & 2 deletions man/cytotalk_score.Rd

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

5 changes: 5 additions & 0 deletions man/liana_aggregate.Rd

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

7 changes: 3 additions & 4 deletions man/liana_bysample.Rd

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

7 changes: 3 additions & 4 deletions man/liana_wrap.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-liana_aggr.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test_that("Test liana aggregate (housekeep)", {
testthat::expect_warning(
res2 <- readRDS(file.path(liana_path, "testdata",
"output", "liana_res_plus.RDS")) %>%
liana_aggregate(.score_mode = .score_housekeep)
liana_aggregate(aggregate_how = "magnitude")
)


Expand Down
2 changes: 1 addition & 1 deletion vignettes/liana_nichenet.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ library(nichenetr)
library(Seurat)
library(ggrepel)
library(cowplot)
options(timeout=300) # required to download expression data /w slow connection
options(timeout=600) # required to download expression data /w slow connection
```

Then, we load and prepare the single-cell data, NicheNet's model weights, and the gene set of interest. The latest is composed by genes that are known to participate in the partial epithelial-mesenchymal transition (p-EMT) program, as defined in [NicheNet's vignette](https://github.com/saeyslab/nichenetr/blob/master/vignettes/ligand_activity_geneset.md).
Expand Down

0 comments on commit ebe6351

Please sign in to comment.