Skip to content

Commit

Permalink
Merge pull request #887 from openpipelines-bio/add_metrics
Browse files Browse the repository at this point in the history
add metrics to uns slot after conversion to h5mu
  • Loading branch information
dorien-er authored Oct 10, 2024
2 parents 926fcc0 + e34ea59 commit 812e25e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
5 changes: 3 additions & 2 deletions src/convert/from_10xh5_to_h5mu/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand Down Expand Up @@ -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"])
Expand Down
23 changes: 21 additions & 2 deletions src/convert/from_10xh5_to_h5mu/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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__]))

0 comments on commit 812e25e

Please sign in to comment.