Skip to content

Commit 83d5c04

Browse files
Fix split_modalities integration test after #1152
1 parent 87979c1 commit 83d5c04

1 file changed

Lines changed: 22 additions & 19 deletions

File tree

  • src/workflows/test_workflows/multiomics/split_modalities

src/workflows/test_workflows/multiomics/split_modalities/script.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
print("Loading data", flush=True)
2020
with open(par["input"], "r", encoding="utf-8") as f:
21-
reader = csv.reader(f)
21+
reader = csv.DictReader(f)
2222
data = list(reader)
2323

2424
input_mu = mu.read_h5mu(par["orig_input"])
2525

26-
num_mod = len(data) - 1
26+
num_mod = len(data)
2727
num_files = len(os.listdir(par["mod_dir"]))
2828

2929
# Check if the number of files is equal to the number of lines in the csv
@@ -32,27 +32,30 @@
3232
f"Expected {num_mod} modalities in {par['orig_input']} got {input_mu.n_mod} modalities."
3333
)
3434

35-
rna_mod = mu.read_h5mu(os.path.join(par["mod_dir"], data[1][1]))
36-
prot_mod = mu.read_h5mu(os.path.join(par["mod_dir"], data[2][1]))
35+
output_mods = {
36+
csv_entry["name"]: mu.read_h5mu(os.path.join(par["mod_dir"], csv_entry["filename"]))
37+
for csv_entry in data
38+
}
3739

3840
# Check if the files exist and if the modality name is in the file name
39-
for i, row in enumerate(data):
40-
if i == 0:
41-
continue
41+
for csv_item in data:
42+
mod_name, mudata_file_name = csv_item["name"], csv_item["filename"]
4243
# Check if the files exist and if the modality name is in the file name
43-
assert row[0] in row[1], f"Expected {row[0]} to be in {row[1]}."
44-
mod_fp = os.path.join(par["mod_dir"], row[1])
45-
assert os.path.exists(mod_fp), f"Expected {row[1]} to exist."
44+
assert mod_name in mudata_file_name, (
45+
f"Expected {mod_name} to be in {mudata_file_name}."
46+
)
47+
mudata_path = os.path.join(par["mod_dir"], mudata_file_name)
48+
assert os.path.exists(mudata_path), f"Expected {mudata_file_name} to exist."
4649
# Check modality is correct in the h5mu file
47-
mod_mu = mu.read_h5mu(mod_fp)
48-
assert mod_mu.n_mod == 1, f"Expected 1 modality in {row[1]}."
49-
assert row[0] in mod_mu.mod.keys(), f"Expected {row[0]} to be the mod in {row[1]}."
50-
assert row[0] in input_mu.mod.keys(), (
51-
f"Expected {row[0]} to be a mod in {par['orig_input']}."
50+
mudata_object = mu.read_h5mu(mudata_path)
51+
assert mudata_object.n_mod == 1, f"Expected 1 modality in {mudata_file_name}."
52+
assert mod_name in mudata_object.mod.keys(), (
53+
f"Expected {mod_name} to be the mod in {mudata_file_name}."
5254
)
53-
54-
# Check if extracted modalities are equal to the original modalities
55-
assert_annotation_objects_equal(rna_mod.mod["rna"], input_mu.mod["rna"])
56-
assert_annotation_objects_equal(prot_mod.mod["prot"], input_mu.mod["prot"])
55+
assert mod_name in input_mu.mod.keys(), (
56+
f"Expected {mod_name} to be a mod in {par['orig_input']}."
57+
)
58+
# Check if extracted modalities are equal to the original modalities
59+
assert_annotation_objects_equal(mudata_object[mod_name], input_mu.mod[mod_name])
5760

5861
print("Test successful!", flush=True)

0 commit comments

Comments
 (0)