Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
iTox
toxprofileR2
Commits
df2ed35f
Commit
df2ed35f
authored
Nov 08, 2022
by
Paul Michaelis
Browse files
added create_nodedf function, small changes to browser
parent
340ad72a
Changes
11
Hide whitespace changes
Inline
Side-by-side
DESCRIPTION
View file @
df2ed35f
...
...
@@ -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),
...
...
NAMESPACE
View file @
df2ed35f
...
...
@@ -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)
...
...
R/create_nodelist.R
View file @
df2ed35f
#' 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
)
}
}
...
...
R/data_for_shiny.R
View file @
df2ed35f
...
...
@@ -60,7 +60,8 @@ create_shiny_mapplotlist <-
'group'
,
'model'
,
'url'
,
'condition'
'condition'
,
'unit'
)]
})
%>%
do.call
(
'rbind'
,
.
)
%>%
unique
()
...
...
R/import_data.R
View file @
df2ed35f
...
...
@@ -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'
)
...
...
R/plottimepoint.R
View file @
df2ed35f
...
...
@@ -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
...
...
R/tfp_browser.R
View file @
df2ed35f
...
...
@@ -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
,
...
...
R/tfp_server.R
View file @
df2ed35f
...
...
@@ -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.'
)
...
...
man/create_nodedf.Rd
0 → 100644
View file @
df2ed35f
% 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
}
man/create_nodelist.Rd
View file @
df2ed35f
...
...
@@ -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.
}
man/plot_noderesponse.Rd
View file @
df2ed35f
...
...
@@ -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()}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment