From 5b0a66dd9e77b96e6e819b274ac3f9425c7df912 Mon Sep 17 00:00:00 2001 From: Dries Schaumont <5946712+DriesSchaumont@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:52:18 +0200 Subject: [PATCH] Bump liana to 1.3.0 (#862) --- CHANGELOG.md | 2 +- src/interpret/lianapy/config.vsh.yaml | 5 ++--- src/interpret/lianapy/script.py | 16 ++++++++++++---- src/interpret/lianapy/test.py | 10 +++++----- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 083aaa0b2ac..5e16d4b1ddb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ * Removed `--disable_library_compatibility_check` in favour of `--check_library_compatibility` to the `mapping/cellranger_multi` component and the `ingestion/cellranger_multi` workflow (PR #818). -* `lianapy`: bumped version to `1.2.1` (PR #827). +* `lianapy`: bumped version to `1.3.0` (PR #827 and PR #862). Additionally, `groupby` is now a required argument. * `XGBoost`: bump version to `2.0.3` (PR #646). diff --git a/src/interpret/lianapy/config.vsh.yaml b/src/interpret/lianapy/config.vsh.yaml index dd1ebf99907..942fa3b709d 100644 --- a/src/interpret/lianapy/config.vsh.yaml +++ b/src/interpret/lianapy/config.vsh.yaml @@ -35,8 +35,7 @@ functionality: description: "Layer in anndata.AnnData.layers to use. If None, use mudata.mod[modality].X." - name: "--groupby" type: string - default: "bulk_labels" - required: false + required: true description: "The key of the observations grouping to consider." - name: "--resource_name" type: string @@ -93,7 +92,7 @@ platforms: - type: python __merge__: [/src/base/requirements/anndata_mudata.yaml, .] packages: - - liana~=1.2.1 + - liana~=1.3.0 test_setup: - type: python __merge__: [ /src/base/requirements/viashpy.yaml, .] diff --git a/src/interpret/lianapy/script.py b/src/interpret/lianapy/script.py index 66c1310d9ca..cee30e73e5f 100644 --- a/src/interpret/lianapy/script.py +++ b/src/interpret/lianapy/script.py @@ -3,16 +3,17 @@ # TODO: Remove when grouping labels exist # For sign/PCA/ import numpy as np +import pandas as pd ### VIASH START par = { - "input": "integration.pca.output.h5mu", + "input": "resources_test/pbmc_1k_protein_v3/pbmc_1k_protein_v3_mms.h5mu", "output": "foo.h5mu", "output_compression": "gzip", "modality": "rna", "layer": None, "gene_symbol": "gene_symbol", - "groupby": "bulk_labels", + "groupby": "harmony_integration_leiden_1.0", "resource_name": "consensus", "expr_prop": 0.1, "min_cells": 5, @@ -31,8 +32,12 @@ def main(): # Add dummy grouping labels when they do not exist if par['groupby'] not in mod.obs: - foo = mod.obsm.to_df().iloc[:, 0] - mod.obs[par['groupby']] = np.sign(foo).astype('category') + raise ValueError(f"Column {par['groupy']} does not exist in " + f".obs for modality {par['modality']}.") + mod_col = mod.obs[par['groupby']] + original_groupby_col = mod_col.copy() + if not isinstance(mod_col, pd.CategoricalDtype): + mod.obs[par['groupby']] = mod_col.astype(str).astype('category') # Solve gene labels orig_gene_label = mod.var.index @@ -57,6 +62,9 @@ def main(): # Return original gene labels mod.var_names = orig_gene_label + # Undo modifications to groupby column + mod.obs[par["groupby"]] = original_groupby_col + # TODO: make sure compression is needed mdata.write_h5mu(par['output'].strip(), compression=par['output_compression']) diff --git a/src/interpret/lianapy/test.py b/src/interpret/lianapy/test.py index f6f7b150d53..cad96d05381 100644 --- a/src/interpret/lianapy/test.py +++ b/src/interpret/lianapy/test.py @@ -5,7 +5,7 @@ ## VIASH START meta = { - 'executable': './target/native/interpret/lianapy/', + 'executable': './target/executable/interpret/lianapy/', 'resources_dir': './resources_test/pbmc_1k_protein_v3/' } ## VIASH END @@ -21,8 +21,8 @@ def test_lianapy(run_component, tmp_path): "--input", input_file, "--output_compression", "gzip", "--modality", "rna", - # "--layer", "log_normalized", - "--groupby", "bulk_labels", + "--layer", "log_normalized", + "--groupby", "harmony_integration_leiden_1.0", "--resource_name", "consensus", "--gene_symbol", "gene_symbol", "--expr_prop", "0.1", @@ -39,8 +39,8 @@ def test_lianapy(run_component, tmp_path): np.testing.assert_array_equal(output_data.mod['rna'].X.data, input_data.mod['rna'].X.data) np.testing.assert_array_equal(input_data.mod['rna'].var.index, output_data.mod['rna'].var.index) assert "liana_res" in output_data.mod["rna"].uns - assert all(elem in output_data.mod['rna'].obs['bulk_labels'].values for elem in output_data.mod['rna'].uns['liana_res']['source'].unique()) - assert all(elem in output_data.mod['rna'].obs['bulk_labels'].values for elem in output_data.mod['rna'].uns['liana_res']['target'].unique()) + assert all(elem in output_data.mod['rna'].obs['harmony_integration_leiden_1.0'].values for elem in output_data.mod['rna'].uns['liana_res']['source'].unique()) + assert all(elem in output_data.mod['rna'].obs['harmony_integration_leiden_1.0'].values for elem in output_data.mod['rna'].uns['liana_res']['target'].unique()) if __name__ == "__main__": sys.exit(pytest.main([__file__])) \ No newline at end of file