-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from nf-core/16-implement-doubletdetection-dou…
…blet-detection Implement doubletdetection doublet detection
- Loading branch information
Showing
10 changed files
with
109 additions
and
5 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
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
modules/local/doublet_detection/doubletdetection/environment.yml
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,10 @@ | ||
name: doubletdetection | ||
channels: | ||
- conda-forge | ||
- bioconda | ||
dependencies: | ||
- conda-forge::anndata=0.10.7 | ||
- conda-forge::louvain=0.8.2 | ||
- pip | ||
- pip: | ||
- doubletdetection==4.2 |
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,24 @@ | ||
process DOUBLETDETECTION { | ||
tag "$meta.id" | ||
label 'process_medium' | ||
|
||
conda "${moduleDir}/environment.yml" | ||
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? | ||
'oras://community.wave.seqera.io/library/anndata_louvain_pip_doubletdetection:42d2326cc250350b': | ||
'community.wave.seqera.io/library/anndata_louvain_pip_doubletdetection:cbe92394c10372fa' }" | ||
|
||
input: | ||
tuple val(meta), path(h5ad) | ||
|
||
output: | ||
tuple val(meta), path("*.h5ad"), emit: h5ad | ||
tuple val(meta), path("*.pkl") , emit: predictions | ||
path "versions.yml" , emit: versions | ||
|
||
when: | ||
task.ext.when == null || task.ext.when | ||
|
||
script: | ||
prefix = task.ext.prefix ?: "${meta.id}" | ||
template 'doubletdetection.py' | ||
} |
59 changes: 59 additions & 0 deletions
59
modules/local/doublet_detection/doubletdetection/templates/doubletdetection.py
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,59 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Set numba cache to /tmp | ||
# This is not an ideal solution | ||
import os | ||
os.environ["NUMBA_CACHE_DIR"] = "/tmp" | ||
|
||
import anndata as ad | ||
import doubletdetection | ||
import platform | ||
|
||
def format_yaml_like(data: dict, indent: int = 0) -> str: | ||
"""Formats a dictionary to a YAML-like string. | ||
Args: | ||
data (dict): The dictionary to format. | ||
indent (int): The current indentation level. | ||
Returns: | ||
str: A string formatted as YAML. | ||
""" | ||
yaml_str = "" | ||
for key, value in data.items(): | ||
spaces = " " * indent | ||
if isinstance(value, dict): | ||
yaml_str += f"{spaces}{key}:\\n{format_yaml_like(value, indent + 1)}" | ||
else: | ||
yaml_str += f"{spaces}{key}: {value}\\n" | ||
return yaml_str | ||
|
||
adata = ad.read_h5ad("${h5ad}") | ||
|
||
counts = adata.layers["counts"] | ||
|
||
clf = doubletdetection.BoostClassifier() | ||
doublets = clf.fit(counts).predict() | ||
scores = clf.doublet_score() | ||
|
||
adata.obs["doublet"] = [label == 1 for label in doublets] | ||
adata.obs["doublet_score"] = scores | ||
|
||
adata.write_h5ad("${prefix}.h5ad") | ||
|
||
df = adata.obs[["doublet"]] | ||
df.columns = ["${prefix}"] | ||
df.to_pickle("${prefix}.pkl") | ||
|
||
# Versions | ||
|
||
versions = { | ||
"${task.process}": { | ||
"python": platform.python_version(), | ||
"anndata": ad.__version__, | ||
"doubletdetection": doubletdetection.__version__, | ||
} | ||
} | ||
|
||
with open("versions.yml", "w") as f: | ||
f.write(format_yaml_like(versions)) |
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