-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHAWKDataAnalysisScript_ForceClamp.m
141 lines (120 loc) · 6.22 KB
/
HAWKDataAnalysisScript_ForceClamp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
%% Worm Tracker Data Analysis Script
% This script brings in the data from the yaml file generated by HAWK and
% analysizes the data.
% Written by: Eileen Mazzochette
% Created: October 20, 2014
%
%%%%%
clear all;
close all;
% Get Folder where all the files are:
clear all
if (ispc) %if on PC workstation in MERL 223
DestinationFolder = 'C:\Users\HAWK\Documents\HAWKData';
addpath(genpath('C:\Users\HAWK\Documents\HAWKDataAnalysisCode\YAMLMatlab_0.4.3'));
excelFile = 'C:\Users\HAWK\Dropbox\HAWK\HAWKExperimentLog.xls';
addpath('C:\Users\HAWK\Documents\HAWKDataAnalysisCode\20130227_xlwrite');s
% For excel writing, need these files linked:
% Initialisation of POI Libs
% Add Java POI Libs to matlab javapath
javaaddpath('20130227_xlwrite\20130227_xlwrite\poi_library\poi-3.8-20120326.jar');
javaaddpath('20130227_xlwrite\20130227_xlwrite\poi_library\poi-ooxml-3.8-20120326.jar');
javaaddpath('20130227_xlwrite\20130227_xlwrite\poi_library\poi-ooxml-schemas-3.8-20120326.jar');
javaaddpath('20130227_xlwrite\20130227_xlwrite\poi_library\xmlbeans-2.3.0.jar');
javaaddpath('20130227_xlwrite\20130227_xlwrite\poi_library\dom4j-1.6.1.jar');
javaaddpath('20130227_xlwrite\20130227_xlwrite\poi_library\stax-api-1.0.1.jar');
elseif (ismac) % if on Eileen's personal computer
DestinationFolder = '/Volumes/home/HAWK Data/Force Response Data/';
addpath(genpath('/Users/emazzochette/Documents/MicrosystemsResearch/HAWK/HAWKDataAnalysisCode/HAWKDataAnalysisCode/YAMLMatlab_0.4.3'));
excelFile = '/Users/emazzochette/Box Sync/HAWK/HAWKExperimentLog.xls';
addpath('/Users/emazzochette/Documents/MicrosystemsResearch/HAWK/HAWKDataAnalysisCode/HAWKDataAnalysisCode/20130227_xlwrite');
% For excel writing, need these files linked:
% Initialisation of POI Libs
% Add Java POI Libs to matlab javapath
javaaddpath('20130227_xlwrite/20130227_xlwrite/poi_library/poi-3.8-20120326.jar');
javaaddpath('20130227_xlwrite/20130227_xlwrite/poi_library/poi-ooxml-3.8-20120326.jar');
javaaddpath('20130227_xlwrite/20130227_xlwrite/poi_library/poi-ooxml-schemas-3.8-20120326.jar');
javaaddpath('20130227_xlwrite/20130227_xlwrite/poi_library/xmlbeans-2.3.0.jar');
javaaddpath('20130227_xlwrite/20130227_xlwrite/poi_library/dom4j-1.6.1.jar');
javaaddpath('20130227_xlwrite/20130227_xlwrite/poi_library/stax-api-1.0.1.jar');
end
%Choice of how to export plots, either individual plots (false), or grouped in a
%single window by stimulus (true)
plotByStim = false;
%asks user for the directory where all the files are:
directory = uigetdir(DestinationFolder,'Choose the folder where the data if located');
%determine experiment title based on file name:
experimentTitle = getExperimentTitle(directory);
%Extract tracking, FPGA, stimulus data from YAML files:
TrackingData = getTrackingDataFromYAML(directory,experimentTitle);
FPGAData = getFPGADataFromYAML(directory, experimentTitle);
StimulusData = getStimulusDataFromYAML(directory,experimentTitle);
%% Populate Experiment Log Spreadsheet:
[NUM,TXT,RAW]=xlsread(excelFile,'Experiment Log Force Clamp');
[rowCount columnCount] = size(RAW);
% spreadsheetTitles = TXT(1,:);
load('spreadsheetTitlesForceClamp.mat');
% %check if it's already been populated:
% if(strmatch(experimentTitle,TXT(:,strmatch('Experiment Name',TXT(1,:),'exact')),'exact')>0)
% experimentRow = strmatch(experimentTitle,TXT(:,2));
% else
experimentRow = rowCount+1;
% end
newRow = populateForceClampExperimentParameters( experimentTitle, TrackingData, spreadsheetTitles);
xlwrite(excelFile, newRow, 'Experiment Log Force Clamp', strcat('A',num2str(experimentRow)));
%% Stop here if no stimulus
if (ismember('NumberOfStimulus',fieldnames(TrackingData)))
if (TrackingData.NumberOfStimulus < 1) % fix this once corrected in HAWK software
disp('No Stimulus Recorded');
break;
end
end
%% Extract General Properties:
% mat file name for the per stimulus data structure.
mat_file = fullfile(directory,strcat(experimentTitle,'_DataByStimulus.mat'));
%if the data has already been read from the .yaml file, just load the mat
%file created last time:
if (exist(mat_file, 'file')==2)
load(mat_file);
%Also need to extract the number of stimulus
if (ismember('NumberOfStimulus',fieldnames(TrackingData)))
numStims = TrackingData.NumberOfStimulus;
else
numStims = min(length(Stimulus), length(fieldnames(FPGAData)));
end
else
%Create new stimulus matrix:
%Extract behavior information from Tracking Data
[Stimulus, numStims] = extractBehaviorDataFromTracking(TrackingData);
%Extract stimulus data from FPGA and Stimulus files:
Stimulus = extractFPGADataFromFPGAData(FPGAData, StimulusData, Stimulus, numStims);
%Save stimulus to mat file
save(mat_file, 'Stimulus');
end
%% Filter Frames based on the worm body length statistics:
[Stimulus] = filterFramesByBodyLength(Stimulus, numStims);
%% Sort Frames based on Stimulus:
[Stimulus] = sortFramesBasedOnStimulus(Stimulus, numStims);
%% Determine the Worm Trajectory in real space:
[Stimulus] = determineWormTrajectory(Stimulus, numStims);
%% Get information about the stimulus timing, also statistics about timing
[Stimulus] = determineStimulusTiming(TrackingData, StimulusData, Stimulus, numStims);
%% Calculate precision of targeting:
videoPresent = true;
Stimulus = spatialResolutionForceClamp(directory, Stimulus, TrackingData, numStims, videoPresent);
%% Determine which frames and trials are not viable:
Stimulus = scoreFrames(Stimulus, numStims);
%% Extract velocity, phase shift by determining the curvature.
Stimulus = getVelocityFromCurvature(Stimulus, numStims);
Stimulus = calculateCurvatureParameters(Stimulus, numStims);
%% Score Trials and Behavior response:
Stimulus = scoreTrials(TrackingData, Stimulus, numStims);
Stimulus = scoreBehaviorResponse(Stimulus, numStims);
%% Write per stimulus data to excel spread sheet
[data, firstColumn] = populateForceClampPerStimulusData( Stimulus, spreadsheetTitles, numStims);
xlwrite(excelFile, data, 'Experiment Log Force Clamp', strcat('A'+firstColumn-1,num2str(experimentRow+1)));
%% Save mat file
mat_file = fullfile(directory,strcat(experimentTitle,'_DataByStimulus.mat'));
save(mat_file, 'Stimulus');
%% Plot Data
% plotData(Stimulus, numStims, true);