Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tacco #15

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/methods_cell_type_annotation/tacco/config.vsh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
__merge__: /src/api/comp_method_cell_type_annotation.yaml

name: tacco
label: "Tacco"
summary: "Annotate cell types using Tacco"
description: "Annotate cell types using Tacco"
links:
documentation: "https://simonwm.github.io/tacco/"
repository: "https://github.com/simonwm/tacco"
references:
doi: "10.1038/s41587-023-01657-3"

resources:
- type: python_script
path: script.py

engines:
- type: docker
image: openproblems/base_python:1.0.0
setup:
- type: python
pypi: [anndata, numpy, tacco]
- type: native

runners:
- type: executable
- type: nextflow
directives:
label: [ midtime, midcpu, midmem ]
44 changes: 44 additions & 0 deletions src/methods_cell_type_annotation/tacco/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3

import anndata as ad
import numpy as np
import tacco

## VIASH START
par = {
'input_spatial_normalized_counts': 'resources_test/task_ist_preprocessing/mouse_brain_combined/spatial_normalized_counts.h5ad',
'input_scrnaseq_reference': 'resources_test/task_ist_preprocessing/mouse_brain_combined/scrnaseq_reference.h5ad',
'output': 'spatial_with_celltypes.h5ad',
'celltype_key': 'cell_type',
}
meta = {
'name': 'tacco',
}
## VIASH END

# Optional parameter check: For this specific annotation method the par['input_spatial_normalized_counts'] and par['input_scrnaseq_reference'] are required
assert par['input_spatial_normalized_counts'] is not None, 'Spatial input is required for this annotation method.'
assert par['input_scrnaseq_reference'] is not None, 'Single cell input is required for this annotation method.'

# Read input
adata_sp = ad.read_h5ad(par['input_spatial_normalized_counts'])
adata_sc = ad.read_h5ad(par['input_scrnaseq_reference'])

# Switch to raw counts
adata_sp.X = adata_sp.layers['counts']
adata_sc.X = adata_sc.layers['counts']

# Run tacco
cell_type_assignment = tacco.tl.annotate(
adata=adata_sp,
reference=adata_sc,
annotation_key=par['celltype_key']
)

# Tacco stores the cell type proportions in a n_obs x n_celltypes matrix, so we have to extract the celltype with highest consensus
cell_types = cell_type_assignment.columns
highest_score_idx = np.argmax(cell_type_assignment, axis=1)
adata_sp.obs[par['celltype_key']] = cell_types[highest_score_idx]

# Write output
adata_sp.write_h5ad(par['output'])