|
7 | 7 | ## VIASH START |
8 | 8 | par = { |
9 | 9 | 'input': 'resources_test/common/cxg_mouse_pancreas_atlas/dataset.h5ad', |
10 | | - 'method': 'batch', |
11 | 10 | 'seed': None, |
12 | 11 | 'obs_batch': 'batch', |
13 | 12 | 'obs_label': 'cell_type', |
14 | | - 'output_train': 'train.h5ad', |
15 | | - 'output_test': 'test.h5ad', |
| 13 | + 'obs_ptime': 'pseudotime_true', |
| 14 | + 'obsm_spatial': 'X_spatial', |
| 15 | + 'layer_counts': 'counts', |
| 16 | + 'output_dataset': 'dataset.h5ad', |
16 | 17 | 'output_solution': 'solution.h5ad' |
17 | 18 | } |
18 | 19 | meta = { |
|
25 | 26 | sys.path.append(meta['resources_dir']) |
26 | 27 | from subset_h5ad_by_format import subset_h5ad_by_format |
27 | 28 |
|
| 29 | +# read viash config |
28 | 30 | config = op.project.read_viash_config(meta["config"]) |
29 | 31 |
|
30 | 32 | # set seed if need be |
31 | 33 | if par["seed"]: |
32 | | - print(f">> Setting seed to {par['seed']}") |
| 34 | + print(f">> Setting seed to {par['seed']}", flush=True) |
33 | 35 | random.seed(par["seed"]) |
34 | 36 |
|
| 37 | +# read the dataset |
35 | 38 | print(">> Load data", flush=True) |
36 | | -adata = ad.read_h5ad(par["input"]) |
37 | | -print("input:", adata) |
| 39 | +input = ad.read_h5ad(par['input']) |
| 40 | +print("input:", input, flush=True) |
38 | 41 |
|
39 | | -print(f">> Process data using {par['method']} method") |
40 | | -if par["method"] == "batch": |
41 | | - batch_info = adata.obs[par["obs_batch"]] |
42 | | - batch_categories = batch_info.dtype.categories |
43 | | - test_batches = random.sample(list(batch_categories), 1) |
44 | | - is_test = [ x in test_batches for x in batch_info ] |
45 | | -elif par["method"] == "random": |
46 | | - train_ix = np.random.choice(adata.n_obs, round(adata.n_obs * 0.8), replace=False) |
47 | | - is_test = [ not x in train_ix for x in range(0, adata.n_obs) ] |
48 | | - |
49 | | -# subset the different adatas |
50 | | -print(">> Figuring which data needs to be copied to which output file", flush=True) |
51 | | -# use par arguments to look for label and batch value in different slots |
| 42 | +# map the source slots of the common dataset onto the dest slots expected by the |
| 43 | +# task-specific file formats (file_dataset.yaml / file_solution.yaml) |
52 | 44 | slot_mapping = { |
| 45 | + "layers": { |
| 46 | + "counts": par["layer_counts"], |
| 47 | + }, |
53 | 48 | "obs": { |
54 | | - "label": par["obs_label"], |
| 49 | + "cell_type": par["obs_label"], |
55 | 50 | "batch": par["obs_batch"], |
56 | | - } |
| 51 | + "pseudotime_true": par["obs_ptime"], |
| 52 | + }, |
| 53 | + "obsm": { |
| 54 | + "X_spatial": par["obsm_spatial"], |
| 55 | + }, |
57 | 56 | } |
58 | 57 |
|
59 | | -print(">> Creating train data", flush=True) |
60 | | -output_train = subset_h5ad_by_format( |
61 | | - adata[[not x for x in is_test]], |
62 | | - config, |
63 | | - "output_train", |
64 | | - slot_mapping |
65 | | -) |
66 | | - |
67 | | -print(">> Creating test data", flush=True) |
68 | | -output_test = subset_h5ad_by_format( |
69 | | - adata[is_test], |
| 58 | +print(">> Creating input data for the methods", flush=True) |
| 59 | +output_dataset = subset_h5ad_by_format( |
| 60 | + input, |
70 | 61 | config, |
71 | | - "output_test", |
| 62 | + "output_dataset", |
72 | 63 | slot_mapping |
73 | 64 | ) |
74 | 65 |
|
75 | 66 | print(">> Creating solution data", flush=True) |
76 | 67 | output_solution = subset_h5ad_by_format( |
77 | | - adata[is_test], |
| 68 | + input, |
78 | 69 | config, |
79 | 70 | "output_solution", |
80 | 71 | slot_mapping |
81 | 72 | ) |
82 | 73 |
|
83 | 74 | print(">> Writing data", flush=True) |
84 | | -output_train.write_h5ad(par["output_train"]) |
85 | | -output_test.write_h5ad(par["output_test"]) |
| 75 | +output_dataset.write_h5ad(par["output_dataset"]) |
86 | 76 | output_solution.write_h5ad(par["output_solution"]) |
0 commit comments