Title: | A toolkit for analyzing protein quantification results |
---|---|
Description: | What the package does (one paragraph). |
Authors: | Kai Aragaki [aut, cre] |
Maintainer: | Kai Aragaki <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-11-03 06:08:10 UTC |
Source: | https://github.com/KaiAragaki/qp |
Takes an absorbance and converts it to a hexidecimal color. For the default qp_pal palette, this should provide a color that approximates real life color at the given absorbance.
abs_to_col(abs, pal)
abs_to_col(abs, pal)
abs |
Numeric. Absorbances. |
pal |
Character. A vector of hexidecimal colors. |
The absorbances have typical baseline absorbance (~ 0.07) removed, and then an index is calculated with a logistic curve of maximum 100 and a center of 0.15.
Character. Hexidecimal colors corresponding to absorbances.
Absorbances from a BCA protein quantification in a data.frame
absorbances
absorbances
absorbances
A data.frame
with 96 rows and 5 columns:;
The row of the 96 well plate, where 1 refers to the top row.
The column of the 96 well plate, where 1 refers to the left column.
The absorbance of the contents of the well at 562nm.
Denotes whether the sample is a standard or an unknown (sample).
Denotes individual standards/samples, where each gets its own index.
Calculate dilution from known concentrations
dilute(c1, c2 = min(c1), v2, round_for_pipettes = TRUE)
dilute(c1, c2 = min(c1), v2, round_for_pipettes = TRUE)
c1 |
Numeric. Initial concentration of sample. |
c2 |
Numeric. Target concentration of sample. |
v2 |
Numeric. Target final volume of sample. If |
round_for_pipettes |
Logical. If TRUE, rounds values to the accuracy of
standard pipettes using |
a data.frame, with sample_to_add
as the volume of sample to add,
and add_to
as the volume to dilute the sample into.
dilute(203, 70, 10) dilute(203, 70, 10, round_for_pipettes = FALSE) # Vectorized: dilute(c(8, 10, 12), c(4, 5, 6), c(7, 8, 9))
dilute(203, 70, 10) dilute(203, 70, 10, round_for_pipettes = FALSE) # Vectorized: dilute(c(8, 10, 12), c(4, 5, 6), c(7, 8, 9))
Round volume to be pipette-compatible
make_pipette_vol(x)
make_pipette_vol(x)
x |
Numeric. Volume to be rounded |
Numeric. Rounded volume.
make_pipette_vol(104.13398) make_pipette_vol(15.3331) make_pipette_vol(9.9211) # Vectorized: make_pipette_vol(c(104.13398, 15.3331, 9.9211, NA, -100.1))
make_pipette_vol(104.13398) make_pipette_vol(15.3331) make_pipette_vol(9.9211) # Vectorized: make_pipette_vol(c(104.13398, 15.3331, 9.9211, NA, -100.1))
Quantify protein concentration from a MicroBCA assay
qp( x, replicate_orientation = c("h", "v"), sample_names = NULL, remove_empty = TRUE, ignore_outliers = c("all", "samples", "standards", "none"), standard_scale = c(0, 2^((2:7) - 5)), n_replicates = 3, wavelength = 562 )
qp( x, replicate_orientation = c("h", "v"), sample_names = NULL, remove_empty = TRUE, ignore_outliers = c("all", "samples", "standards", "none"), standard_scale = c(0, 2^((2:7) - 5)), n_replicates = 3, wavelength = 562 )
x |
A |
replicate_orientation |
Either 'h' or 'v' - see Details. |
sample_names |
Optional character vector of sample names. |
remove_empty |
Should wells that have less absorbance than the lowest standard be dropped? |
ignore_outliers |
Character. From which group - samples or standards - should outliers be detected and removed? |
standard_scale |
Numeric. Known concentrations of standards, in the order they appear. |
n_replicates |
Numeric. The number of techinical replicates. |
wavelength |
Numeric. The wavelength absorbance was captured. |
If x
is a spectramax
, the standards must start in the upper left
corner in the order dictated by standard_scale
. Whether this is from from
left to right or top to bottom can be specified in replicate_orientation
.
Note that replicate_orientation
specified the direction that REPLICATES
lie, NOT the direction the samples flow (which will be perpendicular to
the replicates).
Note: replicate_orientation
, n_replicates
, and wavelength
will
be silently ignored if x
is not a spectramax
or path to a
spectramax
a tibble
data <- system.file("extdata", "absorbances.txt", package = "qp") qp(data, replicate_orientation = "h")
data <- system.file("extdata", "absorbances.txt", package = "qp") qp(data, replicate_orientation = "h")
Add sample names
qp_add_names(x, ...) ## S3 method for class 'list' qp_add_names(x, sample_names = NULL, ...) ## S3 method for class 'data.frame' qp_add_names(x, sample_names = NULL, ...)
qp_add_names(x, ...) ## S3 method for class 'list' qp_add_names(x, sample_names = NULL, ...) ## S3 method for class 'data.frame' qp_add_names(x, sample_names = NULL, ...)
x |
A |
... |
Unused |
sample_names |
Optional character vector. If NULL, uses sample index. In a standard workflow, the index is the order the sample appears in the plate |
df <- expand.grid( index = c(1, 1, 2, 2, 2, 3), sample_type = c("standard", "unknown") ) df # You don't get to name standards: qp_add_names(df, c("a", "b", "c")) # If there aren't enough names, will use index qp_add_names(df, c("a", "b")) # No names provided will use index by default qp_add_names(df)
df <- expand.grid( index = c(1, 1, 2, 2, 2, 3), sample_type = c("standard", "unknown") ) df # You don't get to name standards: qp_add_names(df, c("a", "b", "c")) # If there aren't enough names, will use index qp_add_names(df, c("a", "b")) # No names provided will use index by default qp_add_names(df)
Add known concentrations of protein to standard samples
qp_add_std_conc(x, standard_scale = c(0, 2^((2:7) - 5)), ...) ## S3 method for class 'data.frame' qp_add_std_conc(x, standard_scale = c(0, 2^((2:7) - 5)), ...) ## S3 method for class 'list' qp_add_std_conc(x, standard_scale = c(0, 2^((2:7) - 5)), ...)
qp_add_std_conc(x, standard_scale = c(0, 2^((2:7) - 5)), ...) ## S3 method for class 'data.frame' qp_add_std_conc(x, standard_scale = c(0, 2^((2:7) - 5)), ...) ## S3 method for class 'list' qp_add_std_conc(x, standard_scale = c(0, 2^((2:7) - 5)), ...)
x |
A |
standard_scale |
A numeric vector giving the concentrations of the standards. The units are arbitrary, but will determine the units of the output concentrations. |
... |
Unused |
Input is expected to have two columns:
sample_type
: A character vector denoting which samples are standards
with "standard". All other values will be considered unknowns.
index
: A numeric column denoting the sample number. Index 1 will
correspond to the first item in standard_scale
, 2 will be the second,
etc.
Same type as x, with a .conc
column
abs <- expand.grid( sample_type = c("standard", "unknown"), index = 1:7 ) abs qp_add_std_conc(abs) # Can add custom scale - doesn't have to be 'in order' or unique: qp_add_std_conc(abs, c(1, 4, 2, 2, 3, 0.125, 7)) # Will warn - more values in `standard_scale` than standard indices # Will drop extra qp_add_std_conc(abs, 1:8) # Will error - fewer values in `standard_scale` than standard indices if (FALSE) { qp_add_std_conc(abs, 1:6) }
abs <- expand.grid( sample_type = c("standard", "unknown"), index = 1:7 ) abs qp_add_std_conc(abs) # Can add custom scale - doesn't have to be 'in order' or unique: qp_add_std_conc(abs, c(1, 4, 2, 2, 3, 0.125, 7)) # Will warn - more values in `standard_scale` than standard indices # Will drop extra qp_add_std_conc(abs, 1:8) # Will error - fewer values in `standard_scale` than standard indices if (FALSE) { qp_add_std_conc(abs, 1:6) }
Calculate absorbance means with optional outlier removal
qp_calc_abs_mean(x, ignore_outliers = c("all", "standards", "samples", "none")) ## S3 method for class 'data.frame' qp_calc_abs_mean(x, ignore_outliers = c("all", "standards", "samples", "none")) ## S3 method for class 'list' qp_calc_abs_mean(x, ignore_outliers = c("all", "standards", "samples", "none"))
qp_calc_abs_mean(x, ignore_outliers = c("all", "standards", "samples", "none")) ## S3 method for class 'data.frame' qp_calc_abs_mean(x, ignore_outliers = c("all", "standards", "samples", "none")) ## S3 method for class 'list' qp_calc_abs_mean(x, ignore_outliers = c("all", "standards", "samples", "none"))
x |
A |
ignore_outliers |
Which sample types should have outliers ignored from
their mean calculations? If |
Input data.frame
must contain the following columns:
sample_type
. Character. Must contain values either "standard" or
"unknown"
index
. Numeric. Denotes sample number.
.abs
. Numeric. Contains absorbance values.
If a boolean .is_outlier
is supplied, that will be used instead.
The input tibble
with an .is_outlier
column and a .mean
column
library(dplyr) abs <- expand.grid( sample_type = c("standard", "unknown"), index = 1:7, rep = 1:3 ) |> dplyr::arrange(sample_type, index, rep) abs$.abs <- abs(rnorm(nrow(abs), mean = abs$index)) # Selecting different subsets for outlier removal qp_calc_abs_mean(abs, "none") qp_calc_abs_mean(abs, "standards") qp_calc_abs_mean(abs, "samples") qp_calc_abs_mean(abs, "all") # If an `.is_outlier` column is provided, that will be used instead: abs$.is_outlier <- rep(c(TRUE, FALSE), length.out = nrow(abs)) qp_calc_abs_mean(abs)
library(dplyr) abs <- expand.grid( sample_type = c("standard", "unknown"), index = 1:7, rep = 1:3 ) |> dplyr::arrange(sample_type, index, rep) abs$.abs <- abs(rnorm(nrow(abs), mean = abs$index)) # Selecting different subsets for outlier removal qp_calc_abs_mean(abs, "none") qp_calc_abs_mean(abs, "standards") qp_calc_abs_mean(abs, "samples") qp_calc_abs_mean(abs, "all") # If an `.is_outlier` column is provided, that will be used instead: abs$.is_outlier <- rep(c(TRUE, FALSE), length.out = nrow(abs)) qp_calc_abs_mean(abs)
Predict concentrations from standards fit
qp_calc_conc(x, ignore_outliers = TRUE, group_cols = c("sample_type", "index"))
qp_calc_conc(x, ignore_outliers = TRUE, group_cols = c("sample_type", "index"))
x |
A list. See details. |
ignore_outliers |
Boolean. Should outliers be considered when calculating the mean? See details. |
group_cols |
Character vector. Columns to group by before taking the mean. |
The supplied list should contain two items - fit
, generated by
qp_fit
, and qp
, a data.frame. qp
should contain the following:
Columns used in fit
. Usually, this is .log2_abs
Any columns in group_cols
If ignore_outliers = TRUE
, .is_outlier
will be used if supplied,
or created if not.
Returns a list
with the input fit and data.frame, with additional
columns:
.pred
: The predicted value from the provided model
.pred_conc
: .pred
, transformed by conc_transform
.pred_conc_mean
: The mean of .pred_conc
, sans samples where column
.is_outlier == TRUE
data <- system.file("extdata", "absorbances.txt", package = "qp") calculated <- qp(data, replicate_orientation = "h") # Making a minimal object: calculated$qp <- calculated$qp |> dplyr::select( .log2_abs, sample_type, index, .is_outlier ) calculated qp_calc_conc(calculated)
data <- system.file("extdata", "absorbances.txt", package = "qp") calculated <- qp(data, replicate_orientation = "h") # Making a minimal object: calculated$qp <- calculated$qp |> dplyr::select( .log2_abs, sample_type, index, .is_outlier ) calculated qp_calc_conc(calculated)
Calculate dilutions from predicted concentrations
qp_dilute(x, ...) ## S3 method for class 'data.frame' qp_dilute( x, target_conc = NULL, target_vol = 15, remove_standards = FALSE, pipette_vol_compat = TRUE, ... ) ## S3 method for class 'list' qp_dilute( x, target_conc = NULL, target_vol = 15, remove_standards = FALSE, ... )
qp_dilute(x, ...) ## S3 method for class 'data.frame' qp_dilute( x, target_conc = NULL, target_vol = 15, remove_standards = FALSE, pipette_vol_compat = TRUE, ... ) ## S3 method for class 'list' qp_dilute( x, target_conc = NULL, target_vol = 15, remove_standards = FALSE, ... )
x |
A |
... |
Unused |
target_conc |
Numeric vector. Target concentration in (mg/mL) protein. If length == 1, recycled. |
target_vol |
Target volume in uL. If length == 1, recycled. |
remove_standards |
Boolean. Should standards be removed from results? |
pipette_vol_compat |
Boolean. Shold returned numbers be rounded to the typically precision of a pipette? |
Same as input, with the volumes of lysate and volumes of diluent to add.
df <- data.frame(.pred_conc = 1) qp_dilute(df, target_conc = 0.5, target_vol = 30) # Many sample and target concentrations df2 <- data.frame(.pred_conc = 1:3) qp_dilute(df2, target_conc = c(0.1, 0.4, 0.8), target_vol = 30) # Takes a list, so long as it has a data.frame named qp as one of the items: ls <- list(qp = data.frame(.pred_conc = 3)) qp_dilute(ls, target_conc = 0.5, target_vol = 30)
df <- data.frame(.pred_conc = 1) qp_dilute(df, target_conc = 0.5, target_vol = 30) # Many sample and target concentrations df2 <- data.frame(.pred_conc = 1:3) qp_dilute(df2, target_conc = c(0.1, 0.4, 0.8), target_vol = 30) # Takes a list, so long as it has a data.frame named qp as one of the items: ls <- list(qp = data.frame(.pred_conc = 3)) qp_dilute(ls, target_conc = 0.5, target_vol = 30)
Fit an lm using standards absorbances
qp_fit(x) ## S3 method for class 'data.frame' qp_fit(x) ## S3 method for class 'list' qp_fit(x)
qp_fit(x) ## S3 method for class 'data.frame' qp_fit(x) ## S3 method for class 'list' qp_fit(x)
x |
A |
The supplied data.frame
must have the following columns:
sample_type
. Character. If not 'standard', assumed to be a sample
.is_outlier
. Boolean. If TRUE, assumed to be outlier and removed from
fitting. If FALSE or NA, used for fitting. If unsupplied, will create one
with all values set to NA.
.conc
. Numeric. Known concentration of standard.
.log2_abs
. Numeric. The log2 of the absorbances
A list containing:
fit
, an lm
object fit with the formula .log2_conc ~ .log2_abs
, fit
using non-outlier standards
qp
, the input data
absorbances |> qp_add_std_conc() |> qp_fit()
absorbances |> qp_add_std_conc() |> qp_fit()
Mark absorbance outliers
qp_mark_outliers(x, ignore_outliers = c("all", "standards", "samples", "none")) ## S3 method for class 'data.frame' qp_mark_outliers(x, ignore_outliers = c("all", "standards", "samples", "none")) ## S3 method for class 'list' qp_mark_outliers(x, ignore_outliers = c("all", "standards", "samples", "none"))
qp_mark_outliers(x, ignore_outliers = c("all", "standards", "samples", "none")) ## S3 method for class 'data.frame' qp_mark_outliers(x, ignore_outliers = c("all", "standards", "samples", "none")) ## S3 method for class 'list' qp_mark_outliers(x, ignore_outliers = c("all", "standards", "samples", "none"))
x |
A |
ignore_outliers |
Which sample types should have outliers marked? |
Input data.frame
must contain the following columns:
sample_type
. Character. Must contain values either "standard" or
"unknown"
index
. Numeric. Denotes sample number.
.abs
. Numeric. Contains absorbance values.
The input tibble
with an .is_outlier
column
df <- data.frame( sample_type = rep(c("standard", "unknown"), each = 3), index = c(1, 1, 1, 2, 2, 2), .abs = c(1, 1, 1, 1, 1, 2) ) qp_mark_outliers(df, ignore_outliers = "all") qp_mark_outliers(df, ignore_outliers = "standards") qp_mark_outliers(df, ignore_outliers = "samples") qp_mark_outliers(df, ignore_outliers = "none")
df <- data.frame( sample_type = rep(c("standard", "unknown"), each = 3), index = c(1, 1, 1, 2, 2, 2), .abs = c(1, 1, 1, 1, 1, 2) ) qp_mark_outliers(df, ignore_outliers = "all") qp_mark_outliers(df, ignore_outliers = "standards") qp_mark_outliers(df, ignore_outliers = "samples") qp_mark_outliers(df, ignore_outliers = "none")
It attempts to match the real life colors of a protein quantification
experiment, in combination with abs_to_col
qp_pal
qp_pal
An object of class character
of length 100.
qp
as they were on the plateView the absorbances of an analyzed qp
as they were on the plate
qp_plot_plate(x, size = 15)
qp_plot_plate(x, size = 15)
x |
A |
size |
The size of the points used to illustrate the wells. Passed to geom_point. |
a ggplot
qp_plot_plate(absorbances)
qp_plot_plate(absorbances)
View an absorbance/concentration plot
qp_plot_standards(x)
qp_plot_standards(x)
x |
The output of |
a ggplot
absorbances |> qp() |> qp_plot_standards()
absorbances |> qp() |> qp_plot_standards()
Remove empty wells from data
qp_remove_empty(x) ## S3 method for class 'data.frame' qp_remove_empty(x) ## S3 method for class 'list' qp_remove_empty(x)
qp_remove_empty(x) ## S3 method for class 'data.frame' qp_remove_empty(x) ## S3 method for class 'list' qp_remove_empty(x)
x |
A |
This function keeps any columns with positive .pred_conc
or
sample_type == "standard"
Same as input
df <- expand.grid( .pred_conc = 0:1, sample_type = c("standard", "unknown") ) df qp_remove_empty(df)
df <- expand.grid( .pred_conc = 0:1, sample_type = c("standard", "unknown") ) df qp_remove_empty(df)
Create a report for a protein quantificaiton experiment
qp_report(qp, output_file, other = list())
qp_report(qp, output_file, other = list())
qp |
Likely the output from |
output_file |
Character. The path of the file to export, including
|
other |
Generally used for Shiny application. Assumes a named list of key-values that will be used to document report parameters. |
## Not run: absorbances |> qp() |> qp_dilute() |> qp_report( "~/my_report.html", other = list(key = "value") # Essentially metadata ) ## End(Not run)
## Not run: absorbances |> qp() |> qp_dilute() |> qp_report( "~/my_report.html", other = list(key = "value") # Essentially metadata ) ## End(Not run)
Summarize output from qp pipeline
qp_summarize(x) ## S3 method for class 'data.frame' qp_summarize(x) ## S3 method for class 'list' qp_summarize(x)
qp_summarize(x) ## S3 method for class 'data.frame' qp_summarize(x) ## S3 method for class 'list' qp_summarize(x)
x |
A |
A tibble
with the sample name
, sample_type
, and the mean of its
predicted concentration (.pred_conc_mean
)
Read in and wrangle protein quantification data
qp_tidy(x, ...) ## S3 method for class 'character' qp_tidy(x, ...) ## S3 method for class 'spectramax' qp_tidy( x, replicate_orientation = c("h", "v"), n_standards = 7, n_replicates = 3, wavelength = 562, ... ) ## S3 method for class 'gp' qp_tidy(x, ...) ## Default S3 method: qp_tidy(x, ...)
qp_tidy(x, ...) ## S3 method for class 'character' qp_tidy(x, ...) ## S3 method for class 'spectramax' qp_tidy( x, replicate_orientation = c("h", "v"), n_standards = 7, n_replicates = 3, wavelength = 562, ... ) ## S3 method for class 'gp' qp_tidy(x, ...) ## Default S3 method: qp_tidy(x, ...)
x |
A |
... |
Arguments passed to relevant methods. |
replicate_orientation |
Character. Specified the direction the
replicates lie, not the direction the samples flow (which will be
perpendicular to |
n_standards |
Numeric. The number of different concentrations of standards. Does not include replicates. |
n_replicates |
Numeric. The number of replicates per sample. |
wavelength |
Numeric. For SPECTRAmax files and objects, the wavelength measured. Otherwise, ignored. |
qp
assumes that if you read in data not in a spectramax
file or
object, you probably have a custom workflow in mind - therefore, tidying
will be minimal and mostly focused on checking for validity.
a data.frame
data <- system.file("extdata", "absorbances.txt", package = "qp") qp_tidy(data)
data <- system.file("extdata", "absorbances.txt", package = "qp") qp_tidy(data)