Skip to content

add cycombine no controls #35

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

Merged
merged 3 commits into from
Mar 8, 2025
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

* Added `metrics/n_inconsistent_peaks` + some new helper functions (PR #31)

* Added `methods/cycombine_nocontrol` (PR #35).

## MAJOR CHANGES

* Updated file schema (PR #18):
Expand Down
41 changes: 41 additions & 0 deletions src/methods/cycombine_nocontrols/config.vsh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
__merge__: ../../api/comp_method.yaml

name: cycombine_nocontrols
label: cyCombine (no-controls)
summary: "cyCombine perform batch correction by using self-organizing maps and ComBat."
description: |
cyCombine perform batch integration by first using self-organizing maps (SOM) to
group similar cells, then applies a ComBat-based method to correct batch effects within
each group of similar cells.

Here, we run cyCombine without control samples (replicates in cyCombine terminology).
references:
doi:
- 10.1038/s41467-022-29383-5
links:
documentation: https://biosurf.org/cyCombine.html
repository: https://github.com/biosurf/cyCombine

resources:
# The script of your component (required)
- type: r_script
path: script.R
# Additional resources your script needs (optional)
# - type: file
# path: weights.pt

engines:
- type: docker
image: openproblems/base_r:1.0.0
# Add custom dependencies here (optional). For more information, see
# https://viash.io/reference/config/engines/docker/#setup .
setup:
- type: r
bioc: [sva]
github: [biosurf/cyCombine]

runners:
- type: executable
- type: nextflow
directives:
label: [midtime,midmem,midcpu]
61 changes: 61 additions & 0 deletions src/methods/cycombine_nocontrols/script.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
library(anndata)
requireNamespace("cyCombine", quietly = TRUE)

## VIASH START
par <- list(
input = "resources_test/task_cyto_batch_integration/starter_file/unintegrated_censored.h5ad",
output = "resources_test/task_cyto_batch_integration/starter_file/output.h5ad"
)
meta <- list(name = "cycombine")
## VIASH END

cat("Reading input files\n")
input_adata <- anndata::read_h5ad(par[["input"]])

cat("Preparing input Anndata and df\n")

adata_to_correct <- input_adata[, input_adata$var$to_correct]

markers_to_correct <- input_adata$var_names[input_adata$var$to_correct]

df_to_correct <- as.data.frame(
adata_to_correct$layers[["preprocessed"]],
check.names=FALSE
)
df_to_correct$batch <- adata_to_correct$obs$batch
df_to_correct$sample <- adata_to_correct$obs$sample

cat("Run cyCombine\n")
df_corrected <- cyCombine::batch_correct(
df = df_to_correct,
seed = 42,
markers = markers_to_correct
)

cat("Preparing output Anndata\n")
df_not_corrected <- as.data.frame(
input_adata[, !input_adata$var$to_correct]$layers[["preprocessed"]]
)

df_output <- cbind(
df_corrected[, markers_to_correct],
df_not_corrected
)

# reorder column to match input_adata
df_output <- df_output[, input_adata$var_names]

output <- anndata::AnnData(
obs = input_adata$obs[, integer(0)],
var = input_adata$var[colnames(df_output), integer(0)],
layers = list(integrated = df_output),
uns = list(
dataset_id = input_adata$uns$dataset_id,
method_id = meta$name,
parameters = list()
)
)

cat("Write output AnnData to file\n")

output$write_h5ad(par[["output"]], compression = "gzip")
1 change: 1 addition & 0 deletions src/workflows/run_benchmark/config.vsh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ dependencies:
- name: methods/harmonypy
- name: methods/limma_remove_batch_effect
- name: methods/combat
- name: methods/cycombine_nocontrols
- name: metrics/emd
- name: metrics/n_inconsistent_peaks

Expand Down
3 changes: 2 additions & 1 deletion src/workflows/run_benchmark/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ methods = [
limma_remove_batch_effect,
no_integration,
perfect_integration,
combat
combat,
cycombine_nocontrols
]

// construct list of metrics
Expand Down