Skip to content

Commit 04a4280

Browse files
committed
update cycombine
1 parent fa20205 commit 04a4280

5 files changed

Lines changed: 53 additions & 15 deletions

File tree

src/methods/cycombine_no_controls_to_goal/config.vsh.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ resources:
4848
# The script of your component (required)
4949
- type: r_script
5050
path: script.R
51-
# Additional resources your script needs (optional)
52-
# - type: file
53-
# path: weights.pt
51+
- type: r_script
52+
path: /src/utils/helper_functions.R
5453

5554
engines:
5655
- type: docker

src/methods/cycombine_no_controls_to_goal/script.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@ requireNamespace("cyCombine", quietly = TRUE)
33

44
## VIASH START
55
par <- list(
6-
input = "resources_test/task_cyto_batch_integration/mouse_spleen_flow_cytometry_subset/unintegrated_censored.h5ad",
7-
output = "resources_test/task_cyto_batch_integration/mouse_spleen_flow_cytometry_subset/output.h5ad",
8-
som_grid_size = 8,
6+
input = "resources_test/task_cyto_batch_integration/mouse_spleen_flow_cytometry_subset/censored_split1.h5ad",
7+
output = "resources_test/task_cyto_batch_integration/mouse_spleen_flow_cytometry_subset/output_split1.h5ad",
8+
som_grid_size = 4,
99
rlen = 10
1010
)
11-
meta <- list(name = "cycombine_no_controls")
11+
meta <- list(
12+
name = "cycombine_no_controls_to_goal",
13+
resources_dir = "src/utils"
14+
)
1215
## VIASH END
1316

17+
source(paste0(meta$resources_dir, "/helper_functions.R"))
18+
1419
cat("Reading input files\n")
15-
input_adata <- anndata::read_h5ad(par[["input"]])
20+
input_adata <- anndata::read_h5ad(par[["input"]]) |>
21+
subset_nocontrols()
1622

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

src/methods/cycombine_one_control_to_goal/config.vsh.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ resources:
5858
# The script of your component (required)
5959
- type: r_script
6060
path: script.R
61-
# Additional resources your script needs (optional)
62-
# - type: file
63-
# path: weights.pt
61+
- type: r_script
62+
path: /src/utils/helper_functions.R
6463

6564
engines:
6665
- type: docker

src/methods/cycombine_one_control_to_goal/script.R

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@ requireNamespace("anndata", quietly = TRUE)
33

44
## VIASH START
55
par <- list(
6-
input = "resources_test/task_cyto_batch_integration/leomazzi_cyto_spleen_subset/unintegrated_censored.h5ad",
7-
output = "resources_test/task_cyto_batch_integration/leomazzi_cyto_spleen_subset/output.h5ad"
6+
input = "resources_test/task_cyto_batch_integration/mouse_spleen_flow_cytometry_subset/censored_split1.h5ad",
7+
output = "resources_test/task_cyto_batch_integration/mouse_spleen_flow_cytometry_subset/output_split1.h5ad",
8+
som_grid_size = 4,
9+
rlen = 10
10+
)
11+
meta <- list(
12+
name = "cycombine_one_control_to_goal",
13+
resources_dir = "src/utils"
814
)
9-
meta <- list(name = "cycombine_one_control")
1015
## VIASH END
1116

17+
source(paste0(meta$resources_dir, "/helper_functions.R"))
18+
1219
cat("Reading input files\n")
13-
input_adata <- anndata::read_h5ad(par[["input"]])
20+
input_adata <- anndata::read_h5ad(par[["input"]]) |>
21+
subset_onecontrol()
1422

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

src/utils/helper_functions.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,32 @@ subset_nocontrols <- function(adata) {
8989
adata[adata$obs$is_control == 0, ]
9090
}
9191

92+
93+
#' Subset AnnData Object to Single Control
94+
#'
95+
#' @description
96+
#' Extracts no control samples and just one control sample from an AnnData object based on the specified index.
97+
#'
98+
#' @param adata An AnnData object containing multiple samples with control groups.
99+
#' @param which_control Integer specifying which control sample to extract (default: 1).
100+
#'
101+
#' @return
102+
#' An AnnData object subset to contain only the specified control sample.
103+
#'
104+
#' @examples
105+
#' \dontrun{
106+
#' control_sample <- subset_onecontrol(adata, which_control = 1)
107+
#' }
108+
#'
109+
subset_onecontrol <- function(adata, which_control = 1) {
110+
if (!"is_control" %in% colnames(adata$obs)) {
111+
stop("The column 'is_control' is not present in the adata object.")
112+
}
113+
114+
# Subset the adata to keep cells where is_control == which_control
115+
adata[adata$obs$is_control %in% c(which_control, 0), ]
116+
}
117+
92118
#' Subsets the anndata object to only include markers that need to be
93119
#' (or have been) corrected.
94120
#' These markers are all the entries in adata.var where to_correct == TRUE.

0 commit comments

Comments
 (0)