-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTidyData.m
125 lines (109 loc) · 4.78 KB
/
TidyData.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
%
% --.--o | ,--. |
% | .,---|, .| |,---.|--- ,---.
% | || || || |,---|| ,---|
% ` ``---'`---|`--' `---^`---'`---^
% `---'
% Creates tidy data for a dataset, and drops to raw data section of project
% folder setting.
addpath('~/Code/analysis')
addpath('~/Code/utilities')
Opt = OPTARGS;
Opt.unit = 'spikes';
Opt.taskFilter = [];
Opt.cellFilter = [];
Opt.behFilter = [];
%[animal, day] = deal('RY16', 36);
if ~exist('animal','var')
[animal, day] = deal('RY22', 21);
else
sprintf("\n!!! Taking animal=%s, day=%d from workspace !!!")
end
% ==========
% Input data
% ==========
% -------------
% Get Unit data
% -------------
spikeDat = ndb.load(animal, Opt.unit, 'ind', day);
spikes = units.getRateMatrix(animal, day,...
'unit', Opt.unit,...
'taskFilter', Opt.taskFilter,...
'cellFilter', Opt.cellFilter,...
'spikeData', spikeDat);
clear spikeDat
beh = gbehavior.lookup(animal, [], day);
[spikes, beh_filtered, ~] = units.atBehavior(beh, spikes,...
'useGPU', false,....
'merge', false,...
'returnIndices', true, ...
'query', Opt.behFilter);
spikes.beh = util.table.split(spikes.beh, "neuron");
% ===============================
% How do cells look (raster-wise) :
% Send tidy data to Julia
% ===============================
folder = coding.file.datafolder('exp_raw', 'visualize_raw_neural');
% Behavior
behavioral_properties = ["x","y","currentPathLength","currentAngle"];
beh_fn = coding.file.datafolder('exp_raw', 'visualize_raw_neural',
animal + "_" + day + "_" + 'beh.csv');
writetable(beh, beh_fn);
% Task tabble
task = taskLib.taskTable(animal, day);
task_fn = coding.file.datafolder('exp_raw', 'visualize_raw_neural', ...
animal + "_" + day + "_" + 'task.csv');
writetable(task, task_fn);
% Spikes
labeledSpiking = units.labeledSpiking(spikes, ...
["block", "subblock", "blocktraj", "traj"], beh, task);
spiking_fn = coding.file.datafolder('exp_raw', 'visualize_raw_neural',...
animal + "_" + day + "_" + 'labeled_spiking.csv');
writetable(labeledSpiking, spiking_fn);
% Cell properties
cell_fn = coding.file.datafolder('exp_raw', 'visualize_raw_neural',...
animal day + "_" + 'cell.csv');
writetable(spikes.cellTable, cell_fn);
% Ripples (CA1 and cortical)
rippletime = ndb.load(animal, 'rippletime', 'inds', day);
rippletimepfc = ndb.load(animal, 'rippletimepfc', 'inds', day);
rip_fn = coding.file.datafolder('exp_raw', 'visualize_raw_neural',...
animal + "_" + day + "_" + 'ripple.csv');
rippletime = ndb.toTidy(rippletime, 'labels', ["day","epoch"]);
rippletimepfc = ndb.toTidy(rippletimepfc, 'labels', ["day","epoch"]);
rippletime.area = repmat("CA1", height(rippletime), 1);
rippletimepfc.area = repmat("PFC", height(rippletimepfc), 1);
writetable([rippletime; rippletimepfc], rip_fn);
% Rhythms (Just theta for now)
rhythm_fn = coding.file.datafolder('exp_raw', 'visualize_raw_neural', ...
animal + "_" + day + "_" + 'rhythmref.nc');
rhythm = lfpLib.create.rhythmTable(animal, ...
{'thetaref', 'eegref'}, day, 'label', {'', 'broad'});
for tetrode = progress(unique(rhythm.tetrode)')
tetrode_table = rhythm(rhythm.tetrode == tetrode,:);
tetfile = replace(rhythm_fn, 'mref.', sprintf('mref_%d.', tetrode))
util.table.netcdfwrite(tetrode_table, tetfile);
end
util.notify.pushover("Finished writing rhythmref table tetrodes")
util.table.netcdfwrite(rhythm, rhythm_fn);
util.notify.pushover("Finished writing rhythmref table")
clear rhythm
rhythm = lfpLib.create.rhythmTable(animal, ...
{'theta', 'eeg'}, day, 'label', {'', 'broad'});
rhythm_fn = coding.file.datafolder('exp_raw', 'visualize_raw_neural', ...
animal + "_" + day + "_" + 'rhythm.nc');
for tetrode = progress(unique(rhythm.tetrode)')
tetrode_table = rhythm(rhythm.tetrode == tetrode,:);
tetfile = replace(rhythm_fn, 'm.', sprintf('m_%d.', tetrode))
util.table.netcdfwrite(tetrode_table, tetfile);
end
util.notify.pushover("Finished writing rhythm table pieces")
util.table.netcdfwrite(rhythm, rhythm_fn);
util.notify.pushover("Finished writing rhythm table")
clear rhythm
%spikeDat = ndb.load(animal, Opt.unit, 'ind', day);
%spikes = units.getRateMatrix(animal, day,...
% 'unit', Opt.unit,...
% 'taskFilter', Opt.taskFilter,...
% 'cellFilter', Opt.cellFilter,...
% 'spikeData', spikeDat);