https://github.com/msuefishlab/eodplotter
EODPlotter is designed as an R package, to be installed using a package manager. EODPlotter is a command line alternative to the TDMSViewer
We will install EODPlotter from github. Open RStudio and run
install.packages('devtools')
This will install the devtools package which has the install_github
function. Then run
devtools::install_github('msuefishlab/eodplotter')
After running this it should install the EODViewer code and its dependencies automatically.
To install a specific version, e.g. the version mentioned in this guide, you can also run
install_github('msuefishlab/eodplotter@0.0.4')
Add this line to your .bash_profile
export PATH=$PATH:`Rscript -e 'cat(paste0(.libPaths(),"/eodplotter/scripts",collapse=":"))'`:~/bin
First use peak_finder
to find all EODs and outputs a new file, e.g. file.peaks.csv, which is named based on the input file (if you analyzed fish.tdms, it would output fish.peaks.csv)
peak_finder -f file.tdms -v
Then try using the tdmsplot
command, it plots the raw signal as a graph, use to diagnose signal problems and view where EODs were called
tdmsplot -f file.tdms -p file.tdms.peaks.csv
Finally analyze the signal and the peaks to produce output files
eodplot -f file.tdms -p file.peaks.csv
After running these commands you will have a number of files
Where file is the prefix of your TDMS file that you analyzed e.g. if it was fish123.tdms, then you would have fish123.stats.csv.
The file.stats.csv file contains useful information on duration and amplitude, and also number of EODs measured. Other files can be used for diagnosing issues with the analysis
This script will run the EOD analysis over all tdms files in a directory
parallel "peak_finder -f {}; tdmsplot -f {} -p {/}.peaks.csv; eodplot -f {} -p {/}.peaks.csv" ::: /path/to/files/*.tdms
A helper script called combine_stats is added so after processing many TDMS files, simply run
combine_stats
This will output a combined stats file
If you have different experiments with different timepoints and you want to compare them all then this script is an example of something you could try
This will plot the amplitude from multiple experiments where it assumes some particular file naming conventions e.g.
Generic pattern <number>_MO<experimentname>_minutes_timestamp.tdms
library(stringr)
library(ggplot2)
suppressMessages(library(lubridate))
combined=read.csv('combined.data.csv',stringsAsFactors=F)
l = str_split(substr(combined$name,0,str_locate(combined$name,'2017')[,1]-2),'_')
combined$trial = as.numeric(sapply(l,function(r) r[1]))
combined$group = tolower(sapply(l,function(r) r[2]))
m = sapply(l, function(r) r[3])
m[m == 'Baseline'] = 0
combined$timepoint = as.numeric(m)
combined$date = ymd_hms(str_replace(substring(combined$name, str_locate(combined$name,'2017')[,1]), '.tdms.stats.csv',''))
png('combined.fixed.png', width=1000,height=800)
ggplot(combined, aes(timepoint, amplitude, color = group)) + geom_line() + ggtitle('MO EOD amplitude') + scale_x_continuous(name="Timepoint") + scale_y_continuous(name="Peak-to-peak amplitude") +scale_colour_brewer(palette="Set2")
invisible(dev.off())
pdf('combined.fixed.pdf', width=11,height=8)
ggplot(combined, aes(timepoint, amplitude, color = group)) + geom_line() + ggtitle('MO EOD amplitude') + scale_x_continuous(name="Timepoint") + scale_y_continuous(name="Peak-to-peak amplitude") +scale_colour_brewer(palette="Set2")
invisible(dev.off())
ret = do.call(rbind, lapply(unique(combined$group), function(group) {
r = combined[combined$group == group, ]
r$relative_amplitude = r$amplitude / r[r$timepoint == 0, ]$amplitude
r
}))
png('baseline.fixed.png', width=1000,height=800)
ggplot(ret, aes(timepoint, relative_amplitude, color = group)) + geom_line() + ggtitle('MO EOD amplitude (relative to baseline)') + scale_x_continuous(name="Timepoint") + scale_y_continuous(name="Relative amplitude") +scale_colour_brewer(palette="Set2")
invisible(dev.off())
pdf('baseline.fixed.pdf', width=11,height=8)
ggplot(ret, aes(timepoint, relative_amplitude, color = group)) + geom_line() + ggtitle('MO EOD amplitude (relative to baseline)') + scale_x_continuous(name="Timepoint") + scale_y_continuous(name="Relative am
Example output
Load the library
library(eodplotter)
Plot the raw signal of the data using plotTdms
plotTdms('../tests/testthat/file.tdms')
Find peaks
p = peakFinder('../tests/testthat/file.tdms')
print(head(p))
## peaks direction
## 1 0.08696 +
## 2 0.10198 +
## 3 0.48870 +
## 4 0.87200 +
## 5 1.04231 +
## 6 1.16931 +
Look at where the peaks were called
plotTdms('../tests/testthat/file.tdms', peaks = p)
Get a matrix of EOD signal
m = getEODMatrix('../tests/testthat/file.tdms', p, prebaseline=T)
print(head(m))
## col time data
## 1.1 0.08696 -0.00250 -0.0004999497
## 1.2 0.08696 -0.00249 -0.0011577781
## 1.3 0.08696 -0.00248 0.0011446216
## 1.4 0.08696 -0.00247 -0.0008288639
## 1.5 0.08696 -0.00246 -0.0004999497
## 1.6 0.08696 -0.00245 0.0011446216
Plot the matrix of EOD signals
plotAverage(m)
Plot all the signals
plotTotal(m)
Plot the matrix of EOD signals
landmarks = findLandmarks(m)
print(landmarks)
## landmark time val mean sd
## 1 p0 -0.00068 -7.901732e-04 -7.901732e-04 0.002609323
## 2 p1 -0.00001 3.843618e-01 3.843618e-01 0.175648282
## 3 p2 0.00028 -3.973405e-02 -3.973405e-02 0.021704611
## 4 t1 -0.00025 7.439175e-03 7.439175e-03 0.004501125
## 5 t2 0.00224 -8.381168e-03 -8.381168e-03 0.004497543
## 6 s1 -0.00006 2.601188e-01 2.601188e-01 0.124108301
## 7 s2 0.00005 2.235964e-01 2.235964e-01 0.111163798
## 8 zc1 -0.00039 -1.116577e-05 -1.116577e-05 0.002603257
## 9 zc2 0.00013 -8.529264e-04 -8.529264e-04 0.025507748
Plot the landmarks
plotLandmarks(m, landmarks)
Get stats about the landmarks
getStats(p, landmarks)
## amplitude duration total_eods
## 1 0.4240959 0.00249 152
tdmsplot
tdmsplot
Usage: /Users/cdiesh/src/github.com/msuefishlab/eodplotter/inst/scripts/tdmsplot [options]
Options:
-h, --help
Show this help message and exit
-f FILE, --file=FILE
TDMS file input
-v VERBOSE, --verbose=VERBOSE
Print verbose output
-c CHANNEL, --channel=CHANNEL
Channel name
-s START, --start=START
Start time
-e END, --end=END
End time
Outputs a file.signal.png file representing the raw signal values of the EODs
peak_finder
Usage: /Users/cdiesh/src/github.com/msuefishlab/eodplotter/inst/scripts/peak_finder [options]
Options:
-h, --help
Show this help message and exit
-f FILE, --file=FILE
TDMS file input
-v, --verbose
Print verbose output
-c CHANNEL, --channel=CHANNEL
Channel name
-n NUMBER, --number=NUMBER
Peak finder threshold, sigma or voltage threshold
-d DIRECTION, --direction=DIRECTION
Direction, enter either positive/negative/none
-s START, --start=START
Start time
-e END, --end=END
End time
-r REMOVE, --remove=REMOVE
Amount to remove from start/end of recording
Outputs a file.peaks.png file representing the timepoints where EODs were detected in the TDMS file
eodplot
Usage: /Users/cdiesh/src/github.com/msuefishlab/eodplotter/inst/scripts/eodplot [options]
Options:
-h, --help
Show this help message and exit
-f FILE, --file=FILE
TDMS file input
-p PEAK, --peak=PEAK
Peak file input
-v, --verbose
Print verbose output
-c CHANNEL, --channel=CHANNEL
Channel name
-w WINDOW, --window=WINDOW
Window size around peak value
-b, --prebaseline
Pre-normalization baseline subtract
-d, --postbaseline
Post-normalization baseline subtract
-n, --normalize
Normalize waveform between 0-1 peak to peak height
-a ALPHA, --alpha=ALPHA
Alpha channel for individual peaks
Outputs a bunch of files completing the analysis
multieodplot
Usage: /Users/cdiesh/src/github.com/msuefishlab/eodplotter/inst/scripts/multieodplot [options]
Options:
-h, --help
Show this help message and exit
-f FILE, --file=FILE
TDMS/Peak file table
-c CHANNEL, --channel=CHANNEL
Channel name
-w WINDOW, --window=WINDOW
Window size around peak value
-v, --verbose
Print verbose output
-b, --prebaseline
Pre-normalization baseline subtract
-d, --postbaseline
Post-normalization baseline subtract
-n, --normalize
Normalize waveform between 0-1 peak to peak height
-a ALPHA, --alpha=ALPHA
Transparency factor aka alpha channel for plotting EODs
-p, --pdf
Use PDF output
-A, --all
Plot all traces
This demo shows you how to use the eodplotter
as an R library. Note that there is the alternative usage of the library using the command line as well, which can be more streamlined