Skip to content

update and refractor liana tool - #9034

Open
nilchia wants to merge 13 commits into
galaxyproject:mainfrom
nilchia:fix_liana
Open

nilchia wants to merge 13 commits into
galaxyproject:mainfrom
nilchia:fix_liana

Conversation

@nilchia

@nilchia nilchia commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Upgrades the liana tool suite from 1.6.1 to 2.0.0, fixes runtime/API bugs, removes the Data Manager dependency which was not needed, adds new 2.0.0 methods, and expands test coverage.

Why No Data Manager Is Needed:

  • All 17 built-in ligand–receptor databases are already bundled offline inside the liana Python package (liana/resource/omni_resource.csv).
  • Replaced from_data_table="liana_resources" with a static <select> macro of the 17 bundled resources and removed tool-data/ and tool_data_table_conf.xml.*.

Bugs Fixed

  • liana_methods: Fixed TypeError from passing n_perms to non-permutation methods (logfc, natmi, connectome, singlecellsignalr, geometric_mean); fixed bivariate n_perms to allow None/0 (analytical p-values); fixed estimate_metalinks to accept the required resource, pd_net, and t_net tables.
  • liana_misty: Fixed TypeError in lrMistyData (bypass_intra moved to model call).
  • liana_multi: Fixed to_tensor_c2c (uns_key instead of string liana_res, portable .npy output), lrs_to_views (added required sample_key), and nmf (range(min, max + 1) instead of tuple k_range).
  • liana_plot: Fixed misty_contributions crash by wrapping MuData in li.mt.MistyData; added missing groupby to circle.
  • liana_utils: Fixed anndata_out output filter for mdata_to_anndata on .h5mu inputs.

Functions Added

  • liana_methods: scseqcomm, inflow, compute_global_specificity, lric, cross_pcf, get_lric_auc, plus .by_sample(), spatial proximity weighting, and multi-modal MuData support across single-cell L-R methods.
  • liana_misty: MistyData (custom multi-view AnnData inputs or MuData), separate extra_adata, and optional .tsv exports.
  • liana_multi: filter_view_markers, lrdata_to_mudata.
  • liana_plot: elbow, feature_by_group, annulus, lric_lineplot, lric_divergence.
  • liana_resource: translate_column, direct network exports (export_networks) in get_metalinks, and source/target formatting in get_hcop_orthologs.
  • liana_utils: spatial_pair_proximity, expand_coordinates, interpolate_adata.

Functions Removed or Simplified

  • show_resources: Removed from resource.xml (all 17 built-in resources are now directly selectable in the dropdown UI).
  • Tabular input branch in plot.xml: Simplified all plotting methods to take AnnData (.h5ad) or MuData (.h5mu) directly.

Functions Skipped / Commented Out

  • find_causalnet & build_prior_network: Implemented and tested in liana_methods.xml, but commented out because Bioconda's liana:2.0.0 container ships corneto 1.0.0rc9 (which removed corneto.methods.carnival, required by liana 2.0.0's pinned corneto==0.9.1a6). Ready to uncomment once upstream/Bioconda resolves corneto compatibility.
  • Interactive console helpers (show_methods, show_resources, describe_metalinks, get_metalinks_values): Skipped as their options are exposed directly in the Galaxy UI dropdowns.
  • get_lric_divergence & estimate_elbow: Already executed and reported inside plot.xml (lric_divergence) and multi.xml (nmf with empty n_components).

I checked all the arguments and functions against the upstream API.

FOR CONTRIBUTOR:

  • I have read the CONTRIBUTING.md document and this tool is appropriate for the tools-iuc repo.
  • Use of AI
    • The contribution is mostly AI generated
    • The contribution has been assisted by AI
    • AI harness (required if AI was used): VSCODE copilot, antigravity
    • Model (required if AI was used): GLM 5.3, Gemini 4 Argon
  • License permits unrestricted use (educational + commercial)
  • This PR adds a new tool or tool collection
  • This PR updates an existing tool or tool collection (see the
    tool update guide)
  • This PR does something else (explain below)

There are two labels that allow to ignore specific (false positive) tool linter errors:

  • skip-version-check: Use it if only a subset of the tools has been updated in a suite.
  • skip-url-check: Use it if github CI sees 403 errors, but the URLs work.

To request a review once your PR is ready, comment "please review" on the PR. This will
automatically apply the ready-for-review label if the PR is not a draft, all review
threads are resolved, and all CI checks have passed. The label is removed once a reviewer
submits a review; after addressing it, comment "please review" again to ping the reviewers.

@nilchia

nilchia commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

please review

@tools-iuc

tools-iuc Bot commented Nov 25, 2026

Copy link
Copy Markdown

⏳ Some CI checks are still running. Please wait for them to complete before requesting a review.

@nilchia

nilchia commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

I also checked all available tutorials on the liana site and put everything that was missing from there, here

@nilchia

nilchia commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

There is also an overlapping PR in #7827
The main difference is the data manager that is removed.

The 17 LR databases do not need a data manager at all.
HCOP and metalinkdb might need a DB, however:

  1. for HCOP, users can upload the mapping and pass it to map_df input
  2. for metalinkdb, users can also upload the inputs and pass it to resources, pd_net, and t_net

If we prefer this PR (with or without a Data Manager):

Ready to merge as-is if on-demand downloads for HCOP / MetalinksDB are acceptable.
If we want offline caching via Data Manager for HCOP and MetalinksDB, we can bring back only the refactored Data Manager from #7827 (for HCOP and MetalinksDB) while keeping all 17 built-in L-R resources offline via liana.

If we prefer #7827:

The following features and fixes from this PR are currently missing in #7827 and would be worth porting over:
liana_methods: .by_sample(), spatial proximity weighting, and MuData support across single-cell L-R methods; fixed estimate_metalinks accepting resource, pd_net, and t_net.
liana_misty: MistyData (custom multi-view AnnData inputs or MuData), separate extra_adata, predict_self, maskby, and .tsv exports.
liana_plot: pl.elbow and pl.lric_divergence.
liana_resource: translate_column, generate_lr_geneset, get_metalinks network exports (lr_resource, pd_net, t_net), and source/target formatting in get_hcop_orthologs.
liana_utils: zi_minmax, neg_to_zero, and the anndata_out filter fix for mdata_to_anndata on .h5mu inputs.
Moving the committed binary .h5ad/.h5mu test files to Zenodo.

Happy to adapt this PR in either direction based on preference.

@nilchia

nilchia commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

@khaled196 What do you think?
ping: @pavanvidem

@khaled196

khaled196 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

@khaled196 What do you think? ping: @pavanvidem

Hi Amir,

Thank you for your work on Liana. As the owner of that pull request, I am happy to close it and transfer whatever is needed to this pull request.

Regarding the data managers, I can't provide a direct answer, personaly I don't like them, but depend on if users are aware of the on-demand installation method. If they have learned about this tool from Galaxy, it makes sense to keep them in the data managers, but if they know about that, then I agree about removing them. This would save us the burden of maintaining the wrapper data managers.

The primary reason for using data managers was that the liana api installed them from links, and you could use it as an alternative to the built-in.

final decision will depend on yourself and @pavanvidem

Comment thread tools/liana/macros.xml
#if str($method.orderby).strip() != '':
orderby='$method.orderby'.strip(),
#else:
orderby='$method.colour'.strip() if hasattr($method, 'colour') and str($method.colour).strip() != '' else None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this fallback line will break. $method.colour is resolved by Cheetah before Python ever runs, so for tileplot/circle (no colour param) you'd get a NotFound as soon as someone sets Top N without a sort column. For dotplot, hasattr($method, ...) renders the whole conditional dict (including dataset wrapper reprs) into the script, which probably won't even parse. The tileplot test sets orderby, so this path never runs in CI.

Could you do the check in Cheetah instead? Something like:

#else if 'colour' in $method and str($method.colour).strip() != '':
orderby='$method.colour',
#end if

and maybe add a test with top_n set and orderby left empty.

n_components=$method.n_components,
#else:
n_components=None,
k_range=range($method.k_range_min, $method.k_range_max),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description says this was fixed to range(min, max + 1), and the label on L311 says the maximum is inclusive, but here it's still range(min, max). Test 8's expected message range(1, 5) with k_range_max=5 confirms it's exclusive. I'd go with + 1 so it matches the label.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description was old, I changed it to match the tool defaults

</output>
</test>
<!-- Test 8: nmf with automatic elbow rank estimation (n_components empty; random test matrix has no elbow) -->
<test expect_failure="true">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing the failure path is fine, but this means auto-elbow never actually succeeds anywhere in the tests. Is there a small input with a real elbow we could use for a happy-path test, so we know n_components=None works end to end?

<expand macro="version_command"/>
<command detect_errors="exit_code"><![CDATA[
cat '$script_file' > '$hidden_output' &&
python '$script_file' >> '$hidden_output' 2>&1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With 2>&1 going into hidden_output, a failed job shows the user an empty stderr unless they happened to tick "Output Log". This is the one tool that downloads things (HCOP, MetalinksDB), so it's the one most likely to fail on network problems. Maybe drop the redirect so tracebacks reach stderr like in the other tools?

</param>
<when value="rank_aggregate">
<expand macro="inputs_anndata" format="h5ad,h5mu" label="Annotated data matrix (AnnData, or MuData)"/>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving adata inside the method conditional changes the input path from adata to method|adata, so existing workflows using Liana Methods will lose that connection after upgrading. That might be acceptable for a major bump, but if you keep it, it's worth calling out in the help/README. Misty/Multi/Utils keep adata at the top level, so the methods tool is the odd one out.

**de_method, n_perms, seed**: Differential expression method, permutation count (if applicable), and RNG seed
- **compute_global_specificity**: Computes permutation-based global specificity scores and p-values per receiver cell type from spatial inflow scores.
- *Input*: Inflow `AnnData` (`.h5ad`) produced by `inflow`.
- *Output*: Updated Inflow `AnnData` (`.h5ad`) with specificity statistics in `.uns['global_res']`, plus an optional tabular file (`.tsv`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small help mismatch: the default uns_key is global_interactions, not global_res.

-------
- **df_to_lr**: Combines per-cell-type differential expression (DEA) statistics with expression proportions into a ligand-receptor interaction table.
- *Input*: `AnnData` (`.h5ad`) and a DEA table (`.tsv`) containing gene names, cell-type labels (`groupby`), and test statistics.
- *Output*: Tabular file (`.tsv`) of differential ligand-receptor interactions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

df_to_lr also writes to .uns[key_added] and returns the AnnData, so the output isn't only the TSV. Also, output_tsv defaults to true here but false everywhere else. Is that on purpose?

- *Output*: `MuData` (`.h5mu`) with one pseudobulk modality per cell type.

- **filter_view_markers**: Filters out background marker genes of other cell types from `adata_to_views` pseudobulk views.
- *Input*: `MuData` (`.h5mu`) produced by `adata_to_views` and a marker gene table (`.tsv`, cell types as columns and marker genes as rows).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This says "cell types as columns and marker genes as rows", but the param help on L290 and the code expect a two-column view→gene table. One of them needs updating.

<!-- Test 9: rank_aggregate with custom key_added -->
<test expect_num_outputs="2">
<param name="adata" location="https://zenodo.org/records/18388645/files/pbmc_small.h5ad"/>
<!-- Test 10: rank_aggregate by_sample + spatial proximity weighting -->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the test name says "spatial proximity weighting", but no spatial_key is set, so the spatial path isn't tested anywhere. Either rename the test or add a spatial run.

Comment thread tools/liana/macros.xml
<xml name="param_plot_size">
<param argument="size" type="text" value="" optional="true" label="Size by column" help="Column name in liana_res DataFrame to map to dot size. Larger values = larger dots.">
<xml name="param_plot_size" token_value="specificity_rank" token_optional="false">
<param argument="size" type="text" value="@VALUE@" optional="@OPTIONAL@" label="Size by column" help="Column name in liana_res define color mapping">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: copy-paste in the help text. "define color mapping" should be about size. Also, now that both colour and size carry an empty_field validator, the optional token can't really be true, so it might be cleaner to drop it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage/Discuss

Development

Successfully merging this pull request may close these issues.

3 participants