From cf78be197f31aaefcaddc829851f187545042ae9 Mon Sep 17 00:00:00 2001 From: Dillon Hammill Date: Tue, 5 Nov 2024 15:22:13 +1100 Subject: [PATCH] ODC-182 Support logical and factor gates for CytoExploreR's clustering framework. --- R/wrapper-functions.R | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/R/wrapper-functions.R b/R/wrapper-functions.R index b5b08f0..e528ffe 100644 --- a/R/wrapper-functions.R +++ b/R/wrapper-functions.R @@ -108,8 +108,35 @@ resType <- class(filterRes) - if(extends(resType, "filter")||extends(resType, "filters")||extends(resType, "logical")||extends(resType, "factor")){ - + # format filterRes to ensure gates per sample + # list can be supplied per sample to allow sample-wise logical|factor + if(class(filterRes) == "list" && all( + sapply( + filterRes, + function(v) { + any( + sapply( + c("filter", "filters", "logical", "factor"), + function(i) { + extends(class(v), i) + } + ) + ) + } + ) + ) && length(filterRes) == length(fs)) { + # names missing + if(is.null(names(filterRes))){ + names(filterRes) <- sampleNames(fs) + } + # names don't match + if(!all(sampleNames(fs) %in% names(filterRes))) { + stop( + "Gates should be supplied per sample in a named list." + ) + } + list(filterRes) + } else if(extends(resType, "filter")||extends(resType, "filters")||extends(resType, "logical")||extends(resType, "factor")){ #replicate the filter across samples list(sapply(sampleNames(fs),function(i)filterRes, simplify = FALSE)) }else{