saezlab / liana

LIANA: a LIgand-receptor ANalysis frAmework
https://saezlab.github.io/liana/
GNU General Public License v3.0
169 stars 30 forks source link

liana_aggregate does not work with .simplify = FALSE #91

Closed PoGibas closed 1 year ago

PoGibas commented 1 year ago

There is an option to run liana::liana_wrap with .simplify = FALSE (this parameter might be useful to keep consistent output when running single or multiple methods). For example:

res_multiple_simple <- liana::liana_wrap(
  test_data,
  method = c("logfc", "natmi"),
  resource = "Consensus"
)
res_multiple_notsimple <- liana::liana_wrap(
  test_data,
  method = c("logfc", "natmi"),
  resource = "Consensus",
  .simplify = FALSE
)
res_single_simple <- liana::liana_wrap(
  test_data,
  method = "natmi",
  resource = "Consensus"
)
res_single_notsimple <- liana::liana_wrap(
  test_data,
  method = "natmi",
  resource = "Consensus",
  .simplify = FALSE
)

class(res_multiple_simple)
class(res_multiple_notsimple)
class(res_single_simple)
class(res_single_notsimple)

However, I run into errors when trying to run liana::liana_aggregate on these outputs:

# Works
liana::liana_aggregate(res_multiple_simple, resource = "Consensus")
# Does not Work
liana::liana_aggregate(res_multiple_notsimple, resource = "Consensus")
# Does not Work
liana::liana_aggregate(res_single_simple, resource = "Consensus")
# Does not Work
liana::liana_aggregate(res_single_notsimple, resource = "Consensus")

What should be the correct compatibility between .simplify = FALSE and liana::liana_aggregate? My whole question came from the problem when I'm trying to run analysis on the single method and then pipe result to aggregation, but since output is not a list then aggregation fails.

dbdimitrov commented 1 year ago

.simplify=FALSE would get rid of NULLs, and will convert any list of one dataframe to simply a dataframe (for both resources and methods). If one runs LIANA with multiple methods, they get a list of method dataframes, if ran on multiple methods and resources, they get a list of lists with dataframes.

liana_aggregate is intended to be used only when aggregating multiple methods (so it expects a list, and will hence fail when working on a single method - nothing to aggregate). It also expects the output to be simplified

dbdimitrov commented 1 year ago

liana_aggregate will also work on a single resource at a time (so one needs to provide a resource name, if multiple methods and resources are ran via liana_wrap)