|
21 | 21 | model_file = ( |
22 | 22 | f"{meta['resources_dir']}/annotation_test_data/celltypist_model_Immune_All_Low.pkl" |
23 | 23 | ) |
24 | | -celltypist_input_file = ( |
25 | | - f"{meta['resources_dir']}/annotation_test_data/demo_2000_cells.h5mu" |
26 | | -) |
27 | | -# input_file = f"{meta['resources_dir']}/pbmc_1k_protein_v3/pbmc_1k_protein_v3_mms.h5mu" |
| 24 | +input_file_1 = f"{meta['resources_dir']}/pbmc_1k_protein_v3/pbmc_1k_protein_v3_mms.h5mu" |
| 25 | +input_file_2 = f"{meta['resources_dir']}/annotation_test_data/demo_2000_cells.h5mu" |
| 26 | +reference_file = f"{meta['resources_dir']}/annotation_test_data/TS_Blood_filtered.h5mu" |
28 | 27 |
|
29 | 28 |
|
30 | 29 | def log_normalize(adata): |
31 | | - sc.pp.normalize_total(adata, target_sum=1e4) |
32 | | - sc.pp.log1p(adata) |
| 30 | + adata_norm = sc.pp.normalize_total(adata, target_sum=1e4, copy=True) |
| 31 | + adata_lognorm = sc.pp.log1p(adata_norm, copy=True) |
| 32 | + adata.layers["log_normalized"] = adata_lognorm.X |
| 33 | + return adata |
| 34 | + |
| 35 | + |
| 36 | +def calculate_hvg(adata, n_top_genes=1000): |
| 37 | + adata_hvg = sc.pp.highly_variable_genes(adata, n_top_genes=n_top_genes, copy=True) |
| 38 | + adata.var["filter_with_hvg"] = adata_hvg.var["highly_variable"] |
33 | 39 | return adata |
34 | 40 |
|
35 | 41 |
|
36 | 42 | @pytest.fixture |
37 | 43 | def reference_mdata(): |
38 | | - mdata = mu.read_h5mu( |
39 | | - f"{meta['resources_dir']}/annotation_test_data/TS_Blood_filtered.h5mu" |
40 | | - ) |
| 44 | + mdata = mu.read_h5mu(reference_file) |
| 45 | + adata = mdata.mod["rna"] # already has layer "log_normalized" with 10k target sum |
| 46 | + adata.var["filter_with_hvg"] = adata.var[ |
| 47 | + "highly_variable" |
| 48 | + ] # already has highly variable genes calculated |
| 49 | + return mdata |
| 50 | + |
| 51 | + |
| 52 | +@pytest.fixture |
| 53 | +def input_mdata(): |
| 54 | + mdata = mu.read_h5mu(input_file_1) |
41 | 55 | adata = mdata.mod["rna"].copy() |
| 56 | + adata.layers["counts"] = adata.X.copy() # store raw counts in a layer |
42 | 57 | adata_lognorm = log_normalize(adata) |
43 | 58 | mdata.mod["rna"] = adata_lognorm |
44 | 59 | return mdata |
45 | 60 |
|
46 | 61 |
|
47 | 62 | @pytest.fixture |
48 | | -def input_mdata(): |
49 | | - mdata = mu.read_h5mu( |
50 | | - f"{meta['resources_dir']}/pbmc_1k_protein_v3/pbmc_1k_protein_v3_mms.h5mu" |
51 | | - ) |
| 63 | +def model_input_mdata(): |
| 64 | + mdata = mu.read_h5mu(input_file_2) |
52 | 65 | adata = mdata.mod["rna"].copy() |
53 | 66 | adata_lognorm = log_normalize(adata) |
54 | 67 | mdata.mod["rna"] = adata_lognorm |
@@ -155,15 +168,20 @@ def test_set_params( |
155 | 168 | ) |
156 | 169 |
|
157 | 170 |
|
158 | | -def test_with_model(run_component, random_h5mu_path): |
| 171 | +def test_with_model( |
| 172 | + run_component, random_h5mu_path, write_mudata_to_file, model_input_mdata |
| 173 | +): |
159 | 174 | output_file = random_h5mu_path() |
| 175 | + input_file = write_mudata_to_file(model_input_mdata) |
160 | 176 |
|
161 | 177 | run_component( |
162 | 178 | [ |
163 | 179 | "--input", |
164 | | - celltypist_input_file, |
| 180 | + input_file, |
165 | 181 | "--model", |
166 | 182 | model_file, |
| 183 | + "--reference_layer", |
| 184 | + "", |
167 | 185 | "--reference_obs_targets", |
168 | 186 | "cell_type", |
169 | 187 | "--output", |
@@ -208,7 +226,7 @@ def test_fail_invalid_input_expression( |
208 | 226 | "--input", |
209 | 227 | input_file, |
210 | 228 | "--input_layer", |
211 | | - "log_normalized", |
| 229 | + "counts", |
212 | 230 | "--reference", |
213 | 231 | reference_file, |
214 | 232 | "--reference_layer", |
|
0 commit comments