-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
12 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,43 @@ | ||
import anndata as ad | ||
import sklearn.linear_model | ||
|
||
## VIASH START | ||
# Note: this section is auto-generated by viash at runtime. To edit it, make changes | ||
# in config.vsh.yaml and then run `viash config inject config.vsh.yaml`. | ||
par = { | ||
'train_h5ad': 'resources_test/task_template/pancreas/train_h5ad.h5ad', | ||
'test_h5ad': 'resources_test/task_template/pancreas/test_h5ad.h5ad', | ||
'input_train': 'resources_test/task_template/pancreas/train.h5ad', | ||
'input_test': 'resources_test/task_template/pancreas/test.h5ad', | ||
'output': 'output.h5ad' | ||
} | ||
meta = { | ||
'name': 'my_control_method' | ||
'name': 'logistic_regression' | ||
} | ||
## VIASH END | ||
|
||
print('Reading input files', flush=True) | ||
train_h5ad = ad.read_h5ad(par['train_h5ad']) | ||
test_h5ad = ad.read_h5ad(par['test_h5ad']) | ||
input_train = ad.read_h5ad(par['input_train']) | ||
input_test = ad.read_h5ad(par['input_test']) | ||
|
||
print('Preprocess data', flush=True) | ||
# ... preprocessing ... | ||
|
||
print('Train model', flush=True) | ||
# ... train model ... | ||
classifier = sklearn.linear_model.LogisticRegression() | ||
classifier.fit(input_train.obsm["X_pca"], input_train.obs["label"].astype(str)) | ||
|
||
print('Generate predictions', flush=True) | ||
# ... generate predictions ... | ||
obs = classifier.predict(input_test.obsm["X_pca"]) | ||
|
||
print("Write output AnnData to file", flush=True) | ||
output = ad.AnnData( | ||
uns={ | ||
'dataset_id': train_h5ad.uns['dataset_id'], | ||
'dataset_id': input_train.uns['dataset_id'], | ||
'method_id': meta['name'] | ||
}, | ||
layers={ | ||
'prediction': layers_prediction | ||
obs={ | ||
'label_pred': obs | ||
} | ||
) | ||
output.write_h5ad(par['output'], compression='gzip') |