-
Notifications
You must be signed in to change notification settings - Fork 2
/
transforms.R
52 lines (40 loc) · 1.76 KB
/
transforms.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
library(flowCore)
#set w=0 is important to avoid spurious peaks close to zero
#w=0 is essentially equivalent to asinh according to Moore et al 2012, Cytometry A
lgcl <- logicleTransform(w=0.1)
lgcl <- function(y,m=3) logicleTransform(w=(m-log10(max(y)/abs(min(y))))/2)(y)
estimateTransforms <- function(x, m=4.5) {
sapply(colnames(x), function(n) {
if (grepl('^SSC|^FSC',n))
return(identity)
y <- x[,n]
y <- y[which(percentile.filter(y,bottom=.01,top=.98))]
print(n)
print(t <- max(y))
print(abs(min(y)))
print(r <- log10(t/abs(min(y))))
if (r < 0) w <- 2.25
else w <- (m-r)/2
print(w)
return(logicleTransform(w=w,m=m,t=t))
})
}
applyTransforms.slow <- function(x, transforms) {
sapply(colnames(x), function(n) {
transforms[[n]](x[,n])
})
}
load( '~nikolas/dunwich/Projects/IL2/PSTAT5-CD25-CD45RA-CD4-FOXP3/pstat5-join/All/CB00366X_2012-11-07.RData' )
transforms <- estimateTransforms(fcs.data)
transforms[['FOXP3']] <- logicleTransform(w=1)
transforms[['CD45RA']] <- logicleTransform(w=.5)
transforms[['CD25']] <- logicleTransform(w=.6)
transforms[['PSTAT5.1']] <- logicleTransform(w=.5)
transforms[grep('PSTAT5',names(transforms))] <- transforms['PSTAT5.1']
transforms[['PSTAT5']] <- transforms[['PSTAT5.1']]
save(transforms, file='~nikolas/dunwich/Projects/IL2/PSTAT5-CD25-CD45RA-CD4-FOXP3/transforms.RData')
# all transforms have zero set to one
transforms <- estimateTransforms(fcs.data)
transforms <- lapply(transforms, function(x) logicleTransform(w=1))
transforms[['PSTAT5']] <- transforms[['PSTAT5.1']]
save(transforms, file='~nikolas/dunwich/Projects/IL2/PSTAT5-CD25-CD45RA-CD4-FOXP3/transform-w1.RData')