Skip to content

Instantly share code, notes, and snippets.

@simon-anders
Last active February 10, 2021 16:34
Show Gist options
  • Save simon-anders/dca949e908290246531663df45dfc712 to your computer and use it in GitHub Desktop.
Save simon-anders/dca949e908290246531663df45dfc712 to your computer and use it in GitHub Desktop.
# Wir haben 300 Stämme
m <- 300
# Die wahre mittlere Floureszenz der Stämme ist
true_mu <- exp( rnorm( m, 3, 2) )
# Die mittlere Hintergrund-Floureszenz ist
true_bg <- 10
# Die Hintergrund-Floureszenz schwankt mit einer Standardabweichung von
true_bg_sd <- 2
# Die Floureszenz einer einzelnen Zelle ist log-normal verteilt um
# den MIttelwert (true_mu), wobei das Rauschen pro Zelle (extrinsic noise)
# vom Stamm abhängt:
true_extr_noise <- rgamma( m, 2, 1 )
# There is also intrinsic
true_intr_noise <- rgamma( m, 2, 4 )
# Wir messen von jedem Stamm 1000 Zellen
n <- 1000
# Berechne die Expressionsstärke pro Zelle:
y0 <-
t(sapply( 1:m, function(i)
true_mu[i] * exp( rnorm( n, 0, true_extr_noise[i] ) ) ))
# Addiere intrinisches Rauschen und Hintegrund
yRed <-
t(sapply( 1:m, function(i)
y0[i,] * exp( rnorm( n, 0, true_intr_noise[i] ) ) + rnorm( n, true_bg, true_bg_sd ) ))
yGreen <-
t(sapply( 1:m, function(i)
y0[i,] * exp( rnorm( n, 0, true_intr_noise[i] ) ) + rnorm( n, true_bg, true_bg_sd ) ))
# Ein paar negative Kontrollen (nur Hintergrund-Rauschen)
yNeg <-
t(sapply( 1:m, function(i)
rnorm( 100, true_bg, true_bg_sd ) ))
# Plot data
plot(
apply( yRed, 1, median ),
apply( yRed, 1, mad ), log="xy" )
plot(
apply( yGreen, 1, median ),
apply( yGreen, 1, mad ), log="xy" )
# Let's try an asinh VST by subtracting background and multiplying with some guessed number (10)
vst <- function(x) asinh((x-true_bg)*10)
plot(
apply( vst(yRed), 1, median ),
apply( vst(yRed), 1, mad ), log="xy" )
# Does this help? Can one twiddle with the guessed number to make it work better?
# It works best if we subtract the "true" background but that is cheating.
# But using mean(yNeg) shoudl work as well...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment