diff --git a/CHANGELOG.md b/CHANGELOG.md index b354936d801..45247e658ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -171,6 +171,8 @@ * Fix failing tests for `ingestion/cellranger_postprocessing`, `ingestion/conversion` and `multiomics/process_batches` (PR #869). +* `convert/from_10xh5_to_h5mu`: add .uns slot to mdata root when metrics file is provided (PR #887). + ## DOCUMENTATION * Update authorship of components (PR #835). diff --git a/src/convert/from_10xh5_to_h5mu/script.py b/src/convert/from_10xh5_to_h5mu/script.py index 01d5157973c..ecd8e4517d6 100755 --- a/src/convert/from_10xh5_to_h5mu/script.py +++ b/src/convert/from_10xh5_to_h5mu/script.py @@ -44,7 +44,7 @@ def setup_logger(): .reset_index()\ .set_index("gene_ids") -# parse metrics summary file and store in .obsm or .obs +# parse metrics summary file and store in .uns if par["input_metrics_summary"] and par["uns_metrics"]: logger.info("Reading metrics summary file '%s'", par['input_metrics_summary']) @@ -76,8 +76,9 @@ def read_percentage(val): logger.info("Convert to mudata") mdata = mudata.MuData(adata) -# override root .obs +# override root .obs and .uns mdata.obs = adata.obs +mdata.uns = adata.uns # write output logger.info("Writing %s", par["output"]) diff --git a/src/convert/from_10xh5_to_h5mu/test.py b/src/convert/from_10xh5_to_h5mu/test.py index 316e636fc6b..166a390a482 100644 --- a/src/convert/from_10xh5_to_h5mu/test.py +++ b/src/convert/from_10xh5_to_h5mu/test.py @@ -12,6 +12,7 @@ ## VIASH END input = meta["resources_dir"] + "/pbmc_1k_protein_v3/pbmc_1k_protein_v3_filtered_feature_bc_matrix.h5" +metrics = meta["resources_dir"] + "/pbmc_1k_protein_v3/pbmc_1k_protein_v3_metrics_summary.csv" def test_run(run_component, random_h5mu_path): output = random_h5mu_path() @@ -40,7 +41,25 @@ def test_run(run_component, random_h5mu_path): assert ( "CD3" in data.mod["prot"].var_names ), 'Output should contain antibody column "CD3".' - - + +def test_run_with_metrics(run_component, random_h5mu_path): + output = random_h5mu_path() + cmd_pars = [ + "--input", input, + "--output", output, + "--input_metrics_summary", metrics, + "--output_compression", "gzip", + ] + run_component(cmd_pars) + + # check if file exists + assert path.exists(output), "No output was created." + + # read it with scanpy + data = read_h5mu(output) + + # check whether uns slot was found + assert "metrics_cellranger" in data.uns, "Output mudata object should contain an .uns slot with cellranger metrics." + if __name__ == "__main__": sys.exit(pytest.main([__file__]))