-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoFindPaths.m
More file actions
291 lines (236 loc) · 7 KB
/
coFindPaths.m
File metadata and controls
291 lines (236 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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
function [nobj numTwoHops]=coFindPaths(neuron1,neuron2,max_hops,verboseFlag,coStruct)
%COFINDPATHS(neuron1,neuron2,max_hops,verboseFlag)
%
%find all one or two hop pathways from neuron1 to neuron2
%in maxhops or fewer hops (maxhops cannot exceed 3)
%
%**currently, output datastructure only includes direct paths, not multihop
% although these are given in the verbose command line output
%
%.if particular left or right suffix is not specified in neuron names,
%the search will be performed for all possible L/R combinations and
%output will be given as a struct array
%
%
%example: coFindPaths('ASH','AWC');
%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
%101201
%
if nargin<3 || isempty(max_hops)
max_hops=2;
end
if nargin<1
neuron1='AWCL';
end
if nargin<2
neuron2='AIAL';
end
if nargin<4 || isempty(verboseFlag)
verboseFlag=true;
end
if verboseFlag
disp(' ');
disp(['FINDING PATHS FOR ' neuron1 ' -> ' neuron2 ', max ' num2str(max_hops) ' hops.']);
disp('(syn=synapse, syp=polyadic synapse, gap=gap junction)');
disp(' ');
end
verblist={'syn','syp','gap'};
if nargin<4 || isempty(coStruct)
%load database
[num,txt,raw] = xlsread('NeuronConnect.xls','','','basic');
%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
else
verb=coStruct.verb;
reverb=coStruct.reverb;
num=coStruct.num;
txt=coStruct.txt;
numrows=size(num,1);
end
neuron1L=[neuron1 'L'];
neuron2L=[neuron2 'L'];
neuron1R=[neuron1 'R'];
neuron2R=[neuron2 'R'];
for i=1:numrows
if strcmp(txt(i,1),neuron1)
firstneuron={neuron1}; break;
else
firstneuron={};
end
end
for i=1:numrows
if strcmp(txt(i,1),neuron2)
secondneuron={neuron2}; break;
else
secondneuron={};
end
end
for i=1:numrows
if strcmp(txt(i,1),neuron1L)
firstneuron={firstneuron{:}, neuron1L}; break
end
end
for i=1:numrows
if strcmp(txt(i,1),neuron1R)
firstneuron={firstneuron{:}, neuron1R}; break
end
end
for i=1:numrows
if strcmp(txt(i,1),neuron1L)
secondneuron={secondneuron{:}, neuron2L}; break
end
end
for i=1:numrows
if strcmp(txt(i,1),neuron1R)
secondneuron={secondneuron{:}, neuron2R}; break
end
end
kk=1;
for ii=1:length(firstneuron)
for jj=1:length(secondneuron)
if verboseFlag
disp(' ');
disp('------------------------------');
disp(['|| ' firstneuron{ii} ' -> ' secondneuron{jj} ' ||']);
end
nobj(kk)=FindPathsOneNeuron(firstneuron{ii},secondneuron{jj},max_hops);
kk=kk+1;
end
end
if ~exist('nobj') nobj=[]; end
%subfuncs
function snobj=FindPathsOneNeuron(n1,n2,maxhops)
snobj.n1=n1;
snobj.n2=n2;
m=1;
if verboseFlag
disp('one hop paths:');
end
snobj.downjunction=[];
snobj.downstrength=[];
%find 1-hop paths
for i=1:numrows
if strcmp(n1,txt(i,1))
if strcmp(n2,txt(i,2))
if verb(i)~=0
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.downjunction{m}=verblist{verb(i)};
snobj.downstrength(m)=num(i);
m=m+1;
end
end
end
end
if verboseFlag
if (m==1) disp('none'); else disp([num2str(m-1) ' 1-hop paths found.']); end;
end
%find 2-hop paths
if maxhops>1 %2 hops
numTwoHops=0;
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
numTwoHops=numTwoHops+1;
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
if verboseFlag
disp(' ');
disp('three hop paths:');
end
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
end %main