Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
shinyscreen
Manage
Activity
Members
Labels
Plan
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Environmental Cheminformatics
shinyscreen
Commits
43a3ed3e
Unverified
Commit
43a3ed3e
authored
4 years ago
by
Todor Kondic
Browse files
Options
Downloads
Patches
Plain Diff
mix,api,resources: Start making the plot system more flexible
parent
dbaffff2
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
R/api.R
+49
-1
49 additions, 1 deletion
R/api.R
R/mix.R
+67
-0
67 additions, 0 deletions
R/mix.R
R/resources.R
+12
-1
12 additions, 1 deletion
R/resources.R
with
128 additions
and
2 deletions
R/api.R
+
49
−
1
View file @
43a3ed3e
...
...
@@ -491,9 +491,57 @@ subset_summary <- function(m) {
m
}
#' @export
create_plots
<-
function
(
m
)
{
## Empty ms1_plot table.
## Select the data nedeed for plotting.
x
<-
m
$
out
$
tab
$
flt_summ
ms1_plot_data
<-
gen_base_ms1_plot_tab
(
summ
=
x
,
ms1_spec
=
m
$
out
$
tab
$
ms1_spec
)
group_data
<-
m
$
conf
$
figures
$
grouping
plot_group
<-
group_data
$
group
plot_plot
<-
group_data
$
plot
plot_label
<-
group_data
$
label
plot_index
<-
c
(
plot_group
,
plot_plot
,
plot_label
)
## All the possible curve labels.
all_labels
<-
x
[,
unique
(
.SD
),
.SDcols
=
plot_label
][[
plot_label
]]
## Plot styling.
style_eic_ms1
<-
plot_decor
(
m
,
m
$
conf
$
logaxes
$
ms1_eic_int
,
all_labels
=
all_labels
,
legend_name
=
plot_label
)
style_eic_ms2
<-
plot_decor
(
m
,
m
$
conf
$
logaxes
$
ms2_eic_int
,
all_labels
=
all_labels
,
legend_name
=
plot_label
)
style_spec_ms2
<-
plot_decor
(
m
,
m
$
conf
$
logaxes
$
ms2_spec_int
,
all_labels
=
all_labels
,
legend_name
=
plot_label
)
## Generate MS1 EIC plots.
ms1_plot
<-
ms1_plot_data
[,
.
(
fig
=
{
df
<-
.SD
[,
data.table
::
rbindlist
(
Map
(
function
(
a
,
b
,
c
,
d
)
{
s
<-
a
[[
1
]]
s
$
plot_label
<-
b
s
$
rt_peak
<-
c
s
$
mz
<-
d
s
},
eicMS1
,
.SD
[[
..plot_label
]],
rt_peak
,
mz
))]
list
(
plot_eic_ms1
(
df
,
style_fun
=
style_eic_ms1
,
plot_label
=
..plot_label
))
}),
by
=
c
(
plot_group
,
plot_plot
)]
m
$
out
$
tab
$
ms1_plot
<-
ms1_plot
m
}
create_plots_old
<-
function
(
m
)
{
## Helpers
textf
<-
ggplot2
::
element_text
x
<-
m
$
out
$
tab
$
ms1_spec
...
...
This diff is collapsed.
Click to expand it.
R/mix.R
+
67
−
0
View file @
43a3ed3e
...
...
@@ -1045,3 +1045,70 @@ get_coord_lim <- function(new,def) {
if
(
length
(
new
[[
2
]])
==
0
)
res
[[
2
]]
<-
def
[[
2
]]
res
}
gen_base_ms1_plot_tab
<-
function
(
summ
,
ms1_spec
)
{
ident
<-
c
(
"set"
,
"adduct"
,
"tag"
,
"ID"
,
"mz"
,
"Files"
)
res
<-
summ
[
ms1_spec
,
c
(
.SD
,
list
(
rt_peak
=
i.ms1_rt
,
eicMS1
=
lapply
(
i.eicMS1
,
list
))),
.SDcols
=
ident
,
on
=
BASE_KEY
,
nomatch
=
NULL
]
setkeyv
(
res
,
cols
=
BASE_KEY
)
res
}
plot_decor
<-
function
(
m
,
islog
,
all_labels
,
legend_name
)
{
textf
<-
ggplot2
::
element_text
## Logarithmic, or linear y axis?
scale_y
<-
if
(
shiny
::
isTruthy
(
islog
))
ggplot2
::
scale_y_log10
else
ggplot2
::
scale_y_continuous
rt_new_lim
<-
c
(
rt_in_min
(
m
$
conf
$
figures
$
rt_min
),
rt_in_min
(
m
$
conf
$
figures
$
rt_max
))
rt_lim
<-
get_coord_lim
(
rt_new_lim
,
DEFAULT_RT_RANGE
)
my_theme
<-
function
(
...
)
ggplot2
::
theme
()
getpal
<-
colorRampPalette
(
RColorBrewer
::
brewer.pal
(
8
,
"Dark2"
))
col_all_vals
<-
getpal
(
length
(
all_labels
))
names
(
col_all_vals
)
<-
all_labels
scale_colour
<-
function
(
breaks
,
labels
,
...
)
ggplot2
::
scale_colour_manual
(
values
=
col_all_vals
,
breaks
=
breaks
,
labels
=
labels
,
name
=
legend_name
,
...
)
my_coord
<-
ggplot2
::
coord_cartesian
(
xlim
=
rt_lim
)
function
(
plot
,
breaks
,
labels
)
plot
+
my_coord
+
scale_colour
(
breaks
=
breaks
,
labels
=
labels
)
+
scale_y
()
+
my_theme
()
}
plot_eic_ms1
<-
function
(
df
,
style_fun
,
plot_label
)
{
mk_leg_lab
<-
function
(
tag
,
rt
)
{
if
(
length
(
tag
)
>
0
)
paste
(
tag
,
"; rt= "
,
formatC
(
rt
,
format
=
'f'
,
digits
=
RT_DIGITS
),
" min"
,
sep
=
''
)
else
character
(
0
)}
mz
<-
df
[,
unique
(
mz
)]
tbl
<-
df
[,
.
(
verb_labs
=
mk_leg_lab
(
plot_label
,
rt_peak
),
plot_label
),
by
=
c
(
"plot_label"
,
"rt_peak"
)]
verb_labs
<-
tbl
[,
verb_labs
]
labs
<-
tbl
[,
plot_label
]
df
[,
plot_label
:=
factor
(
plot_label
)]
style_fun
(
ggplot2
::
ggplot
(
df
,
ggplot2
::
aes
(
x
=
rt
,
y
=
intensity
,
colour
=
plot_label
)),
breaks
=
labs
,
labels
=
verb_labs
)
+
ggplot2
::
geom_line
(
key_glyph
=
KEY_GLYPH
)
+
ggplot2
::
labs
(
x
=
CHR_GRAM_X
,
y
=
CHR_GRAM_Y
)
}
This diff is collapsed.
Click to expand it.
R/resources.R
+
12
−
1
View file @
43a3ed3e
...
...
@@ -174,7 +174,7 @@ QA_COLS <- c(QA_FLAGS,QA_NUM_REAL,QA_NUM_INT)
MS2_SPEC_COLS
<-
c
(
"adduct"
,
"ID"
,
"CE"
,
"rt"
,
"Files"
,
"spec"
,
"ms2_max_int"
)
## MS1 spectral table columns
MS1_SPEC_COLS
<-
c
(
"adduct"
,
"
Files"
,
"
ID"
,
"eicMS1"
,
"ms1_int"
,
"ms1_rt"
,
"ms1_mean"
)
MS1_SPEC_COLS
<-
c
(
"adduct"
,
"ID"
,
"eicMS1"
,
"ms1_int"
,
"ms1_rt"
,
"ms1_mean"
,
"Files"
)
## Default sorting keys of spectra in the summary table
DEF_KEY_SUMM
<-
c
(
"set"
,
"qa_pass"
,
"ms1_int"
,
"adduct"
,
"mz"
,
"tag"
)
...
...
@@ -193,3 +193,14 @@ FIG_DEF_SUBSET <- c("set","adduct","ID")
REPORT_AUTHOR
<-
"Anonymous"
REPORT_TITLE
<-
"Plots of EICs and MS2 Spectra"
PLOT_FEATURES
<-
c
(
"set"
,
"adduct"
,
"tag"
,
"ID"
,
"CE"
)
## Select the most fundamental group of entries. Within this group,
## each ID is unique.
BASE_KEY
<-
c
(
"adduct"
,
"Files"
,
"ID"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment