-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalign_clean_data.m
144 lines (112 loc) · 5.31 KB
/
align_clean_data.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
%this script was developped in order to align the refined data(selected
%channels after purification through get_clean_peaks_and_data.m) to the
%first peak
newdatadir = 'C:\Users\daumail\Documents\LGN_data\single_units\inverted_power_channels\good_single_units_data_4bumps_more\new_peak_alignment_anal\su_peaks_02262020_2\all_units\';
channelfilename = [newdatadir 'clean_SUA_sup_50'];
data_file = load(channelfilename);
locsfilename = [newdatadir 'clean_SUA_locs'];
all_locsdSUA = load(locsfilename);
xabs = -199:1300;
nyq = 500;
channum = 1: length(data_file.clean_high_SUA);
mean_filtered_dSUA = struct();
suas_trials = struct();
up_dist = nan(1, length(channum));
all_locsdSUA_filtered = nan(1,length(channum));
for i = channum
if ~isempty(data_file.clean_high_SUA(i).namelist)
trialidx = 1:length(data_file.clean_high_SUA(i).namelist(1,:));
filtered_dSUA = data_file.clean_high_SUA(i).namelist;
% filtered_dSUA = filtered_dSUA(:,~all(isnan(filtered_dSUA))); % for nan - cols
%store unaligned data
suas_trials(i).unaligned = filtered_dSUA;
%determine the first peak location for each trial of a given single
%unit
all_locsdSUA_trials = all_locsdSUA.peaks_locs(i).locs;
locs_peak1 = all_locsdSUA_trials(1, :);
up_dist_trials= length(xabs)- locs_peak1;
max_low_dist_unit = max(locs_peak1(1,:));
%create new matrix with the length(max(d)+max(xabs - d))
new_dist_unit = max_low_dist_unit + max(up_dist_trials);
fp_locked_trials = nan(new_dist_unit,length(filtered_dSUA(1,:)));
clear n
for n = 1:length(filtered_dSUA(1,:))
lower_unit_bound =max_low_dist_unit-locs_peak1(n)+1;
upper_unit_bound =max_low_dist_unit-locs_peak1(n)+length(xabs);
fp_locked_trials(lower_unit_bound:upper_unit_bound,n) = filtered_dSUA(:,n);
end
fp_locked_trials_out = fp_locked_trials(:,~all(isnan(fp_locked_trials))); % for nan - cols
%compute the mean single unit activity if more than 10 trials
mean_filtered_dSUA(i).mean_unit = mean(fp_locked_trials_out,2); % for nan - cols
%get the aligned data if it exists for the unit
suas_trials(i).aligned = fp_locked_trials_out;
end
%{
figure();
x = 1:length(fp_locked_trials_out(:,1));
plot(x,fp_locked_trials)
hold on
plot(x, mean(fp_locked_trials_out,2),'LineWidth',1, 'Color', 'black')
%mean_aligned = mean(fp_locked_trials_out,2);
%nanmean_aligned = nanmean(fp_locked_trials_out,2);
%}
end
%exclude 160517, (first unit, left empty, it is a K neuron)
%Reject 180806 p1 uclust17, M cell, as doesn't seem well triggered (46)
%Reject 181207 (B) uclust22, M cell, as doesn't seem well triggered (55)
layer = {'K','M','P','K','K','K','M','P','P','','M','M','','','M','','','P','','M','','M','M','','P','M','','P', ...
'P','','','K','P','M','M','M','P','','P','K','P','P','','P','P','M','','P','M','P','M','P','','P','M','M','P','','M','M','P','M', ...
'','','M','M','M','P','M','M','M','M','P','P'};
layer([1,46,55]) = [];
pvaluesdir = 'C:\Users\daumail\Documents\LGN_data\single_units\inverted_power_channels\good_single_units_data_4bumps_more\new_peak_alignment_anal\lmer_results_peaks\';
pvalfilename = [pvaluesdir 'lmer_results_rawbs.csv'];
pvalues = dlmread(pvalfilename, ',', 1,1);
%% Plots of peaks with pvalues
channum = 1: length(data_file.clean_high_SUA);
for chan = channum
mean_unaligned = mean(suas_trials(chan).unaligned,2);
unaligned = suas_trials(chan).unaligned;
mean_aligned = mean(suas_trials(chan).aligned,2);
aligned = suas_trials(chan).aligned;
if ~isempty(mean_unaligned) && ~isempty(mean_aligned)
h = figure;
xabs = -199:1300;
subplot(2, 1,1);
plot(xabs, unaligned)
hold on
plot(xabs, mean_unaligned,'LineWidth',1, 'Color', 'black')
hold on
plot([0 0], ylim,'k')
hold on
plot([1150 1150], ylim,'k')
xalign = 1:length(suas_trials(chan).aligned(:,1));
subplot(2, 1,2);
plot(xalign, aligned)
hold on
plot(xalign, mean_aligned,'LineWidth',1, 'Color', 'black')
ylh = ylabel({'\fontsize{9}Contacts','\fontsize{9}Spike Rate (spikes/s)'});
set(gca, 'linewidth',2)
set(gca,'box','off')
sgtitle({sprintf('%s | %s', num2str(chan), char(layer(chan))), 'responses, p<0.05, associated to adaptation pvalues'}, 'Interpreter', 'none')
xlabel('Time from -50ms from stimulus onset (ms)')
set(gcf,'Units','inches')
set(gcf,'position',[1 1 8.5 11])
% filename = strcat('C:\Users\maier\Documents\LGN_data\single_units\inverted_power_channels\good_single_units_data_4bumps_more\new_peak_alignment_anal\plots\',strcat( sprintf('final_bscorr_data_aligned_unaligned_P1040P2_1ms_stimonset_unit_%d', chan)));
% saveas(gcf, strcat(filename, '.png'));
end
end
%% plot trials indep
unaligned = suas_trials(chan).unaligned;
idx = [1 3 5 7 9 11 13 15 17 19 2 4 6 8 10 12 14 16 18 20];
h = figure;
%for i = 1:19:length(unaligned(1,:))
for tr = 1:19
xabs = -199:1300;
sp = subplot(length(1:12), 2, idx(tr));
plot(xabs, unaligned(:,tr))
hold on
plot([0 0], ylim,'k')
hold on
plot([1150 1150], ylim,'k')
end
%end