Repository navigation
Expand file tree
/
Copy pathcontinuous_flow.Rmd
More file actions
175 lines (140 loc) · 8.79 KB
/
Copy pathcontinuous_flow.Rmd
File metadata and controls
175 lines (140 loc) · 8.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
---
title: "Continuous Flow Examples"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Continuous Flow Examples}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
# Introduction
Isoprocessor supports several plotting and data conversion functions specifically for continuous flow data. This vignette shows some of the functionality for continuous flow files read by the [isoreader package](http://isoreader.isoverse.org) (see the [corresponding vignette](http://isoreader.isoverse.org/articles/continuous_flow.html) for details on data retrieval, storage and export).
```{r, warning=FALSE, message=FALSE}
# load isoreader and isoprocessor packages
library(isoreader)
library(isoprocessor)
```
# Reading files
```{r}
# read a few of the continuous flow examples provided with isoreader
cf_files <-
iso_read_continuous_flow(
iso_get_reader_example("continuous_flow_example.cf"),
iso_get_reader_example("continuous_flow_example.iarc"),
iso_get_reader_example("continuous_flow_example.dxf")
)
```
# Chromatograms
Plotting the raw data (i.e. the mass chromatograms) can be done either with the generic `iso_plot_raw_data()` function for a simple plot with default parameters, or directly using the continuous flow specific `iso_plot_continuous_flow()` (recommended), which can be highly customized. Note that the following plot shows the data from all files in their originally recorded signal intensity units. For examples of how to convert to a common unit, see the section on **Signal conversion** further down.
```{r "all data", fig.width = 10, fig.asp = 2}
iso_plot_continuous_flow_data(cf_files)
```
All customization options are described in the function help (`?iso_plot_continuous_flow_data`) and include, for example, plotting only a specific subset of masses (which will omit data from files that don't include this mass):
```{r "select masses", fig.width = 10, fig.asp = 1}
# plot just masses 2, 44 and 45
iso_plot_continuous_flow_data(
cf_files,
data = c("2", "44", "45")
)
```
# Peak Table
Continuous flow data is usually interpreted in the context of the individiual peaks in the chromatogram. For this purpose, isoprocessor provides several functions to set the peak table including `iso_set_peak_table()` (set a peak table manually), `iso_set_peak_table_from_vendor_data_table()` (use the data table precomputed by the vendor software and extracted from the data files by isoreader), and `iso_find_peaks()` (find peaks de novo from the raw chromatographic data). The latter is not yet implemented but coming soon. Here we provide the example of setting the peak table from Isodat-computed data.
```{r}
# this is a convenience function to set peak table from isodat data table, it
# provides detailed information on the information copied to the peak table
cf_files <- iso_set_peak_table_from_isodat_vendor_data_table(cf_files)
# display the resulting peak table now stored in the cf_files for the first file
cf_files[1] %>% iso_get_peak_table() %>% rmarkdown::paged_table()
```
# Peak Labels
Since peak information is often key for interpretating chromatograms, the `iso_plot_continuous_flow_data` function also provides a suite of peak data integration parameters that make it easy to highlight peaks in the chromatogram and label them with any number of desired information. Now that the collection of `cf_files` has peak table information stored within, it is easy to make use of these for visualization.
```{r "with_peak_labels", fig.width = 9, fig.asp = 0.4}
iso_plot_continuous_flow_data(
cf_files,
# select which data to plot and how to plot it
data = c("2", "3"), color = data, panel = NULL,
# specify what to highlight about the peaks (here: bounds, ret. time and dD)
peak_bounds = TRUE,
peak_label = iso_format(rt, dD = d2H, signif = 3),
peak_label_options = list(size = 3),
# specify which labels to display (only the 2 trace, between 500 and 1500s)
peak_label_filter = data == "2 [mV]" & dplyr::between(time.s, 500, 1500)
)
```
# Isotope ratios
Raw data typically only includes ion signals but isotope ratios are often needed to calculate and visualize the data. For this purpose, isoreader provides a dynamic ratio calculation function (`iso_calculate_ratios()`) that accepts any combination of masses, here demonstrated for the standard CO2 ratios $\frac{46}{44}$ and $\frac{45}{44}$. Additionally, the following example demonstrates how the `filter` parameter can be used to exclude plotting artifacts (here e.g. the extreme ratio values seen right after the magnet jump). Notice how the ratios calculated from current intensities are close to 0 (as the real ratios likely are) whereas those calculated from voltages are close to 1 (due to the so chosen, different resistors in the detector circuit). See the section on **Signal conversion** further down on how to scale to uniform intensity units to address this comparison obstacle.
```{r "ratios", fig.width = 10, fig.asp = 0.8}
cf_files <-
cf_files %>%
# calculate 46/44 and 45/44 ratios
iso_calculate_ratios(ratios = c("46/44", "45/44"))
iso_plot_continuous_flow_data(
cf_files,
# visualize ratios along with main ion
data = c("44", "45/44", "46/44"),
# plot all masses but ratios only 0 to 2 to omit peak jump artifacts
filter = category == "mass" | dplyr::between(value, 0, 2)
) + ggplot2::expand_limits(y = -0.3)
```
# Time conversion
Most continuous flow data is reported in time units of seconds but this is not always the most useful unit. Isoreader provides easy time scaling functionality that will work for all standard time units (minutes, hours, days, etc.) regardless of which time units individual isofiles were initially recorded in.
```{r "time conversion", fig.width = 10, fig.asp = 0.5}
# convert to minutes
cf_files <- iso_convert_time(cf_files, to = "minutes")
# plot masses 2 and 3
iso_plot_continuous_flow_data(cf_files, data = c(2, 3))
```
In this context, another useful customization option of the plotting function is the option to select a specific time window (in any time units, regardless of what is plotted), and the possibility to adjust plot aesthetics such as color, linetype, and paneling:
```{r "time window", fig.width = 10, fig.asp = 0.5}
cf_files %>%
# calculate 3/2 ratio on the file
iso_calculate_ratios("3/2") %>%
iso_plot_continuous_flow_data(
# replot masses 2 and 3 together with the ratio for a specific time window
data = c("2", "3", "3/2"),
time_interval = c(10, 13),
time_interval_units = "minutes",
# adjust plot aesthetics to panel by masses vs. ratios and color by traces
panel = category,
color = data,
# add peak labels
peak_label = iso_format(RT = rt, A = amp2),
peak_label_filter = data == "2 [mV]",
peak_label_options = list(size = 4)
)
```
# Signal conversion
Likewise, isoreader can convert between different signal units. This is particularly useful for comparing data files from different mass specs that record signals differentally. The earlier plot of mass 44 illustrated this scenario where some data was recorded in mV and some in nA. Voltages and currents can be scaled within each unit without restriction and with any valid SI prefix (e.g. from mV to V or nA to pA), however, for conversion from voltage to current or vice-versa, the appropriate resistor values need to be provided or be available from the data files themselves. The following is an example of scaling from voltage to current with the resistor values automatically read from the original data files (see file information section for details). Notice how the mass 44 signal is now in the same units for all files and the ratios are on comparable scales because they are calculated from the same unit intensities:
```{r "signal conversion", fig.width = 10, fig.asp = 0.7}
cf_files %>%
# convert all signals to nano ampere
iso_convert_signals(to = "nA") %>%
# re-calculate ratios with the new unuts
iso_calculate_ratios(ratios = c("46/44", "45/44")) %>%
# re-plot same plot as earlier
iso_plot_continuous_flow_data(
data = c("44", "45/44", "46/44"),
filter =
category == "mass" |
(data == "45/44" & dplyr::between(value, 0.005, 0.03)) |
(data == "46/44" & dplyr::between(value, 0, 0.012))
)
```
# Plot styling
Since all isoreader plots are standard [ggplot](http://ggplot2.tidyverse.org/) objects, they can be modified with any ggplot commands. For example to modify the themes:
```{r "styling", fig.width = 10, fig.asp = 0.5}
library(ggplot2)
# replot
iso_plot_continuous_flow_data(cf_files, data = c(2,3)) +
# add vertical dashed line (ggplot functionality)
geom_vline(xintercept = 15, linetype = 2) +
# modify plot styling (ggplot functionality)
theme(text = element_text(size = 20),
legend.position = "none")
```