Skip to content

Commit

Permalink
add metrics to uns slot after conversion to h5mu
Browse files Browse the repository at this point in the history
  • Loading branch information
dorien-er committed Oct 10, 2024
1 parent 926fcc0 commit b1a1a19
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/convert/from_10xh5_to_h5mu/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

## VIASH START
par = {
"input": "resources_test/pbmc_1k_protein_v3/pbmc_1k_protein_v3_raw_feature_bc_matrix.h5",
"input_metrics_summary": None,
"input": "raw_feature_bc_matrix_j1.h5",
"input_metrics_summary": "metrics_summary_j1.csv",
"uns_metrics": "metrics_cellranger",
"output": "foo.h5mu",
"min_genes": None,
Expand Down 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 b1a1a19

Please sign in to comment.