Skip to content

Commit 687668d

Browse files
committed
data processor builds
1 parent 0187f10 commit 687668d

8 files changed

Lines changed: 93 additions & 103 deletions

File tree

src/api/comp_control_method.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ test_resources:
2929
path: /common/component_tests/run_and_check_output.py
3030
- type: python_script
3131
path: /common/component_tests/check_config.py
32-
- path: /resources_test/task_template/cxg_mouse_pancreas_atlas
33-
dest: resources_test/task_template/cxg_mouse_pancreas_atlas
32+
- path: /resources_test/common/cxg_mouse_pancreas_atlas
33+
dest: resources_test/common/cxg_mouse_pancreas_atlas

src/api/comp_data_processor.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ arguments:
1111
__merge__: file_common_dataset.yaml
1212
direction: input
1313
required: true
14-
- name: "--output"
14+
- name: "--output_dataset"
1515
__merge__: file_dataset.yaml
1616
direction: output
1717
required: true

src/api/comp_method.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ test_resources:
2020
path: /common/component_tests/run_and_check_output.py
2121
- type: python_script
2222
path: /common/component_tests/check_config.py
23-
- path: /resources_test/task_template/cxg_mouse_pancreas_atlas
24-
dest: resources_test/task_template/cxg_mouse_pancreas_atlas
23+
- path: /resources_test/common/cxg_mouse_pancreas_atlas
24+
dest: resources_test/common/cxg_mouse_pancreas_atlas

src/api/comp_metric.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ test_resources:
2424
path: /common/component_tests/run_and_check_output.py
2525
- type: python_script
2626
path: /common/component_tests/check_config.py
27-
- path: /resources_test/task_template/cxg_mouse_pancreas_atlas
28-
dest: resources_test/task_template/cxg_mouse_pancreas_atlas
27+
- path: /resources_test/common/cxg_mouse_pancreas_atlas
28+
dest: resources_test/common/cxg_mouse_pancreas_atlas

src/api/file_dataset.yaml

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,28 @@
1-
#TODO: Change to the required and/or optional fields of the anndata
21
type: file
3-
example: "resources_test/task_template/cxg_mouse_pancreas_atlas/train.h5ad" # maybe adjust this after syncing resources
2+
example: "resources_test/task_spatial_trajectory_inference/cxg_mouse_pancreas_atlas/dataset.h5ad"
43
label: "Input data"
5-
summary: "The input data for the spatial TI task"
4+
summary: "The input data for the spatial TI methods"
65
info:
76
format:
87
type: h5ad
9-
layers:
8+
layers:
109
- type: integer
1110
name: counts
1211
description: Raw counts
1312
required: true
14-
- type: double
15-
name: normalized
16-
description: Normalized counts
17-
required: true
1813
obs:
1914
- type: string
20-
name: label
21-
description: Ground truth cell type labels
15+
name: cell_type
16+
description: Cell type information
2217
required: true
2318
- type: string
2419
name: batch
2520
description: Batch information
2621
required: true
27-
var:
28-
- type: boolean
29-
name: hvg
30-
description: Whether or not the feature is considered to be a 'highly variable gene'
31-
required: true
32-
- type: double
33-
name: hvg_score
34-
description: A ranking of the features by hvg.
35-
required: true
3622
obsm:
3723
- type: double
38-
name: X_pca
39-
description: The resulting PCA embedding.
24+
name: X_spatial
25+
description: Spatial coordinates of each cell/spot.
4026
required: true
4127
uns:
4228
- type: string
@@ -46,4 +32,4 @@ info:
4632
- type: string
4733
name: normalization_id
4834
description: "Which normalization was used"
49-
required: true
35+
required: true

src/api/file_solution.yaml

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,32 @@
1-
#TODO: Change to the required and/or optional fields of the anndata
21
type: file
3-
example: "resources_test/task_template/cxg_mouse_pancreas_atlas/solution.h5ad"
2+
example: "resources_test/task_spatial_trajectory_inference/cxg_mouse_pancreas_atlas/solution.h5ad"
43
label: "Solution"
5-
summary: "The solution for the test data"
4+
summary: "The solution (ground truth) for the test data"
65
info:
76
format:
87
type: h5ad
9-
layers:
8+
layers:
109
- type: integer
1110
name: counts
1211
description: Raw counts
1312
required: true
14-
- type: double
15-
name: normalized
16-
description: Normalized counts
17-
required: true
1813
obs:
1914
- type: string
20-
name: label
21-
description: Ground truth cell type labels
15+
name: cell_type
16+
description: Cell type information
2217
required: true
2318
- type: string
2419
name: batch
2520
description: Batch information
2621
required: true
27-
var:
28-
- type: boolean
29-
name: hvg
30-
description: Whether or not the feature is considered to be a 'highly variable gene'
31-
required: true
3222
- type: double
33-
name: hvg_score
34-
description: A ranking of the features by hvg.
23+
name: pseudotime_true
24+
description: Ground truth pseudotime for each cell/spot.
3525
required: true
3626
obsm:
3727
- type: double
38-
name: X_pca
39-
description: The resulting PCA embedding.
28+
name: X_spatial
29+
description: Spatial coordinates of each cell/spot.
4030
required: true
4131
uns:
4232
- type: string
Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
11
__merge__: ../../api/comp_data_processor.yaml
22
name: process_dataset
3-
arguments:
4-
- name: "--method"
5-
type: "string"
6-
description: "The process method to assign train/test."
7-
choices: ["batch", "random"]
8-
default: "batch"
9-
- name: "--obs_label"
10-
type: "string"
11-
description: "Which .obs slot to use as label."
12-
default: "cell_type"
13-
- name: "--obs_batch"
14-
type: "string"
15-
description: "Which .obs slot to use as batch covariate."
16-
default: "batch"
17-
- name: "--seed"
18-
type: "integer"
19-
description: "A seed for the subsampling."
20-
example: 123
3+
namespace: data_processors
4+
5+
info:
6+
label: Process dataset
7+
summary: "Filter and split a common dataset into task-specific data and solution files."
8+
9+
argument_groups:
10+
- name: Parameters
11+
arguments:
12+
- name: "--dataset_id"
13+
type: "string"
14+
description: "New dataset ID"
15+
required: false
16+
- name: "--obs_label"
17+
type: "string"
18+
description: "Which .obs slot to use as label."
19+
default: "cell_type"
20+
- name: "--obs_batch"
21+
type: "string"
22+
description: "Which .obs slot to use as batch covariate."
23+
default: "batch"
24+
- name: "--obs_ptime"
25+
type: "string"
26+
description: "Which .obs slot to use as pseudotime covariate."
27+
default: "pseudotime_true"
28+
- name: "--obsm_spatial"
29+
type: "string"
30+
description: "Which .obsm slot to use as spatial metadata."
31+
default: "X_spatial"
32+
- name: "--layer_counts"
33+
type: "string"
34+
description: "Which .layers slot to use as counts."
35+
default: "counts"
36+
- name: "--seed"
37+
type: "integer"
38+
description: "The seed for." # TODO for what..?
39+
default: 1
40+
2141
resources:
2242
- type: python_script
2343
path: script.py
@@ -31,4 +51,8 @@ runners:
3151
- type: executable
3252
- type: nextflow
3353
directives:
34-
label: [highmem, midcpu, midtime]
54+
label: [highmem, midcpu, midtime]
55+
56+
test_resources:
57+
- path: /resources_test/common/cxg_mouse_pancreas_atlas
58+
dest: resources_test/common/cxg_mouse_pancreas_atlas

src/data_processors/process_dataset/script.py

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
## VIASH START
88
par = {
99
'input': 'resources_test/common/cxg_mouse_pancreas_atlas/dataset.h5ad',
10-
'method': 'batch',
1110
'seed': None,
1211
'obs_batch': 'batch',
1312
'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',
1617
'output_solution': 'solution.h5ad'
1718
}
1819
meta = {
@@ -25,62 +26,51 @@
2526
sys.path.append(meta['resources_dir'])
2627
from subset_h5ad_by_format import subset_h5ad_by_format
2728

29+
# read viash config
2830
config = op.project.read_viash_config(meta["config"])
2931

3032
# set seed if need be
3133
if par["seed"]:
32-
print(f">> Setting seed to {par['seed']}")
34+
print(f">> Setting seed to {par['seed']}", flush=True)
3335
random.seed(par["seed"])
3436

37+
# read the dataset
3538
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)
3841

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)
5244
slot_mapping = {
45+
"layers": {
46+
"counts": par["layer_counts"],
47+
},
5348
"obs": {
54-
"label": par["obs_label"],
49+
"cell_type": par["obs_label"],
5550
"batch": par["obs_batch"],
56-
}
51+
"pseudotime_true": par["obs_ptime"],
52+
},
53+
"obsm": {
54+
"X_spatial": par["obsm_spatial"],
55+
},
5756
}
5857

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,
7061
config,
71-
"output_test",
62+
"output_dataset",
7263
slot_mapping
7364
)
7465

7566
print(">> Creating solution data", flush=True)
7667
output_solution = subset_h5ad_by_format(
77-
adata[is_test],
68+
input,
7869
config,
7970
"output_solution",
8071
slot_mapping
8172
)
8273

8374
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"])
8676
output_solution.write_h5ad(par["output_solution"])

0 commit comments

Comments
 (0)