Skip to content

Commit

Permalink
add transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
rcannood committed Sep 21, 2024
1 parent 2475ed7 commit 6a1cc58
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/transformers/transform/config.vsh.yaml
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]
37 changes: 37 additions & 0 deletions src/transformers/transform/script.py
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')

0 comments on commit 6a1cc58

Please sign in to comment.