Skip to content

Commit

Permalink
Create working components [WIP]:
Browse files Browse the repository at this point in the history
Update control_method script
  • Loading branch information
KaiWaldrant committed Jul 10, 2024
1 parent 2aca120 commit 045c4b1
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/control_methods/my_control_method/script.py
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')

0 comments on commit 045c4b1

Please sign in to comment.