Skip to content

Commit facc520

Browse files
committed
update batchadjust and add copy to subset
1 parent f4bff8d commit facc520

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/methods/batchadjust_one_control/config.vsh.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ resources:
6767
- path: /src/utils/anndata_to_fcs.R
6868
- path: BatchAdjust.R
6969
- path: utils.R
70+
- type: r_script
71+
path: /src/utils/helper_functions.R
7072

7173
engines:
7274
# Specifications for the Docker image for this component.
@@ -77,7 +79,7 @@ engines:
7779
setup:
7880
- type: r
7981
bioc: [flowCore]
80-
packages: [docstring]
82+
packages: [docstring, dplyr]
8183

8284
runners:
8385
# This platform allows running the component natively

src/methods/batchadjust_one_control/script.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@ library(anndata)
22
library(flowCore)
33
## VIASH START
44
par <- list(
5-
input = "resources_test/debug/batchadjust/_viash_par/input_1/censored_split1.h5ad",
5+
input = "resources_test/task_cyto_batch_integration/mouse_spleen_flow_cytometry_subset/censored_split1.h5ad",
66
output = "resources_test/debug/batchadjust/output.h5ad",
77
percentile = as.integer('80')
88
)
99
meta <- list(
1010
name = "batchadjust_one_control",
11-
temp_dir = "resources_test/tmp",
11+
temp_dir = "resources_test/tmp_batchadjust_one_control",
1212
resources_dir = "src/methods/batchadjust_one_control"
1313
)
1414
source("src/utils/anndata_to_fcs.R")
15+
source("src/utils/helper_functions.R")
1516
## VIASH END
1617

1718
source(paste0(meta$resources_dir, "/utils.R"))
1819
source(paste0(meta$resources_dir, "/anndata_to_fcs.R"))
1920
source(paste0(meta$resources_dir, "/BatchAdjust.R"))
21+
source(paste0(meta$resources_dir, "/helper_functions.R"))
2022

2123
tmp_dir <- get_temp_dir(meta)
2224
print(paste0("Using temp dir: ", tmp_dir))
@@ -39,7 +41,9 @@ on.exit(clean_temp_dir(tmp_dir))
3941

4042

4143
cat("Reading input files\n")
42-
input <- anndata::read_h5ad(par[["input"]])
44+
input <- anndata::read_h5ad(par[["input"]]) |>
45+
subset_onecontrol()
46+
4347
#use Original_ID column to restore cell order after I/O operations
4448
# input$layers["preprocessed"][, "Original_ID"] <- seq(1, dim(input)[1])
4549

@@ -92,8 +96,9 @@ if (!non_control_has_batch) {
9296
input_no_controls$obs$sample <- sapply(input_no_controls$obs$sample, fix_batch_underscore_anynum)
9397

9498

95-
cat("Writing FCS files\n")
99+
cat("Writing control FCS files\n")
96100
anndata_to_fcs(input_controls, out_dir = tmp_dir)
101+
cat("Writing non-control FCS files\n")
97102
anndata_to_fcs(input_no_controls, out_dir = tmp_dir)
98103

99104
cat("Writing channels to correct as a text file\n")

src/utils/helper_functions.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ subset_nocontrols <- function(adata) {
8686
}
8787

8888
# Subset the adata to remove cells where is_control != 0
89-
adata[adata$obs$is_control == 0, ]
89+
adata[adata$obs$is_control == 0, ]$copy()
9090
}
9191

9292

@@ -112,7 +112,7 @@ subset_onecontrol <- function(adata, which_control = 1) {
112112
}
113113

114114
# Subset the adata to keep cells where is_control == which_control
115-
adata[adata$obs$is_control %in% c(which_control, 0), ]
115+
adata[adata$obs$is_control %in% c(which_control, 0), ]$copy()
116116
}
117117

118118
#' Subsets the anndata object to only include markers that need to be

0 commit comments

Comments
 (0)