function [] = plotOpticalTraces_transients_compare(compositeTrace1, threshold, transients, dtrans1, dtrans2, usecells, Hz, medfil, meanframe) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Plots a set of temporal traces (intended to be fluorescence or DF/F) along % with markers to denote when important events (ie. calcium transients) % occur. % Inputs: % - compositeTrace: Mx#Neuron temporal traces of the fluorescence % - threshold: threshold used to determine whether a transient occured % or not % - transients: Cell array containing the indexes of the true % transients % - dtrans1: cell array containing the indexes of the transients identified by method 1 % - dtrans2: cell array containing the indexes of the transients % identified by method 2 % - Usecells: Vector of the temporal traces to plot % - Hz: The imaging rate % - medfil: number of frames to use for the moving median % - meanframe: number of frames to use for the short moving average % filter % Outputs: (none) % - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% [tracea, ~] = size(compositeTrace1); pace = 1/Hz; time = (1:tracea)*pace; raise = 0; for fn = 1:length(usecells) i = usecells(fn); t = compositeTrace1(:, i); dfF = movmean(t, meanframe); mindf = min(dfF); dfF = dfF-mindf+raise; plot(time, dfF, 'k') if fn == 1 hold on end medtrace= movmedian(dfF, medfil); yline(threshold(i)+median(dfF), 'k--') plot(time, threshold(i)+medtrace, 'r--'); trans = transients{usecells(fn)}; plot(trans*pace, ones(size(trans))*raise+range(dfF), 'k*') trans = dtrans1{usecells(fn)}; if ~isempty(trans) plot(trans*pace, ones(size(trans))*raise+range(dfF)+0.01, 'ko') end trans = dtrans2{usecells(fn)}; if ~isempty(trans) plot(trans*pace, ones(size(trans))*raise+range(dfF)+0.02, 'rv') end raise = raise+range(dfF)+0.05; if i == 1 legend({'Trace 1', 'Threshold', 'Moving threshold', 'GT', 'Transients 1', 'Transients 2'}, 'AutoUpdate', 'off'); end end hold off xlabel('Time(s)'); ylabel('Cell Number'); set(gca, 'FontName', 'Arial', 'FontSize', 12)