-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_changes.m
167 lines (159 loc) · 5.48 KB
/
map_changes.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
% load(filename);
%% New method
holdI = I(:,contains(I.Properties.VariableNames,'map'));
holdI = table2array(holdI);
chId1 = 1:2:127;
chId2 = 2:2:128;
ct = 0;
Ch = zeros(64,1); % returns logical for channels which stay the same excluding channels that have single to no responses
Q = ones(64,1);
for i = chId1
ct = ct + 1;
cc1 = chId1(ct);
cc2 = chId2(ct);
idx1 = holdI(cc1,:) == 0;
holdI(cc1,idx1) = nan;
idx2 = holdI(cc2,:) == 0;
holdI(cc2,idx2) = nan;
uu1 = unique(holdI(cc1,:));
uu2 = unique(holdI(cc2,:));
uu = unique([uu1 uu2]);
excl = isnan(holdI(cc1,:)) & isnan(holdI(cc2,:));
tot = size(holdI,2) - sum(excl);
for ii = 1:numel(uu)
E{ii} = holdI(cc1,:) == uu(ii) | holdI(cc2,:) == uu(ii);
if sum(E{ii}) == tot
Ch(ct,1) = 1;
Q(ct,1) = 2;
break
else
Ch(ct,1) = 0;
end
end
if tot == 0 || tot == 1
Ch(ct,1) = 0;
Q(ct,1) = 0;
end
end
channel_unchanged = sum(Ch);
quality_channels = [(sum(Q==0)) (sum(Q==1)) (sum(Q==2))];
%% Quantify map changes
nMap = (size(I,2) - 1)/2; % number of maps
mI = table2array(I(:,(contains(I.Properties.VariableNames,'Map')))); % isolate movement type from map
mI(mI == 0) = NaN; % sets NR sites as NaN values
mI = mI(65:128,:); % split to do one array at a time
% mI(mI == 2) = 1; % collapse dFl and pFl movementsI
col = zeros(size(mI,1),1);
mI = cat(2,mI,col); % add new column
for i = 1:size(mI,1)
row = mI(i,1:end-1); % isolate row
allResp = row(~isnan(row)); % removes NaN values from consideration
mI(i,end) = numel(unique(allResp)); % calculate changes in movements between maps
end
nCh = size(mI,1)/2;
Channel = [1:nCh]';
Change = [zeros(nCh,1)];
V = table(Channel,Change);
% accounts (maybe?!??) for slight variations in dual representations if you
% use the below
for i = 1:nCh
c = i*2-1; % channel value 1
cc = i*2; % channel value 2 (to account for dual sites)
V(i,2) = {((mI(c,end) + mI(cc,end))/2)};
end
chV = floor(table2array(V(:,2)));
V(:,2) = num2cell(chV);
noResp = V{:,2} == 0;
V(noResp,:) = []; % removes channels with no responses overall
nChAdj = size(V,1);
no_change = sum(chV == 1); % number of channels with no change in representation over time
percent_no_change = no_change/nChAdj;
some_change = sum(chV == 1 | chV == 2); % includes channels with just a single change in representation
percent_some_change = some_change/nChAdj;
% % the below just eliminates secondary movements
% for i = 1:nCh
% c = i*2-1; % channel value 1
% V(i,2) = {mI(c,end)- 1};
% end
% chV = table2array(V(:,2));
% no_change = sum(chV == 0);
% percent_no_change = no_change/nCh;
%% Quantify percent of map
nMap = (size(I,2) - 1)/2; % number of maps
mI = table2array(I(:,(contains(I.Properties.VariableNames,'Map')))); % isolate movement type from map
mI = mI(65:128,:); % split to do one array at a time
nCh = size(mI,1); % number of channels
mvmtType = [0:5]';
label = {'NR','dFl','pFl','Trunk','Face','Vibrissa'}';
map = cell(6,nMap);
M = table(mvmtType,label,map);
for i = 1:nMap
for ii = 1:6
mID = ii-1;
M.map(ii,i) = {(sum(mI(:,i) == mID)/nCh)*100};
end
end
% NOTE: this method needs to be rethought as it deals with sites with mixed
% responses
%% Quantify percent of map new method
nMap = (size(I,2) - 1)/2; % number of maps
mI = table2array(I(:,(contains(I.Properties.VariableNames,'Map')))); % isolate movement type from map
mI = mI(65:128,:); % split to do one array at a time
nCh = (size(mI,1))/2; % number of channels
add = zeros(64,4) + 6; % filled with sixes to not get them counted as NR
mI = cat(1,mI,add); % add space to table
mvmtType = [0:5]';
label = {'NR','dFl','pFl','Trunk','Face','Vibrissa'}';
map = cell(6,nMap);
M = table(mvmtType,label,map);
for i = 1:4
for ii = 1:nCh
c = (ii*2) - 1;
cc = ii*2;
d = c + 64;
dd = cc + 64;
if mI(c,i) ~= mI(cc,i)
mI(d,i) = mI(c,i);
mI(dd,i) = mI(cc,i);
end
end
end
for i = 1:nMap
for ii = 1:6
mID = ii-1;
M.map(ii,i) = {(sum(mI(:,i) == mID)/2)*0.0625}; %uses area represented by the site
end
end
%% Quantify map changes (deprecated version)
% nMap = (size(I,2) - 1)/2; % number of maps
% mI = table2array(I(:,(contains(I.Properties.VariableNames,'Map')))); % isolate movement type from map
% mI = mI(65:128,:); % split to do one array at a time
% col = zeros(size(mI,1),1);
% mI = cat(2,mI,col); % add new column
% mI(mI == 2) = 1; % collapse dFl and pFl movements
% for i = 1:size(mI,1)
% mI(i,end) = numel(unique(mI(i,1:end-1))); % calculate changes in movements between maps
% end
% nCh = size(mI,1)/2;
% Channel = [1:nCh]';
% Change = [zeros(nCh,1)];
% V = table(Channel,Change);
% accounts (maybe?!??) for slight variations in dual representations if you
% use the below
% for i = 1:nCh
% c = i*2-1; % channel value 1
% cc = i*2; % channel value 2 (to account for dual sites)
% V(i,2) = {((mI(c,end) + mI(cc,end))/2)-1};
% end
% chV = floor(table2array(V(:,2)));
% V(:,2) = num2cell(chV);
% no_change = sum(chV == 0);
% percent_no_change = no_change/nCh;
% % the below just eliminates secondary movements
% for i = 1:nCh
% c = i*2-1; % channel value 1
% V(i,2) = {mI(c,end)- 1};
% end
% chV = table2array(V(:,2));
% no_change = sum(chV == 0);
% percent_no_change = no_change/nCh;