Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 38 additions & 0 deletions src/methods_cell_type_annotation/singler/config.vsh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
__merge__: /src/api/comp_method_cell_type_annotation.yaml

name: singler
label: "singler"
summary: "Cell type annotations using single-cell reference with SingleR"
description: "Cell type annotations using single-cell reference with SingleR"

links:
documentation: "https://github.com/openproblems-bio/task_ist_preprocessing"
Comment thread
LouisK92 marked this conversation as resolved.
Outdated
repository: "https://github.com/openproblems-bio/task_ist_preprocessing"
references:
doi: "10.1038/s41590-018-0276-y"

arguments:
- name: --labels_key
type: string
description: The key of the cell labels in the input data.
default: cell_labels

resources:
- type: python_script
path: script.py

engines:
- type: docker
image: openproblems/base_python:1
setup:
- type: python
pypi: [singler]
__merge__:
- /src/base/setup_spatialdata_partial.yaml
Comment thread
LouisK92 marked this conversation as resolved.
- type: native

runners:
- type: executable
- type: nextflow
directives:
label: [ midtime, lowcpu, lowmem ]
Comment thread
LouisK92 marked this conversation as resolved.
Outdated
69 changes: 69 additions & 0 deletions src/methods_cell_type_annotation/singler/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import anndata as ad
import os
import shutil

import singlecellexperiment as sce
import singler

## VIASH START
# The following code has been auto-generated by Viash.
par = {
'input_spatial_normalized_counts': r'resources_test/task_ist_preprocessing/mouse_brain_combined/spatial_normalized_counts.h5ad',
'input_transcript_assignments': r'resources_test/task_ist_preprocessing/mouse_brain_combined/transcript_assignments.zarr',
'input_scrnaseq_reference': r'resources_test/task_ist_preprocessing/mouse_brain_combined/scrnaseq_reference.h5ad',
'celltype_key': r'cell_type',
'output': r'resources_test/task_ist_preprocessing/mouse_brain_combined/spatial_with_cell_types.h5ad',
'labels_key': r'cell_labels'
}
meta = {
'name': r'singleR',
'functionality_name': r'singleR',
'resources_dir': r'/private/tmp/viash_inject_singleR6465161111175259990',
Comment thread
LouisK92 marked this conversation as resolved.
Outdated
'executable': r'/private/tmp/viash_inject_singleR6465161111175259990/singleR',
'config': r'/private/tmp/viash_inject_singleR6465161111175259990/.config.vsh.yaml',
'temp_dir': r'/var/folders/fq/ymt0vml175s4yvqxzbmlmpz80000gn/T/',
'cpus': int(r'123'),
'memory_b': int(r'123'),
'memory_kb': int(r'123'),
'memory_mb': int(r'123'),
'memory_gb': int(r'123'),
'memory_tb': int(r'123'),
'memory_pb': int(r'123'),
'memory_kib': int(r'123'),
'memory_mib': int(r'123'),
'memory_gib': int(r'123'),
'memory_tib': int(r'123'),
'memory_pib': int(r'123')
}
dep = {

}

## VIASH END
sce_h5ad = sce.read_h5ad(par['input_spatial_normalized_counts'])
adata_sp = ad.read_h5ad(par['input_spatial_normalized_counts'])

sce_ref = sce.read_h5ad(par['input_scrnaseq_reference'])

features = [str(x) for x in sce_h5ad.row_data.row_names]

mat = sce_h5ad.assay("counts") ##example has raw, not sure
Comment thread
LouisK92 marked this conversation as resolved.
mat = mat.sorted_indices() ## magic line to make sure the matrix is in the right format for SingleR

mat_ref = sce_ref.assay("normalized")
mat_ref = mat_ref.sorted_indices() ## magic line to make sure the matrix is in the right format for SingleR

## create the reference from our sc data
built = singler.train_single(ref_data = mat_ref,
ref_labels = sce_ref.get_column_data().column("cell_type"),
ref_features = sce_ref.get_row_names(),
test_features = features,)

## annotate the dataset
output = singler.classify_single(mat, ref_prebuilt=built)

adata_sp.obs["cell_type"] = output['best']

# Write output
print('Writing output', flush=True)
adata_sp.write(par['output'])