Title: | Work with Look at NanoSIMS Data in R |
---|---|
Description: | R interface for working with nanometer scale secondary ion mass spectrometry (NanoSIMS) data exported from Look at NanoSIMS. |
Authors: | Sebastian Kopf [aut, cre] |
Maintainer: | Sebastian Kopf <[email protected]> |
License: | GPL-3 | file LICENSE |
Version: | 1.2.0 |
Built: | 2025-03-12 05:02:23 UTC |
Source: | https://github.com/kopflab/lans2r |
This function allows easy calculation of any quantities derived from other variables. The new quantities can be assigned to a specific data_type and values, errors as well as the resulting variable names are calculated/constructed based on custom functions that can be provided via the function parameters. calculate_sums, calculate_ratios and calculate_abundances are all based on this and provide an easy way for common standard calculations.
calculate( data, data_type, ..., value_fun, error_fun = function(...) return(NA), name_fun = default_name, filter_new = NULL, quiet = FALSE )
calculate( data, data_type, ..., value_fun, error_fun = function(...) return(NA), name_fun = default_name, filter_new = NULL, quiet = FALSE )
data |
a data frame with lans2r data, can be grouped to do calculations within individual groups |
data_type |
what to call the new data type |
... |
the parameters to send to the value, error and naming function for each derived value. These are always expressions that can include references to variable columns, arithmetic and constants, e.g. c( |
value_fun |
a custom function used to calculate the derived value - needs to match the sets of parameters provided through ... |
error_fun |
a custom function used to calculate the error (sigma) for the derived value - needs to match the sets of parameters provided through ... |
name_fun |
a custom function used to construct the variable name for the derived quantity - needs to match the sets of parameters provided through ... |
filter_new |
an expression to apply as a filter on the new data rows (e.g. plane == "all") |
quiet |
whether the function should output information messages or be quiet (default is to output) |
the original data frame with the newly calculated information appended (data_type == "ion_sum")
Other calculations:
calculate_abundances()
,
calculate_ratios()
,
calculate_sums()
This function calculates the isotope abundances (in %!) and resulting counting statistics error from the raw ion counts. It can be applied to data from both LANS_summary and LANS_maps loading but can be slow if LANS_maps is combined from many analyses.
calculate_abundances(data, ..., name_fun = default_name, quiet = FALSE)
calculate_abundances(data, ..., name_fun = default_name, quiet = FALSE)
data |
a data frame with raw ion counts retrieved from |
... |
the fractional abundances to calculate, each entry is for one fractional abundance with major isotope first, then
minor isotope, e.g. c( |
name_fun |
the naming function, receives ... from the top level, default concatenates 'F' + minor ion name |
quiet |
whether the function should output information messages or be quiet (default is to output) |
the original data frame with the fractional abundance information appended (all fractional abundances are in % and have data_type == "abundance")
Other calculations:
calculate_ratios()
,
calculate_sums()
,
calculate()
This function calculates the ratios and resulting counting statistics error from the raw ion counts. It can be applied to data from both LANS_summary and LANS_maps loading but can be slow if LANS_maps is combined from many analyses. It can also be applied to ion_sums generate by calculate_sums to calculate elemental ratios (careful, ionization efficiencies skew their scaling!)
calculate_ratios(data, ..., name_fun = default_name, quiet = FALSE)
calculate_ratios(data, ..., name_fun = default_name, quiet = FALSE)
data |
a data frame with raw ion counts retrieved from |
... |
the ratios to calculate, each entry is one ratio with major isotope first, then
minor isotope, e.g. c( |
name_fun |
the naming function, receives ... from the top level, default concatenates column names with '/' |
quiet |
whether the function should output information messages or be quiet (default is to output) |
the original data frame with the ratio information appended (all ratios have data_type == "ratio")
Other calculations:
calculate_abundances()
,
calculate_sums()
,
calculate()
This function calculates the ion sums and resulting counting statistics error from multiple raw ion counts. It can be applied to data from both LANS_summary and LANS_maps loading but can be slow if LANS_maps is combined from many analyses. Careful about its error propagation, it assumes it is calculating sums of ions and uses the ion counts themselves for error calculation. This is not suitable for calculating other types of sums where other types of error propagation may be more appropriate.
calculate_sums(data, ..., name_fun = default_name, quiet = FALSE)
calculate_sums(data, ..., name_fun = default_name, quiet = FALSE)
data |
a data frame with raw ion counts retrieved from |
... |
the ion sums to calculate, each entry is for one sum of as many ions as desired,
e.g. c( |
name_fun |
the naming function, receives ... from the top level, default concatenates column names with '+' |
quiet |
whether the function should output information messages or be quiet (default is to output) |
the original data frame with the sums information appended (data_type == "ion_sum")
Other calculations:
calculate_abundances()
,
calculate_ratios()
,
calculate()
See HMR vignette for examples.
load_HMR(folder, prefix, suffix = ".hmr_txt")
load_HMR(folder, prefix, suffix = ".hmr_txt")
folder |
|
prefix |
|
suffix |
|
Load the full ion map data (incl. ROI locations) exported from LANS analyses and attach additional information to each analysis. Uses read_map_data to read individual matlab export files.
load_LANS_maps( analysis, ..., base_dir = ".", ion_data_only = TRUE, quiet = FALSE )
load_LANS_maps( analysis, ..., base_dir = ".", ion_data_only = TRUE, quiet = FALSE )
analysis |
|
... |
|
base_dir |
|
ion_data_only |
|
quiet |
|
Load the ROI summary information exported from LANS analyses and attach additional information to each analysis. Uses read_roi_data to read individual files.
load_LANS_summary( analysis, ..., base_dir = ".", ion_data_only = TRUE, load_zstacks = TRUE, quiet = FALSE )
load_LANS_summary( analysis, ..., base_dir = ".", ion_data_only = TRUE, load_zstacks = TRUE, quiet = FALSE )
analysis |
|
... |
|
base_dir |
|
ion_data_only |
|
load_zstacks |
|
quiet |
|
Helps to plot the ion maps exported and loaded from LANS. Can overlay the ROI boundaries for clarity as well. Note that this does not currently support any smoothing yet so plotting ratios or abundances will most likely not work well because individual pixels have extreme values.
plot_maps( data, draw_ROIs = TRUE, normalize = TRUE, color_scale = c("black", "white") )
plot_maps( data, draw_ROIs = TRUE, normalize = TRUE, color_scale = c("black", "white") )
data |
the ion maps data frame |
draw_ROIs |
whether to draw in the ROIs or not (default TRUE) |
normalize |
whether to normalize the intensity scale for each panel (default TRUE) |
color_scale |
what color scale to use for high and low intensity, default is black & white |
Reads the full matlab data files (.mat) that contain the complete ion maps and ROI outlines for the given LANS analysis folder and returns the data in a concatenated data frame with identifier column 'variable' (=ion), data columns value (ion count) and sigma (error based on counting statistics). Additionally, the column 'ROI' indicates which ROI each pixel belongs to with a value of 0 indicating that it does not belong to any ROI. Note that this only reads ion data files by default and not any derived data files (any ratio or other formulas evaluated by LANS). It does also not currently support z-stacks yet.
read_map_data(mat_folder, ion_data_only = TRUE, quiet = FALSE)
read_map_data(mat_folder, ion_data_only = TRUE, quiet = FALSE)
mat_folder |
|
ion_data_only |
|
quiet |
|
concatenated data_frame with the full ion maps data
Reads the ion data (.dac/.dat) files for the given LANS analysis folder and returns the ROIs data in a concatenated data frame with identifier columns 'ROI' and 'variable' (=ions). Note that this only reads ion data files by default and not any derived data files (any ratio or other formulas evaluated by LANS). If zstacks (i.e. individual planes) are exported from LANS, they can be loaded as well (and are by default). The resulting data frame has a 'plane' column that keeps track of the plane, the value 'all' identifies the combined data for the ROI from all planes.
read_roi_data( dat_folder, ion_data_only = TRUE, load_zstacks = TRUE, quiet = FALSE )
read_roi_data( dat_folder, ion_data_only = TRUE, load_zstacks = TRUE, quiet = FALSE )
dat_folder |
|
ion_data_only |
|
load_zstacks |
|
quiet |
|
concatenated data_frame with all the ROIs' data, with identifier columns 'plane', 'ROI' and 'variable'
This function allows easy spreading into wide format.
spread_data(data, values = TRUE, errors = TRUE)
spread_data(data, values = TRUE, errors = TRUE)
data |
a data frame with lans2r data |
values |
whether to include the values in wide format |
errors |
whether to include the errors in wide format |
the original data frame but in wide format