Problem displaying stats in ggcyto after log-transformation (flow cytometry analysis in R)
1
0
Entering edit mode
7.6 years ago

I am using ggcyto package in R to plot flow cytometry data, and to display stats on the plot, I am using the geom_stats() function as shown here: https://www.bioconductor.org/packages/release/bioc/vignettes/ggcyto/inst/doc/ggcyto.GatingSet.html

But while the plot and gates look fine, geom_stats is not working and I get the following warning messages when I run ggcyto()...geom_stats()

Warning messages: 1: Removed 27 rows containing missing values (geom_hex). 2: Removed 2 rows containing missing values (geom_label). 3: Removed 2 rows containing missing values (geom_label). 4: Removed 2 rows containing missing values (geom_label). 5: Removed 2 rows containing missing values (geom_label).

This is the code, but it's not a working example as the data files (FCS files exported from BD FACSdiva) are not uploaded.

# libraries ----
library(flowCore)
library(ggplot2)
library(cowplot)
library(ggcyto)
library(openCyto)
library(flowWorkspace)

# load FCS files ----
files <- list.files(path = "Folder_001/Experiment_001/", pattern = "Specimen", full.names = TRUE)
expt1 <- read.flowSet(files = files, name.keyword = "$FIL", alter.names = TRUE)

# log-transform PI and Annexin V data ----
logTrans <- logTransform(transformationId="log10-transformation", logbase=10, r=1, d=1)
trans <- transformList(c("PI.A", "BV421.A"), logTrans)
expt1.trans <- transform(expt1, trans)

# clean up NA/NaN/Inf ----
for(n in 1:length(expt1.trans)){
  exprs(expt1.trans[[n]]) <- exprs(expt1.trans[[n]])[!rowSums(!is.finite(exprs(expt1.trans[[n]]))), ]
}

# Add gates (flowWorkspace) ----
gate <- rectangleGate(filterId="myRectGate", "FSC.A"=c(0, 255000), "SSC.A"=c(0, 75000))
qg <- quadGate(filterId="myQuadGate1", "PI.A"=log10(10000), "BV421.A"=log10(3000))
gated.gs <- GatingSet(expt1.trans)
addgated.gs, gate, parent = "root", name = "rect", recompute = TRUE)
addgated.gs, qg, parent = "rect", name = c("Early apoptotic", "Dead", "PI only", "Live"))
getNodesgated.gs)
recomputegated.gs)
gated.selected <- gated.gs[c(8, 6)]

# plot ----
p <- ggcyto(gated.selected, aes(x = PI.A, y = BV421.A)) +
  geom_hex(bins = 200) +
  geom_gate(gates) + 
  labs(x = "PI", y = "Annexin V") + 
  geom_stats()

Looking at the ggplot object created by ggcyto, it looks like the problem might be with the x and y columns in the labels data frames, which have NA's, but manually modifying these columns does not seem to have any effect.

> p.build$data[[7]]
   x  y label PANEL group colour  fill size angle hjust vjust alpha family fontface lineheight
1 NA NA 9.16%     1    -1  black white 3.88     0   0.5   0.5    NA               1        1.2
2 NA NA 8.88%     2    -1  black white 3.88     0   0.5   0.5    NA               1        1.2

Hope that is all the relevant information, but please let me know if I missed anything. Thanks.

R Bioconductor ggcyto flow cytometry • 3.5k views
ADD COMMENT
3
Entering edit mode
7.6 years ago
go2rsr ▴ 30

The maintainer of ggcyto has solved this issue for me, just posting this for anyone else who ends up here from a Google search.

https://github.com/RGLab/ggcyto/issues/13

Briefly, there are negative values in my data which generate NaN and Inf/-Inf upon log transformation. Instead, if I do a logicle transformation (http://www.ncbi.nlm.nih.gov/pmc/articles/PMC1994577/), there are no missing values and geom_stats() works as expected.

trans <- estimateLogicle(expt1[[1]], c("PI.A", "BV421.A"))
expt1.trans <- transform(expt1, trans)
ADD COMMENT

Login before adding your answer.

Traffic: 3063 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6