Commit 576e0c81 authored by dmattek's avatar dmattek

Mod:

- trajectory plotting and cluster distribution plot turned into modules
parent 49b9d1e6
source('modules/auxfunc.R')
source('modules/downPlot.R')
source('modules/downCellIDsCls.R')
source('modules/trajPlot.R')
source('modules/clDistPlot.R')
source('modules/tabScatter.R')
source('modules/tabBoxPlot.R')
source('modules/tabClBay.R')
\ No newline at end of file
......@@ -116,7 +116,7 @@ myGgplotTraj = function(dt.arg,
aes_string(y = y.arg, group = 1),
fun.data = mean_cl_normal,
colour = 'red',
alpha = 0.5,
alpha = 0.25,
geom = "ribbon",
group = 1
)
......@@ -127,7 +127,7 @@ myGgplotTraj = function(dt.arg,
aes_string(y = y.arg, group = 1),
fun.data = mean_se,
colour = 'red',
alpha = 0.5,
alpha = 0.25,
geom = "ribbon",
group = 1
)
......@@ -187,20 +187,23 @@ userDataGen <- function() {
locNsites = 4
locNwells = 1
x.rand.1 = c(rnorm(locNtp * locNtracks * locNsites * 0.5, 2, 0.5), rnorm(locNtp * locNtracks * locNsites * 0.5, 2, 0.5))
x.rand.2 = c(rnorm(locNtp * locNtracks * locNsites * 0.5, 0, 0.1), rnorm(locNtp * locNtracks * locNsites * 0.5, 0, 0.1))
x.rand.3 = rep(rnorm(locNtracks, 2, 0.5), 1, each = locNtp)
x.rand.4 = rep(rnorm(locNtracks, 1, 0.1), 1, each = locNtp)
x.rand.1 = c(rnorm(locNtp * locNtracks * locNsites * 0.5, .5, 0.1), rnorm(locNtp * locNtracks * locNsites * 0.5, 1, 0.2))
x.rand.2 = c(rnorm(locNtp * locNtracks * locNsites * 0.5, 0.25, 0.1), rnorm(locNtp * locNtracks * locNsites * 0.5, 0.5, 0.2))
# x.rand.3 = rep(rnorm(locNtracks, 2, 0.5), 1, each = locNtp)
# x.rand.4 = rep(rnorm(locNtracks, 1, 0.1), 1, each = locNtp)
x.arg = rep(seq(0, locNtp-1) / locNtp * 4 * pi, locNtracks * locNsites)
# x.arg = rep(seq(0, locNtp-1) / locNtp * 4 * pi, locNtracks * locNsites)
x.arg = rep(seq(1, locNtp), locNtracks * locNsites)
dt.nuc = data.table(Metadata_Site = rep(1:locNsites, each = locNtp * locNtracks),
Metadata_Well = rep(1:locNwells, each = locNtp * locNsites * locNtracks / locNwells),
Metadata_RealTime = x.arg,
# objCyto_Intensity_MeanIntensity_imErkCor = c(rnorm(locNtp * locNtracks * locNsites * 0.5, .5, 0.1), rnorm(locNtp * locNtracks * locNsites * 0.5, 1, 0.2)),
objCyto_Intensity_MeanIntensity_imErkCor = x.rand.1,
objNuc_Intensity_MeanIntensity_imErkCor = x.rand.2,
objNuc_Location_X = runif(locNtp * locNtracks * locNsites, min = 0, max = 1),
objNuc_Location_Y = runif(locNtp * locNtracks * locNsites, min = 0, max = 1),
# objCyto_Intensity_MeanIntensity_imErkCor = x.rand.3 + ifelse(x.arg < 4, 0, 1) / x.rand.3,
# objNuc_Intensity_MeanIntensity_imErkCor = c(rnorm(locNtp * locNtracks * locNsites * 0.5, .25, 0.1), rnorm(locNtp * locNtracks * locNsites * 0.5, .5, 0.2)),
objCyto_Intensity_MeanIntensity_imErkCor = x.rand.3 + ifelse(x.arg < 4, 0, 1) / x.rand.3,
objNuc_Intensity_MeanIntensity_imErkCor = c(rnorm(locNtp * locNtracks * locNsites * 0.5, .25, 0.1), rnorm(locNtp * locNtracks * locNsites * 0.5, .5, 0.2)),
TrackLabel = rep(1:(locNtracks*locNsites), each = locNtp))
cat(colnames(dt.nuc))
......
modClDistPlotUI = function(id, label = "Plot Fractions WIthin Clusters") {
ns <- NS(id)
tagList(
actionButton(ns('butPlotClDist'), 'Plot!'),
plotOutput(ns('outPlotClDist'), height = '800px', width = 'auto'),
downPlotUI(ns('downPlotClDist'), "Download PDF")
)
}
modClDistPlot = function(input, output, session, in.data, in.fname = 'clDist.pdf') {
ns <- session$ns
# Barplot with distribution of clusters across conditions
plotClDist = function() {
cat(file = stderr(), 'plotClDist: in\n')
loc.dt = in.data()
if (is.null(loc.dt)) {
cat(file = stderr(), 'plotClDist: dt is NULL\n')
return(NULL)
}
p.out = ggplot(loc.dt, aes(x = group, y = nCells)) +
geom_bar(aes(fill = as.factor(cl)), stat = 'identity', position = 'fill') +
scale_y_continuous(labels = percent) +
ylab("percentage of cells\n") +
xlab("") +
scale_fill_discrete(name = "Cluster no.") +
myGgplotTheme
return(p.out)
}
# Hierarchical - display bar plot
output$outPlotClDist <- renderPlot({
locBut = input$butPlotClDist
if (locBut == 0) {
cat(file = stderr(), 'outPlotClDist: Go button not pressed\n')
return(NULL)
}
plotClDist()
})
# Hierarchical - Bar Plot - download pdf
callModule(downPlot, "downPlotClDist", in.fname, plotClDist, TRUE)
}
\ No newline at end of file
modClDistPlotUI = function(id, label = "Plot Fractions WIthin Clusters") {
ns <- NS(id)
}
modClDistPlot = function(input, output, session, in.data, in.facet = 'group') {
ns <- session$ns
}
\ No newline at end of file
modTrajPlotUI = function(id, label = "Plot Individual Time Series") {
ns <- NS(id)
tagList(
fluidRow(
column(
3,
numericInput(
ns('inPlotTrajFacetNcol'),
'#Columns:',
value = 4,
min = 1,
width = '100px',
step = 1
),
checkboxInput(ns('chBplotTrajInt'), 'Interactive Plot?'),
actionButton(ns('butPlotTraj'), 'Plot!')
),
column(
3,
checkboxGroupInput(ns('chBPlotTrajStat'), 'Stats:', list('Mean' = 'mean', '95% conf. interv.' = 'CI', 'Std. error' = 'SE'))
),
column(
3,
sliderInput(ns('sliPlotTrajSkip'), 'Plot every n-th point:', min = 1, max = 10, value = 1, step = 1)
),
column(
3,
numericInput(
ns('inPlotTrajWidth'),
'Width [%]:',
value = 100,
min = 10,
max = 100,
width = '100px',
step = 10
),
numericInput(
ns('inPlotTrajHeight'),
'Height [px]:',
value = 800,
min = 100,
width = '100px',
step = 50
)
)
),
uiOutput(ns('uiPlotTraj')),
downPlotUI(ns('downPlotTraj'), "Download PDF")
)
}
modTrajPlot = function(input, output, session, in.data, in.facet = 'group', in.fname = 'tCourses.pdf') {
ns <- session$ns
output$uiPlotTraj = renderUI({
if (input$chBplotTrajInt)
plotlyOutput(
ns("outPlotTrajInt"),
width = paste0(input$inPlotTrajWidth, '%'),
height = paste0(input$inPlotTrajHeight, 'px')
) else
plotOutput(
ns("outPlotTraj"),
width = paste0(input$inPlotTrajWidth, '%'),
height = paste0(input$inPlotTrajHeight, 'px')
)
})
output$outPlotTraj <- renderPlot({
loc.p = plotTraj()
if(is.null(loc.p))
return(NULL)
return(loc.p)
})
output$outPlotTrajInt <- renderPlotly({
# This is required to avoid
# "Warning: Error in <Anonymous>: cannot open file 'Rplots.pdf'"
# When running on a server. Based on:
# https://github.com/ropensci/plotly/issues/494
if (names(dev.cur()) != "null device")
dev.off()
pdf(NULL)
loc.p = plotTraj()
if(is.null(loc.p))
return(NULL)
return(plotly_build(loc.p))
})
# Trajectory plot - download pdf
callModule(downPlot, "downPlotTraj", in.fname, plotTraj, TRUE)
plotTraj <- function() {
cat(file = stderr(), 'plotTraj: in\n')
locBut = input$butPlotTraj
if (locBut == 0) {
cat(file = stderr(), 'plotTraj: Go button not pressed\n')
return(NULL)
}
loc.dt = isolate(in.data())
cat("plotTraj: on to plot\n\n")
if (is.null(loc.dt)) {
cat(file = stderr(), 'plotTraj: dt is NULL\n')
return(NULL)
}
cat(file = stderr(), 'plotTraj: dt not NULL\n')
# Future: change such that a column with colouring status is chosen by the user
# colour trajectories, if dataset contains mi.din column
# with filtering status of trajectory
if (sum(names(loc.dt) %in% 'mid.in') > 0)
loc.line.col.arg = 'mid.in'
else
loc.line.col.arg = NULL
# select every other point for plotting
loc.dt = loc.dt[, .SD[seq(1, .N, input$sliPlotTrajSkip)], by = id]
# check if columns with XY positions are present
if (sum(names(loc.dt) %like% 'pos') == 2)
locPos = TRUE
else
locPos = FALSE
p.out = myGgplotTraj(
dt.arg = loc.dt,
x.arg = 'realtime',
y.arg = 'y',
group.arg = "id",
facet.arg = in.facet,
facet.ncol.arg = input$inPlotTrajFacetNcol,
xlab.arg = 'Time (min)',
line.col.arg = loc.line.col.arg,
aux.label1 = if (locPos) 'pos.x' else NULL,
aux.label2 = if (locPos) 'pos.y' else NULL,
stat.arg = input$chBPlotTrajStat
)
return(p.out)
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -77,49 +77,9 @@ shinyUI(fluidPage(
checkboxInput('chBhighlightTraj', 'Highlight trajectories?', FALSE),
uiOutput('varSelHighlight'),
br(),
fluidRow(
column(
4,
numericInput(
'inPlotTrajFacetNcol',
'#Columns:',
value = 4,
min = 1,
width = '100px',
step = 1
),
checkboxInput('chBplotTrajInt', 'Interactive Plot?'),
actionButton('butPlotTraj', 'Plot!')
),
column(
4,
sliderInput('sliPlotTrajSkip', 'Plot every n-th point:', min = 1, max = 10, value = 1, step = 1),
checkboxGroupInput('chBPlotTrajStat', 'Stats:', list('Mean' = 'mean', '95% conf. interv.' = 'CI', 'Std. error' = 'SE'))
),
column(
4,
numericInput(
'inPlotTrajWidth',
'Width [%]:',
value = 100,
min = 10,
max = 100,
width = '100px',
step = 10
),
numericInput(
'inPlotTrajHeight',
'Height [px]:',
value = 800,
min = 100,
width = '100px',
step = 50
)
)
modTrajPlotUI('modTrajPlot')
),
uiOutput('uiPlotTraj'),
downPlotUI('downPlotTraj', "Download PDF")
),
tabPanel(
"Box-plots",
......@@ -272,13 +232,11 @@ shinyUI(fluidPage(
# tabPanel('Heat-map int.',
# helpText("Choose your settings 2")),
tabPanel('Time-courses',
actionButton('butPlotHierTraj', 'Plot!'),
plotOutput('outPlotHierTraj' , height = '800px', width = 'auto'),
downPlotUI('downPlotHierTraj', "Download PDF")),
modTrajPlotUI('modPlotHierTraj')),
tabPanel('Cluster dist.',
actionButton('butPlotHierClDist', 'Plot!'),
plotOutput('outPlotHierClDist', height = '800px', width = 'auto'),
downPlotUI('downPlotHierClDist', "Download PDF"))
modClDistPlotUI('hierClDistPlot', 'xxx'))
)
),
......@@ -452,13 +410,9 @@ shinyUI(fluidPage(
# tabPanel('Heat-map int.',
# helpText("Choose your settings 2")),
tabPanel('Time-courses',
actionButton('butPlotHierSparTraj', 'Plot!'),
plotOutput('outPlotHierSparTraj', height = '800px', width = 'auto'),
downPlotUI('downPlotHierSparTraj', "Download PDF")),
modTrajPlotUI('modPlotHierSparTraj')),
tabPanel('Cluster dist.',
actionButton('butPlotHierSparClDist', 'Plot!'),
plotOutput('outPlotHierSparClDist', height = '800px', width = 'auto'),
downPlotUI('downPlotHierSparClDist', "Download PDF"))
modClDistPlotUI('hierClSparDistPlot'))
)
)
#
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment