generated from openproblems-bio/task_template
-
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
Showing
2 changed files
with
57 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
__merge__: /src/api/comp_transformer.yaml | ||
name: transform | ||
label: Transform outputs | ||
summary: Transform batch integration outputs where necessary | ||
description: | | ||
Transform corrected feature output to an embedding, and an embedding to a graph output. | ||
resources: | ||
- type: python_script | ||
path: script.py | ||
engines: | ||
- type: docker | ||
image: openproblems/base_python:1.0.0 | ||
setup: | ||
- type: python | ||
pypi: scanpy | ||
runners: | ||
- type: executable | ||
- type: nextflow | ||
directives: | ||
label: [midtime, midmem, lowcpu] |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import anndata as ad | ||
import scanpy as sc | ||
|
||
## VIASH START | ||
par = { | ||
'input': 'resources_test/task_batch_integration/cxg_mouse_pancreas_atlas/integrated.h5ad', | ||
'ouput': 'output.h5ad' | ||
} | ||
## VIASH END | ||
|
||
print('Read input', flush=True) | ||
adata = ad.read_h5ad(par['input']) | ||
|
||
assert 'corrected_counts' in adata.layers.keys() or \ | ||
'X_emb' in adata.obsm.keys() or \ | ||
'neighbors' in adata.uns.keys(), \ | ||
"Input data is missing necessary information. " \ | ||
"Expected 'corrected_counts' in layers, " \ | ||
"'X_emb' in obsm, or 'neighbors' in uns.\n" \ | ||
f"Found: {adata}" | ||
|
||
if 'X_emb' not in adata.obsm: | ||
print('Run PCA...', flush=True) | ||
adata.obsm['X_emb'] = sc.pp.pca( | ||
adata.layers['corrected_counts'], | ||
n_comps=50, | ||
use_highly_variable=False, | ||
svd_solver='arpack', | ||
return_info=False | ||
) | ||
|
||
if 'neighbors' not in adata.uns: | ||
print('Run kNN...', flush=True) | ||
sc.pp.neighbors(adata, use_rep='X_emb') | ||
|
||
print("Store outputs", flush=True) | ||
adata.write_h5ad(par['output'], compression='gzip') |