diff --git a/R/GatingSetToCOMPASS.R b/R/GatingSetToCOMPASS.R index f381372..71dd21a 100644 --- a/R/GatingSetToCOMPASS.R +++ b/R/GatingSetToCOMPASS.R @@ -283,11 +283,11 @@ COMPASSContainerFromGatingSet <- function(gs = NULL, node = NULL, filter.fun = N map <- map[markers, ] } message("We will map the following nodes to markers:") - kable(map) + kable(as.data.frame(map)) # construct the map - mp <- map[, desc] + mp <- as.character(map[, desc]) names(mp) <- map[, node] mp <- as.list(mp) } diff --git a/R/GetThresholdedIntensities.R b/R/GetThresholdedIntensities.R index 3b85ab3..b6cb31c 100644 --- a/R/GetThresholdedIntensities.R +++ b/R/GetThresholdedIntensities.R @@ -98,8 +98,7 @@ GetThresholdedIntensities <- function(gs, node, map) { ## Try to guess whether we should be pulling names from the 'desc' ## column or the 'name' column of the flowSets - dat <- flowWorkspace::getData(gs, use.exprs=FALSE) - ff <- get( objects(dat@frames)[[1]], envir=dat@frames ) + ff <- flowWorkspace::getData(gs[[1]], use.exprs=FALSE) params <- parameters(ff)@data ## First, check for a perfect match using a basic regex @@ -151,9 +150,9 @@ GetThresholdedIntensities <- function(gs, node, map) { } else { node_path <- file.path(path, cNode) } - gate <- flowWorkspace::getGate(x, node_path) - thresh <- gate@min - exprs[, expr_nms[i]][ exprs[, expr_nms[i]] < thresh ] <- 0 + ## find out what cells didn't fall into the gate + ind <- !flowWorkspace::getIndices(x, node_path) + exprs[ind, expr_nms[i]] <- 0 } exprs <- exprs[ rowSums(exprs) > 0, , drop=FALSE] return(exprs) diff --git a/examples/GetThresholdedIntensities.R b/examples/GetThresholdedIntensities.R index 2c75910..02cbef6 100644 --- a/examples/GetThresholdedIntensities.R +++ b/examples/GetThresholdedIntensities.R @@ -28,13 +28,25 @@ if (require(flowWorkspace)) { fs <- flowSet( lapply(data, flowFrame) ) gs <- GatingSet(fs) + ## Add some dummy metadata + meta <- pData(gs) + meta$PTID <- 1:10 + pData(gs) <- meta + + gate <- rectangleGate( list(TNFa=c(-Inf,Inf))) + add(gs, gate, parent="root", name="dummy") + + ## Add dummy gate + ## Make some gates, and apply them invisible(lapply(marker_names, function(marker) { .gate <- setNames( list( c( rexp(1, runif(1, 1E-5, 1E-3)), Inf) ), marker ) gate <- rectangleGate(.gate=.gate) - add(gs, gate, parent="root", name=paste0(marker, "+")) + add(gs, gate, parent="dummy", name=paste0(marker, "+")) })) + recompute(gs) + ## Map node names to channel names map=list( "TNFa+"="TNFa", @@ -44,7 +56,15 @@ if (require(flowWorkspace)) { ) ## Pull out the data as a COMPASS-friendly dataset - output <- GetThresholdedIntensities(gs, "root", map) + node <- "dummy" + map <- map + system.time( + output <- GetThresholdedIntensities(gs, "dummy", map) + ) + + system.time( + output <- COMPASSContainerFromGatingSet(gs, "dummy", individual_id="PTID", sample_id="name") + ) str(output) } diff --git a/man/GetThresholdedIntensities.Rd b/man/GetThresholdedIntensities.Rd index 1cad982..467d37c 100644 --- a/man/GetThresholdedIntensities.Rd +++ b/man/GetThresholdedIntensities.Rd @@ -61,13 +61,25 @@ if (require(flowWorkspace)) { fs <- flowSet( lapply(data, flowFrame) ) gs <- GatingSet(fs) + ## Add some dummy metadata + meta <- pData(gs) + meta$PTID <- 1:10 + pData(gs) <- meta + + gate <- rectangleGate( list(TNFa=c(-Inf,Inf))) + add(gs, gate, parent="root", name="dummy") + + ## Add dummy gate + ## Make some gates, and apply them invisible(lapply(marker_names, function(marker) { .gate <- setNames( list( c( rexp(1, runif(1, 1E-5, 1E-3)), Inf) ), marker ) gate <- rectangleGate(.gate=.gate) - add(gs, gate, parent="root", name=paste0(marker, "+")) + add(gs, gate, parent="dummy", name=paste0(marker, "+")) })) + recompute(gs) + ## Map node names to channel names map=list( "TNFa+"="TNFa", @@ -77,7 +89,15 @@ if (require(flowWorkspace)) { ) ## Pull out the data as a COMPASS-friendly dataset - output <- GetThresholdedIntensities(gs, "root", map) + node <- "dummy" + map <- map + system.time( + output <- GetThresholdedIntensities(gs, "dummy", map) + ) + + system.time( + output <- COMPASSContainerFromGatingSet(gs, "dummy", individual_id="PTID", sample_id="name") + ) str(output) }