RGLab / flowWorkspace

flowWorkspace
GNU Affero General Public License v3.0
45 stars 21 forks source link

Polygon gate coordinates shifted in one of 2 dimensions #309

Closed hamid-bolouri closed 4 years ago

hamid-bolouri commented 4 years ago

Hi Greg & Mike;

I am trying to reproduce a FlowJo gating strategy in R and find that some (polygon) gates seem scaled incorrectly in 1 dimension but are OK in the other. This seems different from issues #230 and #261 in that (perplexingly) only 1 dimension is affected (and the gates are polygons). In the example below, "Event_length" coords in the right-hand plot are ~ 10x higher in R than FlowJo but "Ir191Di" coords seem fine (see attached image). Am I doing something silly here? Any thoughts/guidance would be much appreciated.

Thanks,

Hamid gates_in_FlowJo

Sample code with in-line info/comments:


ffiles <- dir(pattern = ".fcs$")
fset <- flowCore::read.flowSet(ffiles)

ws <- open_flowjo_xml("2020-03-11 CyTOF gating strategy.wsp")

selSample = 1 # samples == 1:4

# fset[[1]]
# flowFrame object 'CT00119-01_Old_02_1.fcs'
# with 248024 cells and 57 observables ...

tbl <- t(fset[[selSample]]@exprs) # 248024 cells
colnames(tbl) <- paste0("c", 1:ncol(tbl))

gs <- flowjo_to_gatingset(ws, name = 2)
gh <- gs[[selSample]]

tbl <- tbl[ , tbl["Ce140Di", ] < 1000] # 240929 as in FlowJo

plot(log10(tbl2["Ir191Di", ]+1), log10(tbl2["Event_length", ]+1), 
     cex=0.25, col=rgb(0,0.3,1,0.25)) # Comparable to FlowJo plot

nodelist <- gs_get_pop_paths(gs, path = "auto")
g <- gs_pop_get_gate(gs, nodelist[3])[[1]]
# g
# Polygonal gate 'Singlets' with 7 vertices in dimensions Ir191Di and Event_length

# g@boundaries
      # Ir191Di Event_length
# [1,] 157.3370    121.65505
# [2,] 156.4481     89.17604
# [3,] 172.4476     83.27077
# [4,] 191.5580     87.69973
# [5,] 182.2250    102.46291
# [6,] 180.0028    120.91688
# [7,] 169.7810    123.13137

# min(g@boundaries[ ,"Event_length"]) 
# 83.27077 i.e. about 10-fold higher than in FlowJo
mikejiang commented 4 years ago

You seems to be plotting the raw file that was loaded by read.flowSet call, which is entirely independent from the gs object your generated from flowjo_to_gatingset. To plot the data and gates, try to use ggcyto instead of inventing your own wheel.

gfinak commented 4 years ago

Hi, Hamid. What Mike is getting at is that the raw FCS file contains untransformed data on the raw scale, while the GatingSet object contains transformed data and gates (on the same scale). The raw FCS is on a different scale than the gates. The ggcyto package is a good way to pull out specific populations from the GatingSet and visualize them.

hamid-bolouri commented 4 years ago

Ah, my bad! Sorry, and thanks for the explanation Greg.

Hamid