To help with this, here's a quick function for getting a 2D polygon gate with an optional transform:
interactiveGate = function(fcs,x,y,filterId="Picked", trans=NULL,...) {
if(is.function(trans)) {
tnf = structure(list(trans,trans),names=c(x,y))
trans = do.call("transform",tnf)
}
plot(exprs(if(is.null(trans)) fcs else trans %on% fcs)[,c(x,y)],
pch=20,cex=.5,main=filterId,...)
points = locator(type="n")
polygon(points)
points = cbind(points$x,points$y)
colnames(points) = c(x,y)
r = polygonGate(filterId,points)
if(is.null(trans)) r else r %on% trans
}
The fcs parameter is a flowFrame and the x and y arguments should be pretty obvious. The trans argument can be one of three things: NULL, a function, or a transform object. If it is a transform object (created by transform(...)) then it is simply applied. If it's a function, a transform will be created for both parameters and also applied to the subsequent gate.
e.g.
interactiveGate(fcs,"APC-Cy7-A","PacOrange-565-A","Control",function(x) asinh(x/32))
Just a little thing, but pretty useful.
No comments:
Post a Comment