|
18 | 18 |
|
19 | 19 | print("Loading data", flush=True) |
20 | 20 | with open(par["input"], "r", encoding="utf-8") as f: |
21 | | - reader = csv.reader(f) |
| 21 | + reader = csv.DictReader(f) |
22 | 22 | data = list(reader) |
23 | 23 |
|
24 | 24 | input_mu = mu.read_h5mu(par["orig_input"]) |
25 | 25 |
|
26 | | -num_mod = len(data) - 1 |
| 26 | +num_mod = len(data) |
27 | 27 | num_files = len(os.listdir(par["mod_dir"])) |
28 | 28 |
|
29 | 29 | # Check if the number of files is equal to the number of lines in the csv |
|
32 | 32 | f"Expected {num_mod} modalities in {par['orig_input']} got {input_mu.n_mod} modalities." |
33 | 33 | ) |
34 | 34 |
|
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 | +} |
37 | 39 |
|
38 | 40 | # 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"] |
42 | 43 | # 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." |
46 | 49 | # 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}." |
52 | 54 | ) |
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]) |
57 | 60 |
|
58 | 61 | print("Test successful!", flush=True) |
0 commit comments