Welcome to pastaWRAP!¶
pastaWRAP is a Python wrapper for R-based Awesome Toolkit for PASTA, more commonly known as ratPASTA - an R package used for processing and visualising data from startle experiments in rodents or experiments measuring grip strength in rodents. Currently, pastaWRAP only supports ratPASTA functionality for startle experiments, with plans for adding griPASTA (grip strength test) functionality wrapping at a later date. The input data for this package is created with a PASTA solution (Platform for Acoustic STArtle), described in detail here:
Virag, D., Homolak, J., Kodvanj, I., Babic Perhoc, A., Knezovic, A., Osmanovic Barilar, J., & Salkovic-Petrisic, M. (2020). Repurposing a digital kitchen scale for neuroscience research: a complete hardware and software cookbook for PASTA. BioRxiv, 2020.04.10.035766. https://doi.org/10.1101/2020.04.10.035766
Using the same platform for measuring grip strength in rodents is described here:
Homolak, J., Virag, D., Kodvanj, I., Matak, I., Babic Perhoc, A., Knezovic, A., Osmanovic Barilar, J., Salkovic-Petrisic, M. (2020). griPASTA: A hacked kitchen scale for quantification of grip strength in rodents. BioRxiv, 2020.07.23.217737. https://doi.org/10.1101/2020.07.23.217737
Full pastaWRAP source code is available here under the GPLv3 license.
Documentation¶
-
class
pastawrap.
RatPasta
(*args, **kwargs)¶ The RatPasta class used for wrapping the ratPASTA functionality of the ratPASTA R package.
This is a Python class which wraps all ratPASTA R functionality. When instantiated, all parameters are passed to the
load_startle_data()
method, which stores the working data as an R dataframe in self.df. The class also stores its methods’ outputs into appropriate attributes, listed below. The last generated plot is stored in self.last_plot. All plots may be modified by appending rpy2.robjects.lib.ggplot2 functions’ outputs to them using the ‘+’ operator (for more information on available parameters, please see rpy2’s ggplot2 library documentation). All parameters are passed to theload_startle_data()
method’s R function - only some are explained here. For more information, please refer to ratPASTA documentation.- Parameters
addhead (float) – Correction factor for the animal’s latency (before the pulse).
addtail (float) – Correction factor for the animal’s latency (after the pulse).
*args – Arguments, passed verbatim to the respective R function.
**kwargs – Keyword arguments, passed verbatim to the respective R function.
*args – Arguments, passed verbatim to the load_startle_data() method.
**kwargs – Keyword arguments, passed verbatim to the load_startle_data() method.
- Variables
df (rpy2.robjects.vectors.DataFrame) – R dataframe of raw .pasta data imported using load_startle_data(), passed by default to the summary and plotting methods.
summary (dict of pandas.core.frame.DataFrame) – A dictionary containing three pandas dataframes: “values”, “ratio” and “ratio_s”, automatically (re)generated on every data load.
plots (nested dict of rpy2.robjects.lib.ggplot2.GGPlot) – A dictionary containing plots generated by the last invocation of each of the plotting methods. Unlike “basic_startle_plot” and “startle_plot” keys in this dict which contain a ggplot, the “latency_plot” key is a nested dictionary containing latency_vs_cycle and latency_vs_group keys, which contain the corresponding latency plots. All values default to None if the respective method hasn’t been invoked yet.
last_plot (rpy2.robjects.lib.ggplot2.GGPlot) – Contains the last generated plot by any of the plotting methods.
>>> rp = pastawrap.RatPasta(addhead=0.5, addtail=0.5)
>>> rp.startle_plot(type=2) >>> import rpy2.robjects.lib.ggplot2 as ggplot2 >>> rp.last_plot += ggplot2.theme_light()
-
basic_startle_plot
(df=None, *args, **kwargs)¶ Plotting method. Calls ratPASTA’s basicStartlePlot()
All parameters are passed to the respective R function. For more information, please refer to ratPASTA documentation.
- Parameters
df – R dataframe to be plotted, defaults to
self.df
(auto-generated usingload_startle_data()
when instantiating theRatPasta
class)*args – Arguments, passed verbatim to the respective R function.
**kwargs – Keyword arguments, passed verbatim to the respective R function.
- Returns
A ggplot, which is also stored in self.plots and self.last_plot.
- Return type
rpy2.robjects.lib.ggplot2.GGPlot
-
latency_plot
(df=None, *args, **kwargs)¶ Plotting method. Calls ratPASTA’s latencyPlot()
All parameters are passed to the respective R function. For more information, please refer to ratPASTA documentation.
- Parameters
df (rpy2.robjects.vectors.DataFrame) – R dataframe to be plotted, defaults to
self.df
(auto-generated usingload_startle_data()
when instantiating theRatPasta
class)*args – Arguments, passed verbatim to the respective R function.
**kwargs – Keyword arguments, passed verbatim to the respective R function.
- Returns
A dict containing two ggplots: latency_vs_cycle and latency_vs_group
- Return type
dict of rpy2.robjects.lib.ggplot2.GGPlot
-
load_startle_data
(*args, **kwargs)¶ Load startle data. Calls ratPASTA’s loadStartleData()
Clears all instance attributes on load and regenerates self.summary so as to avoid confusing freshly loaded data with plots and summaries of old data. All parameters are passed to the respective R function - only some are explained here. For more information, please refer to ratPASTA documentation.
- Parameters
addhead (float) – Correction factor for the animal’s latency (before the pulse).
addtail (float) – Correction factor for the animal’s latency (after the pulse).
*args – Arguments, passed verbatim to the respective R function.
**kwargs – Keyword arguments, passed verbatim to the respective R function.
- Returns
R dataframe which can be passed to pastaWRAP plotting methods.
- Return type
rpy2.robjects.vectors.DataFrame
-
plot_close
()¶ Closes the ggplot2 plotting window.
-
plot_save
(plot=None, plot_key=None, *args, **kwargs)¶ Saves a plot using ggsave.
Saves the last plot generated, or the one specified by plot, using the ggsave wrapper function,
r_ggsave()
. For more information, please refer to ggplot2’s ggsave documentation.- Parameters
plot (str) – Plot to save, defaults to the last generated plot (
self.last_plot
).- Returns
None
>>> rp.plot_save(filename="test.png", width=10, height=8, dpi=150, units="in", device="png")
-
plot_show
(plot_key=None)¶ Shows the ggplot2 plotting window.
Displays the last plot generated (stored in
self.last_plot
) in a ggplot2 plotting window.- Parameters
plot_key (str) – Currently only used when displaying a latency plot, in which case it can be either latency_vs_cycle or latency_vs_group, defaults to None.
- Returns
None
>>> rp.plot_show() # usual usage >>> rp.plot_show(plot_key="latency_vs_group") # for latency plots
-
startle_plot
(df=None, type=None, *args, **kwargs)¶ Plotting method. Calls ratPASTA’s startlePlot()
All parameters are passed to the respective R function. For more information, please refer to ratPASTA documentation.
- Parameters
df (rpy2.robjects.vectors.DataFrame) – R dataframe to be plotted, defaults to
self.df
(auto-generated usingload_startle_data()
when instantiating theRatPasta
class)type (int) – Type of startle plot. Please refer to ratPASTA documentation for available types.
*args – Arguments, passed verbatim to the respective R function.
**kwargs – Keyword arguments, passed verbatim to the respective R function.
- Returns
A ggplot, which is also stored in
self.plots
andself.last_plot
.- Return type
rpy2.robjects.lib.ggplot2.GGPlot
-
summarise_startle
(df=None, *args, **kwargs)¶ Generate a summary. Calls ratPASTA’s summariseStartle()
All parameters are passed to the respective R function. For more information, please refer to ratPASTA documentation.
- Parameters
df – R dataframe to be processed, defaults to
self.df
(auto-generated usingload_startle_data()
when instantiating the RatPasta class)*args – Arguments, passed verbatim to the respective R function.
**kwargs – Keyword arguments, passed verbatim to the respective R function.
- Returns
A dictionary containing three pandas dataframes: values, ratio and ratio_s, which is also stored in
self.summary
.- Return type
dict of pandas.core.frame.DataFrame
-
pastawrap.
r_ggsave
(*args, **kwargs)¶ A wrapper for R ggplot2’s ggsave function.
All parameters are passed to the respective R function. For more information, please refer to the ggplot2 documentation.
- Parameters
*args – Arguments, passed verbatim to the respective R function.
**kwargs – Keyword arguments, passed verbatim to the respective R function.
- Returns
None
-
pastawrap.
r_install_packages
(package)¶ A wrapper for R utils install.packages function.
All parameters are passed to the respective R function. For more information, please refer to the R utils documentation.
- Parameters
*args – Arguments, passed verbatim to the respective R function.
**kwargs – Keyword arguments, passed verbatim to the respective R function.
- Returns
None