-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from donaldsonlab/addBORISparser
Add boris parser
- Loading branch information
Showing
5 changed files
with
304 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
%% Script to take BORIS .csv output and format it for fiber fluorescence analysis with behavior_driver script | ||
% Written 9/16/20 by Lisa Hiura | ||
% Editted 9/16/20 by Anna McTigue | ||
|
||
%% Imports Data | ||
% % Import behavior Data | ||
prompt = 'Enter the BORIS output file name \n'; | ||
behavior_file_name = input(prompt, 's'); | ||
behaviorData = readtable(behavior_file_name); | ||
|
||
%drop the first 10 lines because they are extraneous | ||
behaviorData(1:10,:) = []; | ||
|
||
%drop columns for media file, total length, FPS, subject, behavioral | ||
%category, and comment | ||
behaviorData(:,[2:5,7:8]) = []; | ||
|
||
%Assign meaningful column names | ||
behaviorData.Properties.VariableNames = {'Time_in_Video' 'Behavior' 'Status'}; | ||
|
||
%drop rows that have 'STOP' as Status to treat all behaviors as point | ||
%events | ||
behaviorData(ismember(behaviorData.Status,'STOP'),:)=[]; | ||
|
||
%transform time in sec to msec | ||
behaviorData.Time_in_Video = behaviorData.Time_in_Video ./ 1000; | ||
|
||
%move the Status column over 1 to the right (should now be column 4) | ||
behaviorData(:,4) = [ behaviorData(:,3)]; | ||
|
||
%prompt time offset to align behavior data with fluorescence data | ||
prompt = 'Enter the timestamp file name \n'; | ||
timestamp_file_name = input(prompt, 's'); | ||
timestamps = readtable(timestamp_file_name); | ||
time_offset = timestamps{1,1}; | ||
|
||
%fix column names | ||
behaviorData.Properties.VariableNames = {'Time_in_Video' 'Behavior' 'corrected_time' 'Status'}; | ||
|
||
%add offset to the behavioral timestamps | ||
%behaviorData.Var9 = behaviorData.ObservationId+time_offset; | ||
behaviorData.corrected_time = behaviorData.Time_in_Video+time_offset; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
%% Script to analze behavior fluorescence data (one fiber) | ||
% written by Katie Gallagher Edited by Kathleen Murphy & Anna McTigue | ||
|
||
% UPDATE THIS EACH NEW VERSION (date of update): | ||
onefiberversion = 'v1.1'; | ||
|
||
format long | ||
%% Read Tables | ||
|
||
fTime = table2array(fData(:,1)); %time column in fluorescent data | ||
|
||
fRed = table2array(fData(:,3)); %3rd column (red) | ||
fGreen = table2array(fData(:,4)); %4th column (green) | ||
|
||
bTime = table2array(behaviorData(:,3)); % time of behavior | ||
behavior = table2array(behaviorData(:,2)); % actual behavior | ||
bTime = double(bTime); | ||
|
||
%% De-interleave | ||
|
||
% determining which row index is red channel | ||
offset1 = fRed(1:3:end); | ||
offset2 = fRed(2:3:end); | ||
offset3 = fRed(3:3:end); | ||
meanoffsets = [mean(offset1), mean(offset2), mean(offset3)]; | ||
redIdx = find(meanoffsets == max(meanoffsets(:))); | ||
|
||
% assigning correct rows to colors | ||
fGreenisosbestic = fGreen(redIdx+2:3:end); %iso | ||
fGreenred = fGreen(redIdx:3:end); %red | ||
fGreengreen = fGreen(redIdx+1:3:end);%green | ||
|
||
fRedisosbestic = fRed(redIdx+2:3:end); | ||
fRedred = fRed(redIdx:3:end); | ||
fRedgreen = fRed(redIdx+1:3:end); | ||
|
||
fTimeIsosbestic = fTime(redIdx+2:3:end); | ||
fTimeRed = fTime(redIdx:3:end); | ||
fTimeGreen = fTime(redIdx+1:3:end); | ||
|
||
%% Minimize behavior data | ||
%pull out index and time for every time behavior occurs | ||
%initialize matrices to hold indices and corresponding times | ||
behaviorIdx = {}; %will be populated with behavior indices | ||
behaviorT = {}; | ||
j=1; | ||
for i = 1:length(behavior) | ||
if string(behavior(i)) == behavior_name | ||
behaviorIdx{j} = i; | ||
behaviorT{j} = bTime(i); | ||
j=j+1; | ||
end | ||
end | ||
|
||
behaviorT = cell2mat(behaviorT); | ||
behaviorIdx = cell2mat(behaviorIdx); | ||
|
||
% if time between behaviors sis greater than threshold seconds then count as | ||
% one bout | ||
Thres=200; | ||
startbout = {}; %start of first bout is the first time it licks | ||
startboutIdx = {}; %index of start bout | ||
finbout = {}; | ||
finboutIdx = {}; %index of end bout | ||
% i=1; | ||
% startbout{i}=behaviorT(i); | ||
% startboutIdx{i} = behaviorIdx(i); | ||
% j=1; | ||
% % seeing if diff in time btwn licks is great enough to consider it as | ||
% % about5 | ||
% while i < length(behaviorT) | ||
% if abs(behaviorT(i+1)-behaviorT(i))>=Thres | ||
% endTime=behaviorT(i); | ||
% endTimeIdx = behaviorIdx(i); | ||
% startTime=behaviorT(i+1); | ||
% startTimeIdx = behaviorIdx(i+1); | ||
% finbout{j} = endTime; | ||
% finboutIdx{j} = endTimeIdx; | ||
% startbout{j+1} = startTime; | ||
% startboutIdx{j+1} = startTimeIdx; | ||
% | ||
% j=j+1; | ||
% end | ||
% i=i+1; | ||
% end | ||
% finbout{j} = behaviorT(end); | ||
% finboutIdx{j}=behaviorIdx(end); | ||
% finbout{length(startbout)} = behaviorT(length(behaviorT)); | ||
% finbout = cell2mat(finbout); | ||
% startbout = cell2mat(startbout); | ||
% finboutIdx = cell2mat(finboutIdx); | ||
% startboutIdx = cell2mat(startboutIdx); | ||
% %seeing if number of licks within each bout is great enough to consider it | ||
% %as a bout | ||
% % threshold on how many licks constitute a bout | ||
% numLicksThres = 0; %must have 10 licks in order to be considered a bout | ||
% i=1; | ||
% j=1; | ||
% while i < length(startbout) | ||
% if (finboutIdx(i) - startboutIdx(i)) < numLicksThres | ||
% finbout(i) = []; | ||
% startbout(i) = []; | ||
% j=j+1; | ||
% end | ||
% i=i+1; | ||
% end | ||
|
||
%% Plot behavior times on raw data plot as tick marks | ||
|
||
%Green Plot | ||
gplot_title = string(behavior_name) + ' Green Plot ' + ' Animal no. '+ ... | ||
animal_num + ' ' + onefiberversion; | ||
figure('Name', gplot_title) | ||
subplot(3,1,1) | ||
plot(fTimeIsosbestic,fGreenisosbestic) | ||
xlabel('Time (ms)') | ||
ylabel('Isosbestic') | ||
for i = 1:length(behaviorT) | ||
xline(behaviorT(i),'k') | ||
end | ||
for i = 1:length(startbout) | ||
xline(startbout(i),'g'); | ||
end | ||
for i = 1:length(finbout) | ||
xline(finbout(i),'r'); | ||
end | ||
subplot(3,1,2) | ||
plot(fTimeRed,fGreenred) | ||
xlabel('Time (ms)') | ||
ylabel('Red') | ||
for i = 1:length(behaviorT) | ||
xline(behaviorT(i),'k') | ||
end | ||
for i = 1:length(startbout) | ||
xline(startbout(i),'g'); | ||
end | ||
for i = 1:length(finbout) | ||
xline(finbout(i),'r'); | ||
end | ||
subplot(3,1,3) | ||
plot(fTimeGreen,fGreengreen) | ||
xlabel('Time (ms)') | ||
ylabel('Green') | ||
for i = 1:length(behaviorT) | ||
xline(behaviorT(i),'k') | ||
end | ||
for i = 1:length(startbout) | ||
xline(startbout(i),'g'); | ||
end | ||
for i = 1:length(finbout) | ||
xline(finbout(i),'r'); | ||
end | ||
|
||
%Red PLot | ||
rplot_title = string(behavior_name) + ' Red Plot' + ' Animal no. '+ ... | ||
animal_num + ' ' + onefiberversion; | ||
figure('Name', rplot_title) | ||
subplot(3,1,1) | ||
plot(fTimeIsosbestic,fRedisosbestic) | ||
xlabel('Time (ms)') | ||
ylabel('Isosbestic') | ||
for i = 1:length(behaviorT) | ||
xline(behaviorT(i),'k') | ||
end | ||
for i = 1:length(startbout) | ||
xline(startbout(i),'g'); | ||
end | ||
for i = 1:length(finbout) | ||
xline(finbout(i),'r'); | ||
end | ||
subplot(3,1,2) | ||
plot(fTimeRed,fRedred) | ||
xlabel('Time (ms)') | ||
ylabel('Red') | ||
for i = 1:length(behaviorT) | ||
xline(behaviorT(i),'k') | ||
end | ||
for i = 1:length(startbout) | ||
xline(startbout(i),'g'); | ||
end | ||
for i = 1:length(finbout) | ||
xline(finbout(i),'r'); | ||
end | ||
subplot(3,1,3) | ||
plot(fTimeGreen,fRedgreen) | ||
xlabel('Time (ms)') | ||
ylabel('Green') | ||
for i = 1:length(behaviorT) | ||
xline(behaviorT(i),'k') | ||
end | ||
for i = 1:length(startbout) | ||
xline(startbout(i),'g'); | ||
end | ||
for i = 1:length(finbout) | ||
xline(finbout(i),'r'); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters