Commit d96c2b74 authored by arsenij.ustjanzew's avatar arsenij.ustjanzew
Browse files

debuged and selection option

parent 8b6e8865
......@@ -11,3 +11,4 @@ Depends: R (>= 3.5.2)
License: What license is it under?
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
# Generated by roxygen2: fake comment so roxygen2 overwrites silently.
exportPattern("^[^\\.]")
# Generated by roxygen2: do not edit by hand
......@@ -10,14 +10,14 @@ features_by_factors <- function(object, x, y, title = "Features by factor") {
env_id <- paste0("env_", stringi::stri_rand_strings(1, 6, pattern = "[A-Za-z0-9]"))
# validate input, create environment variables, save environment object
.validate_input(object@workdir, env_id, x, y)
.validate_input_features_by_factors(object@workdir, env_id, x, y)
timestamp <- Sys.time()
expanded_component <- knitr::knit_expand(file = system.file("templates", "features_by_factors_template.Rmd", package = "i2dash"), title = title, env_id = env_id, date = timestamp)
expanded_component <- knitr::knit_expand(file = system.file("templates", "features_by_factors_template.Rmd", package = "i2dash.scrnaseq"), title = title, env_id = env_id, date = timestamp)
return(expanded_component)
}
.validate_input <- function(workdir, env_id, x, y) {
.validate_input_features_by_factors <- function(workdir, env_id, x, y) {
env <- new.env()
env$x_selection <- FALSE
env$y_selection <- FALSE
......@@ -27,9 +27,8 @@ features_by_factors <- function(object, x, y, title = "Features by factor") {
if(!is.list(y)) y <- list(y = y)
# Check validity
if(!all(sapply(x, is.numeric))) stop("x should only contain numeric values.")
if(!all(sapply(y, is.numeric))) stop("y should only contain numeric values.")
if(!all(sapply(x, is.factor))) stop("y should only contain factorial values.")
if(!all(sapply(x, is.factor))) stop("x should only contain factorial values.")
# Add objects to env
env$x <- x
......
......@@ -12,14 +12,14 @@ sequence_saturation <- function(object, x, y, colour_by = NULL, title = "Sequenc
env_id <- paste0("env_", stringi::stri_rand_strings(1, 6, pattern = "[A-Za-z0-9]"))
# validate input, create environment variables, save environment object
.validate_input(object@workdir, env_id, x, y, colour_by)
.validate_input_sequence_saturation(object@workdir, env_id, x, y, colour_by)
timestamp <- Sys.time()
expanded_component <- knitr::knit_expand(file = system.file("templates", "sequence_saturation_template.Rmd", package = "i2dash.scrnaseq"), title = title, env_id = env_id, date = timestamp)
return(expanded_component)
}
.validate_input <- function(workdir, env_id, x, y, colour_by) {
.validate_input_sequence_saturation <- function(workdir, env_id, x, y, colour_by) {
env <- new.env()
env$x_selection <- FALSE
env$y_selection <- FALSE
......
### {{plot_title}}
### {{ title }}
<!-- Component created on {{ date }} -->
<!-- Page created on {{ date }} -->
```{r}
{{ env_id }} = readRDS("envs/{{ env_id }}.rds")
plotly::plotlyOutput("plot_{{ env_id }}")
is_shiny <- identical(knitr::opts_knit$get("rmarkdown.runtime"), "shiny")
```
```{r, eval=!is_shiny}
x_value <- {{ env_id }}$x[[1]]
x_title <- names({{ env_id }}$x)
y_value <- {{ env_id }}$y[[1]]
y_title <- names({{ env_id }}$y)
p <- plotly::plot_ly(data.frame(x_value, y_value),
x = x_value,
y = y_value,
split = x_value,
type = 'violin',
box = list(
visible = T
),
meanline = list(
visible = T
)
)
p <- plotly::layout(p,
xaxis = list(title = x_title),
yaxis = list(title = y_title,
zeroline = F))
p
```
```{r, eval=is_shiny}
ui_list <- list()
# selection field for x
if ({{ env_id }}$x_selection){
ui_list <- rlist::list.append(ui_list,
selectInput("select_x_{{ env_id }}", label = "Select data for x axis:",
choices = names({{ env_id }}$x)))
}
# selection field for y
if ({{ env_id }}$y_selection){
ui_list <- rlist::list.append(ui_list,
selectInput("select_y_{{ env_id }}", label = "Select data for y axis:",
choices = names({{ env_id }}$y)))
}
fillCol(flex = c(NA, 1),
do.call("inputPanel", ui_list),
plotly::plotlyOutput("plot_{{ env_id }}", height = "100%"))
output$plot_{{ env_id }} <- plotly::renderPlotly({
if (!{{ env_id }}$x_selection){
......@@ -35,33 +88,19 @@ output$plot_{{ env_id }} <- plotly::renderPlotly({
meanline = list(
visible = T
)
)
p <- plotly::layout(p,
)
p <- plotly::layout(p,
xaxis = list(title = x_title),
yaxis = list(title = y_title,
zeroline = F))
p
p
})
```
***
```{r}
# selection field for x
if ({{ env_id }}$x_selection){
selectInput("select_x_{{ env_id }}", label = "Select data for x axis:",
choices = names({{ env_id }}$x))
}
# selection field for y
if ({{ env_id }}$y_selection){
selectInput("select_y_{{ env_id }}", label = "Select data for y axis:",
choices = names({{ env_id }}$y))
}
```
Plot description:
Sequencing is called *saturated* when generating more sequencing output from a cDNA library does not substantially increase the number of detected features in a sample. Since the number of detected features can act as a technical confounder, and thereby drive substructure in the data, it is advisable to aim for a saturated sequencing by either adding more sequencing output or decreasing the number of samples until saturation is achieved. [@zhang_one_2018] gives advise on how to choose the optimal cell number given a fixed sequencing budget
### {{ title }}
<!-- Component created on 2019-05-03 15:14:07 -->
<!-- Component created on {{ date }} -->
```{r}
{{ env_id }} = readRDS("envs/{{ env_id }}.rds")
......@@ -104,3 +104,5 @@ output$plot_{{ env_id }} <- plotly::renderPlotly({
Plot description:
Sequencing is called *saturated* when generating more sequencing output from a cDNA library does not substantially increase the number of detected features in a sample. Since the number of detected features can act as a technical confounder, and thereby drive substructure in the data, it is advisable to aim for a saturated sequencing by either adding more sequencing output or decreasing the number of samples until saturation is achieved. [@zhang_one_2018] gives advise on how to choose the optimal cell number given a fixed sequencing budget
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/features_by_factors.R
\name{features_by_factors}
\alias{features_by_factors}
\title{Renders a features by factor violin plot}
\usage{
features_by_factors(object, x, y, title = "Features by factor")
}
\arguments{
\item{x}{A list with the x-axis values. If it is a nested list, a dropdown-field will be provided in the interactive mode.}
\item{y}{A list with the y-axis values. If it is a nested list, a dropdown-field will be provided in the interactive mode.(Needs to be categorial. Horizontal violinplots are not possible.)}
\item{plot_title}{The title of the Component}
}
\value{
A string containing markdown code for the rendered textbox
}
\description{
Renders a features by factor violin plot
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/multiplot.R
\name{multiplot}
\alias{multiplot}
\title{Renders a Sequence saturation plot}
\usage{
multiplot(object, x, y, title = "Multiplot", colour_by = NULL)
}
\arguments{
\item{x}{A list with the x-axis values. If it is a nested list, a dropdown-field will be provided in the interactive mode.}
\item{y}{A list with the y-axis values. If it is a nested list, a dropdown-field will be provided in the interactive mode.}
\item{colour_by}{A list with the color_by values. If it is a nested list, a dropdown-field will be provided in the interactive mode.}
\item{plot_title}{The title of the Component}
}
\value{
A string containing markdown code for the rendered textbox
}
\description{
Renders a Sequence saturation plot
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sequence_saturation.R
\name{sequence_saturation}
\alias{sequence_saturation}
\title{Renders a Sequence saturation plot}
\usage{
sequence_saturation(object, x, y, colour_by = NULL,
title = "Sequencing saturation")
}
\arguments{
\item{object}{A \linkS4class{i2dash::i2dashboard} object.}
\item{x}{Numeric values mapped to the x-axis. In case of a nested list, a dropdown menu will be provided in the interactive mode.}
\item{y}{Numeric values mapped to the y-axis. In case of a nested list, a dropdown menu will be provided in the interactive mode.}
\item{title}{A title that will be displayed on top.}
\item{coulor_by}{A factor that will be mapped to colours.In case of a nested list, a dropdown menu will be provided in the interactive mode.}
}
\value{
A string containing markdown code for the rendered textbox
}
\description{
Renders a Sequence saturation plot
}
Supports Markdown
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