Commit df2ed35f authored by Paul Michaelis's avatar Paul Michaelis
Browse files

added create_nodedf function, small changes to browser

parent 340ad72a
......@@ -11,7 +11,7 @@ Encoding: UTF-8
LazyData: true
biocViews:
Imports:
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
Suggests:
clusterProfiler (>= 3.10.0),
mgcv (>= 1.8.24),
......
......@@ -5,6 +5,7 @@ export(add_pw_protection)
export(arrayqc)
export(calc_logfc)
export(calc_logfc_public)
export(create_nodedf)
export(create_nodelist)
export(create_nodelist_voom)
export(create_shiny_mapplotlist)
......
#' Create logFC Nodelist
#'
#' A simple wrapper function to applying create_nodedf() to all nodes in a nodeframe.
#'
#' @param elist An limma EList object with normalized logFC values
#' @param nodeframe a nodeframe describing the associations of genes in the toxicogenomic universe
#' @param keep_recovery (Boolean) Defaults to False, intended for tcta fit, set to True if recoveries should be analysed
......@@ -18,100 +20,67 @@ create_nodelist <- function(elist, nodeframe, keep_recovery = F) {
} # for smoothed datasets
# create list with logFC and metadata for each node -----------------------
if (!keep_recovery) {
nodelist <-
nodelist <-
lapply(
X = seq(1, max(nodeframe_elist$node)),
FUN = function(nodeID) {
if (sum(nodeframe_elist$node == nodeID) > 0) {
logFC <-
c(t(elist$E[elist$genes$ProbeName %in% nodeframe_elist$ProbeID[nodeframe_elist$node == nodeID], elist$targets$type != "recovery"]))
concentration <-
rep(
elist$targets$concentration[elist$targets$type != "recovery"],
times = sum(nodeframe_elist$node == nodeID)
)
concentration_level <-
rep(
elist$targets$concentration_level[elist$targets$type != "recovery"],
times = sum(nodeframe_elist$node == nodeID)
)
time_hpe_factor <-
ordered(rep(
elist$targets$time_hpe[elist$targets$type != "recovery"],
times = sum(nodeframe_elist$node == nodeID)
))
time_hpe <-
rep(elist$targets$time_hpe[elist$targets$type != "recovery"],
times = sum(nodeframe_elist$node == nodeID))
probe_id <-
rep(as.character(nodeframe_elist$ProbeID)[nodeframe_elist$node == nodeID], each = nrow(t(elist$E[elist$genes$ProbeName %in% nodeframe_elist$ProbeID[nodeframe_elist$node == nodeID], elist$targets$type != "recovery"])))
ensembl_gene_id <-
rep(as.character(nodeframe_elist$ensembl)[nodeframe_elist$node == nodeID], each = nrow(t(elist$E[elist$genes$ProbeName %in% nodeframe_elist$ProbeID[nodeframe_elist$node == nodeID], elist$targets$type != "recovery"])))
substance <- elist$targets$substance[1]
type <-
rep(
elist$targets$type[elist$targets$type != "recovery"],
times = sum(nodeframe_elist$node == nodeID)
)
probeframe <-
data.frame(
logFC = logFC,
concentration = concentration,
concentration_level = concentration_level,
time_hpe_factor = time_hpe_factor,
time_hpe = time_hpe,
probe_id = probe_id,
ensembl_gene_id = ensembl_gene_id,
nodeID = nodeID,
substance = substance,
type = type
)
return(probeframe)
} else {
return(NA)
}
}
X = seq(1, max(nodeframe_elist$node)),
FUN = create_nodedf,
elist = elist,
nodeframe = nodeframe,
keep_recovery = keep_recovery
)
} else {
nodelist <-
lapply(
X = seq(1, max(nodeframe_elist$node)),
FUN = function(nodeID) {
if (sum(nodeframe_elist$node == nodeID) > 0) {
logFC <-
c(t(elist$E[elist$genes$ProbeName %in% nodeframe_elist$ProbeID[nodeframe_elist$node == nodeID],]))
concentration <-
rep(
elist$targets$concentration,
times = sum(nodeframe_elist$node == nodeID)
)
concentration_level <-
rep(
elist$targets$concentration_level,
times = sum(nodeframe_elist$node == nodeID)
)
time_hpe_factor <-
ordered(rep(
nodelist
}
#' Create a nodedf
#'
#' Creates a data frame with logFC and metadata for a single node
#'
#' @param nodeID id of the node
#' @param elist limma elist
#' @param nodeframe a nodeframe describing the associations of genes in the toxicogenomic universe
#' @param keep_recovery (Boolean) Defaults to False, intended for tcta fit, set to True if recoveries should be analysed
#'
#' @return a data frame or NA if the node does noch contain any genes
#' @export
#'
create_nodedf = function(nodeID, elist, nodeframe, keep_recovery = F) {
nodeframe$ensembl <- as.character(nodeframe$ensembl)
nodeframe$ProbeID <- as.character(nodeframe$ProbeID)
elist$genes$ProbeName <- as.character(elist$genes$ProbeName)
nodeframe_elist <- nodeframe[!is.na(nodeframe$ProbeID), ]
if (is.null(elist$targets$type)) {
elist$targets$type <- "treatment"
} # for smoothed datasets
if (sum(nodeframe_elist$node == nodeID) > 0) {
logFC <-
c(t(elist$E[elist$genes$ProbeName %in% nodeframe_elist$ProbeID[nodeframe_elist$node == nodeID], ]))
concentration <-
rep(elist$targets$concentration,
times = sum(nodeframe_elist$node == nodeID))
concentration_level <-
rep(elist$targets$concentration_level,
times = sum(nodeframe_elist$node == nodeID))
time_hpe_factor <-
ordered(rep(
elist$targets$time_hpe,
times = sum(nodeframe_elist$node == nodeID)
))
time_hpe <-
rep(elist$targets$time_hpe,
times = sum(nodeframe_elist$node == nodeID))
probe_id <-
rep(as.character(nodeframe_elist$ProbeID)[nodeframe_elist$node == nodeID], each = nrow(t(elist$E[elist$genes$ProbeName %in% nodeframe_elist$ProbeID[nodeframe_elist$node == nodeID],])))
ensembl_gene_id <-
rep(as.character(nodeframe_elist$ensembl)[nodeframe_elist$node == nodeID], each = nrow(t(elist$E[elist$genes$ProbeName %in% nodeframe_elist$ProbeID[nodeframe_elist$node == nodeID],])))
substance <- elist$targets$substance[1]
type <-
rep(
elist$targets$type,
times = sum(nodeframe_elist$node == nodeID)
)
probeframe <-
data.frame(
))
time_hpe <-
rep(elist$targets$time_hpe,
times = sum(nodeframe_elist$node == nodeID))
probe_id <-
rep(elist$genes$ProbeName[elist$genes$ProbeName %in% nodeframe_elist$ProbeID[nodeframe_elist$node == nodeID]], each = nrow(t(elist$E[elist$genes$ProbeName %in% nodeframe_elist$ProbeID[nodeframe_elist$node == nodeID], ])))
ensembl_gene_id <-
rep(elist$genes$ensembl_gene_id[elist$genes$ProbeName %in% nodeframe_elist$ProbeID[nodeframe_elist$node == nodeID]], each = nrow(t(elist$E[elist$genes$ProbeName %in% nodeframe_elist$ProbeID[nodeframe_elist$node == nodeID], ])))
substance <- elist$targets$substance[1]
type <-
rep(elist$targets$type,
times = sum(nodeframe_elist$node == nodeID))
probeframe <-
data.frame(
logFC = logFC,
concentration = concentration,
concentration_level = concentration_level,
......@@ -122,15 +91,14 @@ create_nodelist <- function(elist, nodeframe, keep_recovery = F) {
nodeID = nodeID,
substance = substance,
type = type
)
return(probeframe)
} else {
return(NA)
}
)
if (!keep_recovery) {
probeframe = probeframe[probeframe$type != 'recovery',]
}
)
}
nodelist
return(probeframe)
} else {
return(NA)
}
}
......
......@@ -60,7 +60,8 @@ create_shiny_mapplotlist <-
'group',
'model',
'url',
'condition'
'condition',
'unit'
)]
}) %>% do.call('rbind', .) %>%
unique()
......
......@@ -259,7 +259,7 @@ import_seq_data = function(counts,
keep = rowSums(counts) >= ncol(counts) - 1
dge = dge[keep,]
voom = voomWithQualityWeights(
voom = limma::voomWithQualityWeights(
counts = dge,
normalize.method = 'cyclicloess'
)
......
......@@ -5,7 +5,7 @@
#' @return a ggplot
#' @export
#'
plot_noderesponse = function(plot_data) {
plot_noderesponse = function(plot_data, conc_unit = 'µM') {
model = plot_data$model
nodeplot_theme = theme_bw() +
......@@ -59,7 +59,7 @@ plot_noderesponse = function(plot_data) {
) +
scale_colour_discrete(name = "Gene ID") +
ylab("logFC") +
xlab("\n\nexposure concentration [µM]") +
xlab(sprintf('\nexposure concentration [%s]', conc_unit)) +
{
if (model == 'lm') {
# the limits are extended by 20% of the max concentration so the
......
......@@ -30,6 +30,24 @@ tfp_browser = function(filename, version = '4.0.0') {
return(sort(round(breaks, digits = 1)))
}
convert_unit = function(str) {
if (str_detect(str, '^log')) {
log = T
} else {
log = F
}
str = str_remove(str, '^log\\d+_')
if (str_detect(str, '_L$')) {
str = str_remove(str, '_L$')
str = paste0(str, '/L')
}
if (log) {
str = paste0('log(', str, ')')
}
str = str_replace(str, 'u', 'µ')
return(str)
}
# function for plotting text in the space where the SOM would be
generic_plot = function(text, font_size = 5) {
ggplot2::ggplot(data = data.frame(x = 1,
......
......@@ -459,8 +459,12 @@ tfp_server = function(input, output, session) {
output$fingerprintheader = renderText({
sprintf(
'Transcriptomic response for %s at %.2f μmol/L and %s hpe',
'Transcriptomic response for %s at %.2f %s and %s hpe',
input$selectedsubstance1,
targets()$unit[
targets()$group == input$selectedgroup &
targets()$substance == input$selectedsubstance1 &
targets()$concentration_level == input$concselect1][1] %>% convert_unit(),
targets()$concentration[
targets()$group == input$selectedgroup &
targets()$substance == input$selectedsubstance1 &
......@@ -482,6 +486,10 @@ tfp_server = function(input, output, session) {
selected_group = input$selectedgroup
selected_condition = input$selectedcondition1
unit = targets()$unit[targets()$group == selected_group &
targets()$substance == selected_substance &
targets()$concentration_level == input$concselect1][1] %>% convert_unit()
D_measured = tbl(db, 'D_measured_all') %>%
filter(group == selected_group &
substance == selected_substance &
......@@ -510,7 +518,7 @@ tfp_server = function(input, output, session) {
)
if (dim(D_measured)[1] > 0) {
plot_noderesponse(plot_data = plot_data)
plot_noderesponse(plot_data = plot_data, conc_unit = unit)
} else {
# selected node has no data
generic_plot('No measured data for selected node.\n Please select different node.')
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/create_nodelist.R
\name{create_nodedf}
\alias{create_nodedf}
\title{Create a nodedf}
\usage{
create_nodedf(nodeID, elist, nodeframe, keep_recovery = F)
}
\arguments{
\item{nodeID}{id of the node}
\item{elist}{limma elist}
\item{nodeframe}{a nodeframe describing the associations of genes in the toxicogenomic universe}
\item{keep_recovery}{(Boolean) Defaults to False, intended for tcta fit, set to True if recoveries should be analysed}
}
\value{
a data frame or NA if the node does noch contain any genes
}
\description{
Creates a data frame with logFC and metadata for a single node
}
......@@ -17,5 +17,5 @@ create_nodelist(elist, nodeframe, keep_recovery = F)
A List with logFC values for each node of the toxicogenomic universe
}
\description{
Create logFC Nodelist
A simple wrapper function to applying create_nodedf() to all nodes in a nodeframe.
}
......@@ -4,7 +4,7 @@
\alias{plot_noderesponse}
\title{Plot noderesponse over all time points}
\usage{
plot_noderesponse(plot_data)
plot_noderesponse(plot_data, conc_unit = "µM")
}
\arguments{
\item{plot_data}{output from get_nodeplot_data()}
......
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