-
Notifications
You must be signed in to change notification settings - Fork 1
/
loadMouseData.m
147 lines (108 loc) · 5.01 KB
/
loadMouseData.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
142
143
144
145
146
147
function vocData = loadMouseData(files,isSoloFile,parameters)
% loadMouseData: loads vocalization data and creates a "vocData" data structure
%
% form: vocData = loadMouseData(files,isSoloFile,parameters)
%
% Inputs:
% files -> cell array (L x 1) of .mat files containing vocalization data
% isSoloFile -> L x 1 binary array, true if no female present, false
% otherwise
% parameters -> struct containing non-default parameter values
%
% Output:
% vocData -> vocalization database
%
% input file format: a .mat file with a cell array of experiments,
% each element has two fields, .exptName, which is a string
% and .vocs, which is a cell array, each element of
% which is a 3 row, N col matrix, where row 1 is time
% in the frequency contour, row 2 is frequency and
% row 3 is amplitude. Frequency contours like this
% are produced by Ax (https://github.com/JaneliaSciComp/Ax)
%
% (C) Gordon J. Berman, 2016
% Emory University
addpath('./utilities');
if nargin < 3
parameters = [];
end
parameters = setRunParameters(parameters);
numPoints = parameters.numPoints;
L = length(files);
lengths = zeros(L,1);
data = cell(L,1);
experimentNames = cell(L,1);
individualNames = cell(L,1);
numVocs = zeros(L,1);
min_voc_length = parameters.min_voc_length;
fprintf(1,'Initializing\n');
for i=1:L
a = load(files{i});
f = fieldnames(a);
data{i} = a.(f{1});
lengths(i) = length(data{i});
experimentNames{i} = cell(lengths(i),1);
individualNames{i} = cell(lengths(i),1);
tempVocs = zeros(lengths(i),1);
for j=1:lengths(i)
experimentNames{i}{j} = data{i}(j).exptName;
idx = find(experimentNames{i}{j} == '_');
individualNames{i}{j} = experimentNames{i}{j}(1:idx(1)-1);
tempVocs(j) = length(data{i}(j).vocs);
end
numVocs(i) = sum(tempVocs);
end
totalNumberVocalizations = sum(numVocs);
vocData.N = totalNumberVocalizations;
vocData.lengths = lengths;
vocData.numVocs = numVocs;
fprintf(1,'Loading Vocalizations\n');
times = cell(totalNumberVocalizations,1);
amps = cell(totalNumberVocalizations,1);
vocs = cell(totalNumberVocalizations,1);
exptNames = cell(totalNumberVocalizations,1);
indNames = cell(totalNumberVocalizations,1);
meanValues = zeros(totalNumberVocalizations,1);
bandwidths = zeros(totalNumberVocalizations,1);
durations = zeros(totalNumberVocalizations,1);
normalizedVocs = cell(totalNumberVocalizations,1);
isSolo = false(totalNumberVocalizations,1);
count = 1;
for i=1:L
fprintf(1,'Loading Vocalizations from File #%3i out of %3i\n',i,L);
for j=1:lengths(i)
for k=1:length(data{i}(j).vocs)
if length(data{i}(j).vocs{k}(1,:)) >= min_voc_length
times{count} = data{i}(j).vocs{k}(1,:);
vocs{count} = data{i}(j).vocs{k}(2,:);
amps{count} = data{i}(j).vocs{k}(3,:);
exptNames{count} = experimentNames{i}{j};
indNames{count} = individualNames{i}{j};
idx2 = ~isnan(vocs{count}) & ~isinf(vocs{count});
durations(count) = max(times{count}) - min(times{count});
bandwidths(count) = max(vocs{count}(idx2)) - min(vocs{count}(idx2));
meanValues(count) = trapz(times{count}(idx2),vocs{count}(idx2))/durations(count);
isSolo(count) = isSoloFile(i);
idx = find([1 diff(times{count})]~=0 & idx2);
x = vocs{count}(idx) - meanValues(count);
t = times{count}(idx);
normalizedVocs{count} = interp1(t,x,linspace(t(1),t(end),numPoints));
count = count + 1;
end
end
end
end
idx = returnCellLengths(vocs) > 0;
[vocData.experimentNames,~,vocData.experimentNumbers] = unique(exptNames(idx));
[vocData.individualNames,~,vocData.individualNumbers] = unique(indNames(idx));
vocData.times = times(idx);
vocData.vocs = vocs(idx);
vocData.amps = amps(idx);
vocData.durations = durations(idx);
vocData.bandwidths = bandwidths(idx);
vocData.meanValues = meanValues(idx);
vocData.normalizedVocs = cell2mat(normalizedVocs(idx,:));
vocData.numPoints = numPoints;
vocData.isSolo = isSolo(idx);
vocData.inTrainingSet=true(size(vocData.isSolo)); % added by RE, eventually be able to select a subbset of a large dataset for training
vocData.numVocs = sum(idx);