-
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.
- Loading branch information
1 parent
3be418b
commit 8fbc4d1
Showing
2 changed files
with
28 additions
and
18 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
19 changes: 13 additions & 6 deletions
19
src/methods/my_method/script.py → src/methods/logistic_regression/script.py
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,37 +1,44 @@ | ||
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', | ||
'input_train': 'resources_test/task_template/pancreas/train.h5ad', | ||
'input_test': 'resources_test/task_template/pancreas/test.h5ad', | ||
'output': 'output.h5ad' | ||
} | ||
meta = { | ||
'name': 'my_method' | ||
'name': 'logistic_regression' | ||
} | ||
## VIASH END | ||
|
||
print('Reading input files', flush=True) | ||
train_h5ad = ad.read_h5ad(par['train_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_label_pred = 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'], | ||
'normalization_id': input_train.uns['normalization_id'], | ||
'method_id': meta['name'] | ||
}, | ||
layers={ | ||
'prediction': layers_prediction | ||
obs={ | ||
'label_pred': obs_label_pred | ||
} | ||
) | ||
output.write_h5ad(par['output'], compression='gzip') |