[BioC] Gating with an ellipsoidGate

Roger Leigh rleigh at codelibre.net
Wed Sep 15 13:37:40 CEST 2010


On 15/09/2010 12:24, Roger Leigh wrote:
> This appears to work well when rotation is not involved. However, as
> soon as I try to add rotation, it blows up:
>
> library(flowCore)
> library(flowViz)
> library(flowUtils)
>
> cov.matrix <- function (a, b, angle) {
> theta <- angle * (pi/180)
>
> c1 <- ((cos(theta)^2)/a^2) + ((sin(theta)^2)/b^2)
> c2 <- sin(theta) * cos(theta) * ((1/a^2) - (1/b^2))
> c3 <- ((sin(theta)^2)/a^2) + ((cos(theta)^2)/b^2)
>
> m1 <- matrix(c(c1, c2, c2, c3), byrow=TRUE, ncol=2)
> m2 <- solve(m1)
>
> m2
> }
>
> d <- read.FCS("0isotype.fcs", alter.names=TRUE)
> d <- transform(d, `SS.Log` = log10(`SS.Log`))
>
> # No rotation
> cov <- cov.matrix(20000, 0.4, 0)
> colnames(cov) <- c("FS.Lin", "SS.Log")
> rownames(cov) <- c("FS.Lin", "SS.Log")
> mean <- c("FS.Lin"=40000, "SS.Log"=2.8)
> cells <- ellipsoidGate(filterId="CellGate", .gate=cov, mean=mean)
> print(cov)
> pdf("test.pdf", width=8, height=8, pointsize=12)
> print(xyplot(`SS.Log` ~ `FS.Lin`, d, filter=cells, xlab="FS",
> ylab=expression(log[10]~(SS))))
> dev.off()
>
> # Now repeat with a 20 degree rotation...
> cov <- cov.matrix(20000, 0.4, 20)
> colnames(cov) <- c("FS.Lin", "SS.Log")
> rownames(cov) <- c("FS.Lin", "SS.Log")
> mean <- c("FS.Lin"=40000, "SS.Log"=2.8)
> cells <- ellipsoidGate(filterId="CellGate", .gate=cov, mean=mean)
> print(cov)
>
> pdf("test-rotate.pdf", width=8, height=8, pointsize=12)
> print(xyplot(`SS.Log` ~ `FS.Lin`, d, filter=cells, xlab="FS",
> ylab=expression(log[10]~(SS))))
> dev.off()
>
> I've put the source data, script and results at:
> http://www-users.york.ac.uk/~rl522/flowcore-test/
>
> http://www-users.york.ac.uk/~rl522/flowcore-test/test.pdf
> http://www-users.york.ac.uk/~rl522/flowcore-test/test-rotate.pdf
>
> You can see that while an ellipse is drawn correctly in the first
> instance, when we add a 20 degree rotation, it's completely screwed. I'm
> not sure if this is due to the extreme differences in the x and y
> dimensions, which alter the length of a and b, or for some other reason.

cov <- cov.matrix(20000, 0.4, 20)

While this gives what looks like an almost entirely vertical line, using 
a much smaller angle

cov <- cov.matrix(20000, .25, 0.0005)

actually results in a sensible rotation, of about 20 degrees.  So it 
looks like it works, but the scaling of the angle is wrong--it's far too 
sensitive.  I'm correctly converting from degrees to radians, so I'm not 
sure why 8.7e-6 radians actually results in a rotation of ~0.35 radians!


Regards,
Roger



More information about the Bioconductor mailing list