Skip to content

Working with analysis results

Johannes Niediek edited this page Jan 27, 2023 · 6 revisions

After running the pipeline, a number of files are available for further analysis:

Analysis result files

Here we show two examples on how to further work with the output files.

Example 1: Plotting the rat trajectory

The following Matlab script produces a simple plot of the rat trajectory in a two-minute time window. It relies on the following data from the file RIFF_s1_R1_1_camera_analyzed_data.mat:

  • bg_image is the background image of the RIFF, taken before a rat was placed in it
  • t_frames are the time stamps for each image taken at 30 frames per second
  • loc_arr are the x, y coordinates of the rat at each time stamp

The script is also available here.

S = load("RIFF_s1_R1_1_camera_analyzed_data.mat");

start_min = 10; % 10 minutes into the experiment
plot_mins = 2; % 2 minutes
time_to_plot = plot_mins * 60; 
start = start_min * 60; 

t_start = S.t_frames(1) + start;

start_idx = find(S.t_frames > t_start, 1, 'first');
stop_idx = find(S.t_frames < t_start + time_to_plot, 1, 'last');

time_axis = S.t_frames(start_idx:stop_idx);

x = S.loc_arr(start_idx:stop_idx, 1);
y = S.loc_arr(start_idx:stop_idx, 2);

bg_im = cat(3, S.bg_image, S.bg_image, S.bg_image);

figure();
ax = axes();
ax.NextPlot = "add";
ax.DataAspectRatio = [1 1 1];
imagesc(bg_im)
scatter(x, y, 3, time_axis - time_axis(1), 'filled')
ax.XLim = [70 550];
ax.YLim = [10 480];
cax = colorbar();
cax.YLabel.String = "Time [sec]";
ax.Title.String = sprintf("Minutes %d to %d into the session", ...
    start_min, start_min + plot_mins);

This is the generated figure

Example 2: Plotting nose-pokes and rewards by port

The Matlab script below plots a histogram of nose-pokes and food rewards. It uses the file behavior_table.mat. The script is also available here.

S = load('behavior_table.mat');
beh_tab = S.behavior_table;

pk_idx = beh_tab.event_type == "nosepoke";
fd_idx = beh_tab.event_type == "food";
figure()
ax = axes();
ax.NextPlot = "add";

hpk = histogram(beh_tab.port(pk_idx), .5:12.5, 'EdgeColor', 'none');
hfd = histogram(beh_tab.port(fd_idx), .5:12.5, 'EdgeColor', 'none');

ax.XTick = 1:12;
ax.XLabel.String = "Port number";
ax.YLabel.String = "Count";
ax.XLim = [0 13];
legend({'Nose-pokes', 'Rewards'}, 'Position', [.4 .8 .2 .1], ...
    'EdgeColor', .8 * [1 1 1])

for i = 1:12
    if ~hfd.Values(i)
        continue
    end
    pct = hfd.Values(i)/hpk.Values(i);
    text(i + .25, hfd.Values(i), sprintf('%.1f%%', pct * 100), ...
        'HorizontalAlignment', 'left', ...
        'VerticalAlignment', 'bottom', ...
        'Rotation', 90);
end

ax.Title.String = "Rewarded nose-pokes by port";

The resulting plot looks like this: