Skip to content

Commit

Permalink
Fix some small bugs that snuck into COMPASSContainerFromGatingSet, st…
Browse files Browse the repository at this point in the history
…art optimizing re: #29
  • Loading branch information
kevinushey committed Mar 26, 2014
1 parent e2e622b commit e8921d5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
4 changes: 2 additions & 2 deletions R/GatingSetToCOMPASS.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 4 additions & 5 deletions R/GetThresholdedIntensities.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 22 additions & 2 deletions examples/GetThresholdedIntensities.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)

}
24 changes: 22 additions & 2 deletions man/GetThresholdedIntensities.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)

}
Expand Down

0 comments on commit e8921d5

Please sign in to comment.