-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoFindNeighbors.m
More file actions
276 lines (234 loc) · 7 KB
/
coFindNeighbors.m
File metadata and controls
276 lines (234 loc) · 7 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
function nobj=coFindNeighbors(neuron,verboseFlag)
%COFINDNEIGHBORS(neuron1,verboseFlag)
%
%find all one-hop neighbors of neuron or cell array of neurons
%
%.if particular left or right suffix is not specified in neuron names,
%the search will be performed for all possible L/R combinations
%
%example: coFindNeighbors('ASH');
%will give pathways for ASHL->AWCL, ASHR->ASHR, ASHR->AWCL, and ASHL->AWCR
%
%.synapses can only be traversed in one direction, gap junctions in either
%
%.needs NeuronConnect.xls in same directory (get latest from WormAtlas.org)
%
%Saul Kato
%110531 first version
%
if nargin<2
verboseFlag=true;
end
% if nargin<2 || isempty(max_hops)
max_hops=1;
% end
if nargin<1
neuron='AWCL';
end
neuron=upper(neuron);
verblist={'syn','syp','gap'};
%load database
[num,txt,raw] = xlsread('NeuronConnect.xls','','','basic');
if verboseFlag
disp(' ');
disp(['FINDING NEIGHBORS FOR ' neuron ', max ' num2str(max_hops) ' hops.']);
disp('(syn=synapse, syp=polyadic synapse, gap=gap junction)');
disp(' ');
end
%preprocess database
txt(1,:)=[]; %delete header
numrows=size(num,1);
verb=zeros(numrows,1);
for i=1:numrows
if strcmp(txt{i,3},'S')
verb(i)=1;
elseif strcmp(txt{i,3},'Sp')
verb(i)=2;
elseif strcmp(txt{i,3} ,'EJ')
verb(i)=3;
end
end
reverb=zeros(numrows,1);
for i=1:numrows
if strcmp(txt{i,3},'R')
reverb(i)=1;
elseif strcmp(txt{i,3},'Rp')
reverb(i)=2;
elseif strcmp(txt{i,3} ,'EJ')
reverb(i)=3;
end
end
neuron1L=[neuron 'L'];
neuron1R=[neuron 'R'];
for i=1:numrows
if strcmp(txt(i,1),neuron)
neuronList={neuron}; break;
else
neuronList={};
end
end
t=0;
for i=1:numrows
if strcmp(txt(i,1),neuron1L)
neuronList={neuronList{:}, neuron1L}; break
end
end
for i=1:numrows
if strcmp(txt(i,1),neuron1R)
neuronList={neuronList{:}, neuron1R}; break
end
end
for ii=1:length(neuronList)
if verboseFlag
disp(' ');
disp('------------------------------');
disp(['|| ' neuronList{ii} ]);
end
nobj(ii)=FindNeighborsOneNeuron(neuronList{ii},max_hops);
end
if ~exist('nobj') nobj=[]; end
%subfuncs
function snobj=FindNeighborsOneNeuron(n1,maxhops)
snobj.n=n1;
m=1;
if (verboseFlag) disp('one hop paths:'); end
%find 1-hop paths
for i=1:numrows
if strcmp(n1,txt(i,1))
if verb(i)~=0 && verb(i)~=3
%plot
p{m}=[txt{i,1} ' -' num2str(num(i)) verblist{verb(i)} '-> ' txt{i,2} ...
];
numsyn(m)=num(i);
if verboseFlag disp(p{m}); end
%write into nobj
snobj.downNeighbor{m}=txt{i,2};
snobj.downJunction{m}=verblist{verb(i)};
snobj.downStrength(m)=num(i);
m=m+1;
end
end
end
if verboseFlag
if (m==1) disp('none'); else disp([num2str(m-1) ' downstream neighbors found.']); end;
disp('---');
end
m=1;
for i=1:numrows
if strcmp(n1,txt(i,2))
if verb(i)~=0 && verb(i)~=3
p{m}=[txt{i,1} ' -' num2str(num(i)) verblist{verb(i)} '-> ' txt{i,2} ...
];
numsyn(m)=num(i);
if verboseFlag disp(p{m}); end
%write into nobj
snobj.upNeighbor{m}=txt{i,1};
snobj.upJunction{m}=verblist{verb(i)};
snobj.upStrength(m)=num(i);
m=m+1;
end
end
end
if verboseFlag
if (m==1) disp('none'); else disp([num2str(m-1) ' upstream neighbors found.']); end;
disp('---GAP JUNCTIONS---');
end
%write out gap junctions
m=1;
for i=1:numrows
if strcmp(n1,txt(i,2))
if verb(i)==3
p{m}=[txt{i,1} ' -' num2str(num(i)) verblist{verb(i)} '-> ' txt{i,2}];
if verboseFlag disp(p{m}); end
snobj.gapNeighbor{m}=txt{i,1};
snobj.gapStrength(m)=num(i);
% elseif strcmp(n1,txt(i,1))
% snobj.gapneighbor{m}=txt{i,2};
% snobj.gapstrength(m)=num(i);
m=m+1;
end
end
end
%multi-hop neighbors not yet implemented
% %find 2-hop paths
%
% if maxhops>1 %2 hops
% if verboseFlag
% disp(' ');
% disp('two hop paths:');
% end
% n=1;
% for i=1:numrows
% if strcmp(n1,txt(i,1))
% for j=1:numrows
% if strcmp(n2,txt(j,2)) && strcmp(txt(j,1),txt(i,2))
% if verb(i)~=0 && verb(j)~=0
% pp{n}=[txt{i,1} ' -' num2str(num(i)) verblist{verb(i)} '-> '...
% txt{i,2} ' -' num2str(num(j)) verblist{verb(j)} '-> ' txt{j,2}];
% numpp1(n)=num(i);
% numpp2(n)=num(j);
% if verboseFlag disp(pp{n}); end
% n=n+1;
% end
% end
% end
% end
% end
% if verboseFlag
% if (n==1) disp('none'); else disp([num2str(n-1) ' 2-hop paths found.']); end;
% end
% end
%
% %find 3-hop paths
% if maxhops>2 %3 hops
% disp(' ');
% disp('three hop paths:');
%
% c2=1;
% for i=1:numrows
% if strcmp(n1,txt(i,1))
% if verb(i)~=0
% ppp_2{c2}=txt(i,2);
% ppp_12{c2}=[num2str(num(i)) verblist{verb(i)}];
% c2=c2+1;
% end
% end
% end
%
% c3=1;
% for i=1:numrows
% if strcmp(n2,txt(i,2))
% if reverb(i)~=0
% ppp_3{c3}=txt(i,1);
% ppp_34{c3}=[num2str(num(i)) verblist{reverb(i)}];
% c3=c3+1;
% end
% end
% end
% c2=c2-1;
% c3=c3-1;
%
% q=1;
% for c=1:c2
% for cc=1:c3
% for i=1:numrows
% if strcmp(ppp_2{c},txt(i,1)) && strcmp(ppp_3{cc},txt(i,2))
% if verb(i)~=0
% ppp{q}=[n1 ' -' ppp_12{c} '-> ' txt{i,1} ...
% ' -' num2str(num(i)) verblist{verb(i)} '-> ' txt{i,2} ...
% ' -' ppp_34{cc} '-> ' n2];
%
% if (verboseFlag) disp(ppp{q}); end
% q=q+1;
% end
% end
% end
% end
% end
%
% if verboseFlag
% if (q==1) disp('none'); else disp([num2str(q-1) ' 3-hop paths found.']); end;
% end
% end
end %FindPathsOneNeuron
end %findpaths