### Analysis of FACS data, using text files having ### columnar data consisting of green (GFP) channel and red ### (DNA stain) measurements. Density kernel estimates for ### the red channel are calculated and a subset of cells are ### selected for analysis. Median, mean, ### and sd of GFP for these cells are then calculated. ### the number of cells to gate for the analysis N <- 1.0e+4 ### the file ot analyze my.file <- "/Users/facsFiles/gene.txt" ### min values for the RFP and GFP MIN.GFP <- 1 MIN.RFP <- 10 EXCLUDE <- 1000 ### exclude the first N events (1000 or so - these appear to be inaccurate) ########################################## ### Gating Function ########################################## ### Returns a list of length N ### of cells within a gate and their rfp ### and gfp values gate.rfp <- function(data, N) { ### Exclude first few values (these are usually inaccurate) data <- data[EXCLUDE:nrow(data),] ### get rid of low values data <- data[which(data[,2] > MIN.RFP),] data <- data[which(data[,1] > MIN.GFP),] gated <- list() ### log transform data <- log10(data) rfp <- data[,2] gfp <- data[,1] if(length(gfp)>N) { data.dens <- density(rfp) max.dens <- data.dens$x[which(data.dens$y == max(data.dens$y))] o <- order(rfp) rfp <- rfp[o] gfp <- gfp[o] ### check that i is not too close to ends of vectors i <- max(min(which(rfp >= max.dens)), N/2+1) i <- min(i, length(gfp)-N/2) min.rfp <- rfp[i-N/2] max.rfp <- rfp[i+N/2] gated$gfp <- gfp[(i-N/2+1):(i+N/2)] gated$rfp <- rfp[(i-N/2+1):(i+N/2)] } else { gated$gfp <- gfp gated$rfp <- rfp } gated } ### ************************************** ### fcs <- read.table(file=my.file, header=T) gated.data <- gate.rfp(fcs, N) ### This caluclates log-transformed values only mean.rfp <- mean(gated.data$rfp) mean.gfp <- mean(gated.data$gfp) sd.gfp <- sd(gated.data$gfp) median.gfp <- median(gated.data$gfp)