-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorganizeData.m
More file actions
90 lines (71 loc) · 3.02 KB
/
organizeData.m
File metadata and controls
90 lines (71 loc) · 3.02 KB
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
function output_file_reference = organizeData(fileName, identifier)
load(fileName, 'cellData', 'ReachS'); % Load the necessary variables from the file
exportPrefex = "";
allNeurons = 0;
% pull necessory structs
cellType = {cellData.cellID};
timeMatrix = cellData(1).Bin10(:,1);
% create binary matrix of fireing activity and cell type
neuronType = [];
binaryMatrix = [timeMatrix];
complex_spikes = [];
sumP = 0;
for k=1:length(cellType)
% seperate out PC from other cells
if allNeurons || (~isempty(cellType{:,k}) && cellType{:,k} == "PC")
sumP = sumP + 1;
% binaryMatrix = [binaryMatrix, lowpass(cellData(k).Bin10smooth(:,2), 0.25, 1/0.01)];
binaryMatrix = [binaryMatrix, cellData(k).Bin10(:,2)];
% if ~isempty(cellData(k).CS_Bin1)
% min_length = min(length(timeMatrix), length(cellData(k).CS_Bin1(:,2)));
% complex_spikes = [complex_spikes, cellData(k).CS_Bin1(1:min_length, 2)];
% else
% complex_spikes = [complex_spikes,[]];
% end
neuronType = [neuronType, ~isempty(cellType{:,k}) && cellType{:,k} == "PC"];
end
end
disp("total PC: " + sumP);
scale_01_kin = {1,1,1,1,0,0,0};
% aggrogate all data together
simStruct = {ReachS.stim};
kinStruct = {ReachS.filt_kin};
kinAggrogate = struct();
for i = 1:length(simStruct)
% get kin data
kinActivity = kinStruct{:,i};
% select reach
% threshHold_idx = find(kinActivity(:,2) > 1,1);
% kinActivity = kinActivity(threshHold_idx-600:threshHold_idx+600,:);
% aggorgate
disp("aggorgating row: " + i)
num_columns = size(kinActivity, 2);
% get all time in neural activations associated with kin time
timeMask = timeMatrix > kinActivity(1,1) & timeMatrix < kinActivity(end,1);
stimTime_0 = timeMatrix(timeMask);
kinInterp = [stimTime_0];
% interpolate kinematic data to fill in space for binary
for t = 2:num_columns
interp = interp1(kinActivity(:,1), kinActivity(:,t), kinInterp(:,1));
if scale_01_kin{t-1} == 1
interp = rescale(interp);
else
interp = rescale(interp, -1,1);
end
kinInterp = [kinInterp, interp];
end
if ~isempty(simStruct{:,i})
% save kinematic and neural data together
kinAggrogate.("stim_"+simStruct{:,i}).("l_"+i) = kinInterp;
kinAggrogate.("stim_"+simStruct{:,i}).("n_"+i) = binaryMatrix(timeMask,:);
kinAggrogate.("stim_"+simStruct{:,i}).("label_"+i) = neuronType;
if ~isempty(complex_spikes)
kinAggrogate.("stim_"+simStruct{:,i}).("comp_"+i) = complex_spikes(timeMask,:);
end
end
end
% save file
output_file_reference = identifier+"_bin10_spike"+exportPrefex;
save(output_file_reference, "kinAggrogate");
disp(output_file_reference);
end