File tree Expand file tree Collapse file tree
src/methods_cell_type_annotation/tacco Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ __merge__ : /src/api/comp_method_cell_type_annotation.yaml
2+
3+ name : tacco
4+ label : " Tacco"
5+ summary : " Annotate cell types using Tacco"
6+ description : " Annotate cell types using Tacco"
7+ links :
8+ documentation : " https://simonwm.github.io/tacco/"
9+ repository : " https://github.com/simonwm/tacco"
10+ references :
11+ doi : " 10.1038/s41587-023-01657-3"
12+
13+ resources :
14+ - type : python_script
15+ path : script.py
16+
17+ engines :
18+ - type : docker
19+ image : openproblems/base_python:1.0.0
20+ setup :
21+ - type : python
22+ pypi : [anndata, numpy, tacco]
23+ - type : native
24+
25+ runners :
26+ - type : executable
27+ - type : nextflow
28+ directives :
29+ label : [ midtime, midcpu, midmem ]
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+
3+ import anndata as ad
4+ import numpy as np
5+ import tacco
6+
7+ ## VIASH START
8+ par = {
9+ 'input_spatial_normalized_counts' : 'resources_test/task_ist_preprocessing/mouse_brain_combined/spatial_normalized_counts.h5ad' ,
10+ 'input_scrnaseq_reference' : 'resources_test/task_ist_preprocessing/mouse_brain_combined/scrnaseq_reference.h5ad' ,
11+ 'output' : 'spatial_with_celltypes.h5ad' ,
12+ 'celltype_key' : 'cell_type' ,
13+ }
14+ meta = {
15+ 'name' : 'tacco' ,
16+ }
17+ ## VIASH END
18+
19+ # Optional parameter check: For this specific annotation method the par['input_spatial_normalized_counts'] and par['input_scrnaseq_reference'] are required
20+ assert par ['input_spatial_normalized_counts' ] is not None , 'Spatial input is required for this annotation method.'
21+ assert par ['input_scrnaseq_reference' ] is not None , 'Single cell input is required for this annotation method.'
22+
23+ # Read input
24+ adata_sp = ad .read_h5ad (par ['input_spatial_normalized_counts' ])
25+ adata_sc = ad .read_h5ad (par ['input_scrnaseq_reference' ])
26+
27+ # Switch to raw counts
28+ adata_sp .X = adata_sp .layers ['counts' ]
29+ adata_sc .X = adata_sc .layers ['counts' ]
30+
31+ # Run tacco
32+ cell_type_assignment = tacco .tl .annotate (
33+ adata = adata_sp ,
34+ reference = adata_sc ,
35+ annotation_key = par ['celltype_key' ]
36+ )
37+
38+ # Tacco stores the cell type proportions in a n_obs x n_celltypes matrix, so we have to extract the celltype with highest consensus
39+ cell_types = cell_type_assignment .columns
40+ highest_score_idx = np .argmax (cell_type_assignment , axis = 1 )
41+ adata_sp .obs [par ['celltype_key' ]] = cell_types [highest_score_idx ]
42+
43+ # Write output
44+ adata_sp .write_h5ad (par ['output' ])
You can’t perform that action at this time.
0 commit comments