knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This package contains tools for analyzing data that quantifies a transient. The package was originally created to analyze the contractions and sarcomeres of cardiomyocytes, but can be used on any vector of time series data quantifying a transient.
Being able to measure and quantify the intensity of cardiomyocyte contraction is very important in developing treatments for cardiovascular diseases that damage cardiac tissue. Cardiomyocyte contraction can be quantified by measuring the flux of Calcium ions across the cell's cytoplasm, or by measuring the intensity of pixel change on a video of beating cardiomyocytes. Cardiomyocyte sarcomere length and spacing can also be analyzed though visual media, though only a single photo is necessary. This R package contains several tools that make analyzing contraction and sarcomere data much more convenient. Because the contraction data (as well as the sarcomere spacing) is a transient (departs from a baseline, then returns to it, and repeats) it can be measured in terms of peaks and/or pulses. This package includes functions that help measure and quantify these peaks and pulses.
Each of the highlighted circles above represents an ROI (region of interest) for a video of cardiomyocyte calcium pulses. An open-source software called ImageJ then calculates the mean pixel change intensity (inside each ROI) over the course of the video as a vector of time series data quantifying the calcium flux transient. In the examples below, "ca_flux" refers to the data set from all of the ROIs, and "Mean1" refers to the first ROI, and "Mean2" the second ROI, etc.
Images of cardiomyocyte sarcomeres can also produce a transient. Using a linear ROI, a vector of transient data (this time over distance rather than time) can be generated by ImageJ and analyzed by this package. In the examples below, "sarc" refers to the sarcomere data, and "Y" refers to the vector of data from the linear ROI.
library(cardiocyte) sarc <- read.csv("sarc.csv", header = TRUE)
find_peaks()
this function takes a vector of time series data quantifying a transient, and returns the location where each peak is located.
find_peaks(ca_flux$Mean1) find_peaks(ca_flux$Mean2) find_peaks(sarc$Y)
correct_baseline()
This function corrects any transient deviation from a baseline, i.e. it makes sure every peak of the transient deviates from the same baseline value. The function takes a vector of time series data quantifying a transient. This function is especially useful when plotting a curve, and can be used in combination with the plot_curve() function (as seen in section 3: Plotting)
bl_corrected <- correct_baseline(ca_flux$Mean1) bl_corrected <- correct_baseline(sarc$Y)
peak_height()
This function takes a vector of time series data quantifying a transient, and returns the height of each peak.
peak_height(ca_flux$Mean1) peak_height(ca_flux$Mean2) peak_height(sarc$Y)
ensemble()
This function takes a vector of time series data quantifying a transient, and extracts all the curves from the trace data. Each row represents an individual peak.
(dat <- ensemble(ca_flux$Mean1)) dat2 <- ensemble(ca_flux$Mean2) dat3 <- ensemble(sarc$Y)
pulse_widths()
This function calculates the widths of pulses. It takes data from an ensemble() matrix (as described above), as well as a specified percentile (p) of the max at which to calculate width.
pulse_widths(dat, .9) pulse_widths(dat2, .9) pulse_widths(dat, .8) pulse_widths(dat3, .9)
time_to_peak()
This function calculates the time that it takes for a pulse to reach its maximum. The function takes a vector of time series data quantifying a transient, and starts calculating time when the value reaches 10% of the peak height. It returns the time calculated for the pulse to go from 10% to maximum peak height.
time_to_peak(ca_flux$Mean1) time_to_peak(ca_flux$Mean2)
percent_peak()
This function divides the locations of each peak by the baseline value at each peak, then multiplies by 100. The function takes takes a vector of time series data quantifying a transient.
percent_peak(ca_flux$Mean1) percent_peak(ca_flux$Mean2) percent_peak(sarc$Y)
percent_peak_height()
This function divides the heights of each peak by the baseline value at each peak, then multiplies by 100. The function takes a vector of time series data quantifying a transient.
percent_peak_height(ca_flux$Mean1) percent_peak_height(ca_flux$Mean2) percent_peak_height(sarc$Y)
max_rates()
This function returns the maximum velocities of each peak on the transient. The function takes a vector of time series data quantifying a transient, and returns both the locations of the maximum up (x.up) and down (x.down) velocities, as well as the values for the maximum up and down velocities.
max_rates(ca_flux$Mean1)
max_rates_baseline()
This function divides the maximum transient velocities by the baseline value at the point where the transient reaches its maximum velocity.
max_rates_bl(ca_flux$Mean1) max_rates_bl(ca_flux$Mean2) max_rates_bl(sarc$Y)
max_rates_ph()
This function divides the maximum transient velocities by the height of that specific peak.
max_rates_ph(ca_flux$Mean1) max_rates_ph(ca_flux$Mean2)
trans_integral()
This function finds the area under a transient, or the integral. Essentially, it finds the sum of the area under all the peaks.
trans_integral(ca_flux$Mean1) trans_integral(ca_flux$Mean2) trans_integral(sarc$Y)
peak_integrals()
This function returns the area under every peak in a transient.
peak_integrals(ca_flux$Mean1) peak_integrals(ca_flux$Mean2) peak_integrals(sarc$Y)
FFT()
This function uses the Fast Fourier Transform method to smooth messy data. Especially useful for plotting. Data can also be normalized with two different methods.
head(FFT(ca_flux$Mean1, y=40, norm = "baseline")) head(FFT(ca_flux$Mean2, y=40, norm = "min")) head(FFT(sarc$Y, y=30))
The cardiocyte package provides functionality to plot annotated transients, both in their original form and as overlays (ensemble) of all peaks.
plot_curve()
We can plot the transients with the plot_curve function
plot_curve(ca_flux$Mean1) plot_curve(sarc$Y)
The package also implements annotations as ggplot layers so you can chain the plots in the usual ggplot fashion:
plot_curve(ca_flux$Mean1) + geom_vel("up") + geom_vel("down") + geom_peaks()
The effects of baseline correction can then be directly visualized.
plot_curve(correct_baseline(ca_flux$Mean1)) + geom_vel("up") + geom_vel("down") + geom_peaks()
Finally, the curves can be extracted an overlaid in an ensemble plot together with an averaged curve with error bounds.The offset parameter indicates how many time points to drop at the start of the acquisition to assist in centering the curves in the ensemble window.
plot_ensemble(ca_flux$Mean1, offset = 3, norm=FALSE)
To account for bleaching over the time course, the curves can be normalized to standardized heights.
plot_ensemble(ca_flux$Mean1, offset = 3, norm=TRUE)
If the data is lengthy with many time points, this alternative method for overlaying the peaks may be more useful.
plot_overlay(ca_flux$Mean1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.