Skip to content

Commit

Permalink
Make sure to save the general metadata from an SE.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Oct 26, 2023
1 parent c086934 commit dea7297
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/dolomite_se/load_summarized_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,17 @@ def load_summarized_experiment(meta: dict[str, Any], project, **kwargs) -> Summa
except Exception as ex:
raise ValueError("failed to load assay '" + curname + "' from '" + meta["$schema"] + "'; " + str(ex))

other_meta = None
if "other_data" in se_meta:
try:
child_meta = acquire_metadata(project, se_meta["other_data"]["resource"]["path"])
other_meta = load_object(child_meta, project)
except Exception as ex:
raise ValueError("failed to load other metadata from '" + meta["$schema"] + "'; " + str(ex))

return SummarizedExperiment(
assays=assays,
row_data=row_data,
col_data=col_data
col_data=col_data,
metadata=other_meta,
)
14 changes: 11 additions & 3 deletions src/dolomite_se/stage_summarized_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,28 @@ def stage_summarized_experiment(

if x.row_data.row_names is not None or x.row_data.shape[1] > 0:
try:
rd_meta = stage_object(x.row_data, dir, path + "/row_data", **data_frame_args)
rd_meta = stage_object(x.row_data, dir, path + "/row_data", is_child=True, **data_frame_args)
rd_stub = write_metadata(rd_meta, dir)
except Exception as ex:
raise ValueError("failed to stage row data for a " + str(type(x)) + "; " + str(ex))
se_meta["row_data"] = { "resource": rd_stub }

if x.col_data.row_names is not None or x.col_data.shape[1] > 0:
try:
cd_meta = stage_object(x.col_data, dir, path + "/column_data", **data_frame_args)
cd_meta = stage_object(x.col_data, dir, path + "/column_data", is_child=True, **data_frame_args)
cd_stub = write_metadata(cd_meta, dir)
except Exception as ex:
raise ValueError("failed to stage row data for a " + str(type(x)) + "; " + str(ex))
raise ValueError("failed to stage column data for a " + str(type(x)) + "; " + str(ex))
se_meta["column_data"] = { "resource": cd_stub }

if x.metadata is not None and len(x.metadata):
try:
o_meta = stage_object(x.metadata, dir, path + "/other_data", is_child=True)
o_stub = write_metadata(o_meta, dir)
except Exception as ex:
raise ValueError("failed to stage other metadata for a " + str(type(x)) + "; " + str(ex))
se_meta["other_data"] = { "resource": o_stub }

return {
"$schema": "summarized_experiment/v1.json",
"path": path + "/experiment.json",
Expand Down
16 changes: 16 additions & 0 deletions tests/test_stage_summarized_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,19 @@ def test_stage_summarized_experiment_with_dimdata():
assert isinstance(roundtrip, summarizedexperiment.SummarizedExperiment)
assert se.row_data.row_names == roundtrip.row_data.row_names
assert se.col_data.row_names == roundtrip.col_data.row_names


def test_stage_summarized_experiment_with_other_meta():
x = numpy.random.rand(1000, 200)
se = summarizedexperiment.SummarizedExperiment(
assays={ "counts": x },
metadata={"YAY":2, "FOO":'a'}
)

dir = mkdtemp()
info = stage_object(se, dir, "se")
assert "other_data" in info["summarized_experiment"]
write_metadata(info, dir)

roundtrip = load_object(info, dir)
assert roundtrip.metadata == se.metadata

0 comments on commit dea7297

Please sign in to comment.