knitr::opts_chunk$set(echo = TRUE)
This is a quick guide on how to use the RCaMP package. Feel free to follow along with the code in this file to make sure everything is working well. For this file, R code is in boxes, and outputs are boxes with ## before the code.
Before starting, include the following lines of code at the top of your script to install the package from my personal github:
install.packages('devtools') library(devtools) devtools::install_github('allgenesconsidered/RCaMP')
Once installed, the package can be invoked using the following line:
library(RCaMP)
Data from a Ziess experiment incudes several metrics we are not interested in, as well as artifacts introduced by loading the data into R. Here is an example of raw data from the Ziess:
raw_data <- read.csv(file = "./data/CMEC_75_25-1_5_16_17_1.csv") colnames(raw_data) <- c("Time" ,paste("R",c(1:(ncol(raw_data)-1)),sep="")) # Changes colnames (Time, R1, R2, ... Rn) head(raw_data)
PeakFinder has a build in function to automatically clean the data, leaving only the mean intensity values.
raw_data <- readZiessData(path_to_csv = "./data/CMEC_75_25-1_5_16_17_1.csv", time_index = 1, grep_keyword = "IntensityMean") colnames(raw_data) <- c("Time" ,paste("R",c(1:(ncol(raw_data)-1)),sep="")) head(raw_data)
Note that I am nullifying the column names for printing purposes only. You do not nulify column names normally, and you are recommended to change column names after running readZiessData().
For simplicity's sake, I will be loading in another preprocessed dataframe. Samples must be preprocessed to be a dataframe with Time included, and all other columns the mean intensity values of samples. A preprocessed dataset is included in the zip folder:
example <- read.csv('data/CaHandUT1.csv') head(example) # Prints first 6 rows
As a side note, make sure all of your comlumes are numeric/integers. A common mistake with R is that .csv files are loaded with columns being factors.
str(example)
As you can see above, all columns are of type numeric (num). Looking a the second row of the output, $ Time indicates the title of the column, then the datatype, followed by the first few data entries.
To analyze data, I have written a function to wrap the data in an object called dataframeToExperiment(). The 'experiment' object will hold all the intensity values, the time measurments, and all the computed readings. Argument are:
example.object <- dataframeToRCaMP(raw_data = example, time_index = 1, smooth_fxn = T ,smooth_n = 50) print(example.object)
When the object is created, it will run a full test to try and detect errors in the data. Some errors will be patched automatically, while others might have to be excluded from further analysis.
The main functions are analyzeExperiemnt() and runTestGraph(). You can call analyzerExperiment() on you experiment object to get physiologically relivant data, including:
example.object <- analyzeExperiment(example.object) head(example.object$results)
Individual readings can be called to a ploting funciton, for closer inspection of where the progrmaing is calling peaks, minimum values, etc. runTestGraph() can be called on the names of individual reading, or on the whole dataset (if the second argument is left blank). Down arrows indicate downstroke measurments, up arrows indicate upstroke measurments. The color key is as follows:
runTestGraph(example.object, c("R2", "R6"))
Before the data is processed, you can subset the data using the trimData() function.
example <- read.csv('data/CaHandUT1.csv') s <- example[,c(1,2)] plotRawData(s, time_index = 1)
If you wanted to subset the data to only include measurments before the error, you can run trimData() to remove sections from either the right or the left.
left_trim <- trimData(s,1,trim_start = 11000) # Trims from the left plot(x = left_trim$Time, y=left_trim$R1, type = 'l')
right_trim <- trimData(s,1,trim_end = 10000) #Trims from the right plot(x =right_trim$Time, y=right_trim$R1, type = 'l')
The results output can be saved and extracted to be used in Excel/Prism.
write.csv(example.object$results, "~/Desktop/results.csv")
If you have any questions or bugs, please let me know (michael.olvera@gladstone.ucsf.edu).
sessionInfo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.