@@ -34,9 +34,16 @@ public static boolean isUnbranchedNonOverlapping(SegmentGroup sg) {
34
34
sg .getNeuroLexId ().equals (NEUROML2_NEUROLEX_UNBRANCHED_NONOVERLAPPING_SEG_GROUP );
35
35
}
36
36
37
- public static boolean hasUnbranchedNonOverlappingInfo (Cell cell )
37
+ @ Deprecated
38
+ public static boolean hasUnbranchedNonOverlappingInfo (Cell cell ) throws NeuroMLException
38
39
{
39
- for (SegmentGroup sg : cell .getMorphology ().getSegmentGroup ())
40
+ return hasUnbranchedNonOverlappingInfo (cell , null );
41
+ }
42
+
43
+ public static boolean hasUnbranchedNonOverlappingInfo (Cell cell , NeuroMLDocument nml2doc ) throws NeuroMLException {
44
+
45
+ Morphology morphology = getCellMorphology (cell , nml2doc );
46
+ for (SegmentGroup sg : morphology .getSegmentGroup ())
40
47
{
41
48
if (isUnbranchedNonOverlapping (sg ))
42
49
{
@@ -46,21 +53,26 @@ public static boolean hasUnbranchedNonOverlappingInfo(Cell cell)
46
53
return false ;
47
54
}
48
55
49
- public static Morphology getCellMorphology (Cell cell , NeuroMLDocument nml2doc ) {
56
+ public static Morphology getCellMorphology (Cell cell , NeuroMLDocument nml2doc ) throws NeuroMLException {
50
57
51
58
if (cell .getMorphology ()!=null ) {
52
-
53
59
return cell .getMorphology ();
54
60
}
55
-
56
61
else if (cell .getMorphologyAttr () !=null )
57
- {
58
- for (Morphology m : nml2doc .getMorphology ()) {
62
+ {
63
+ for (Morphology m : nml2doc .getMorphology ())
64
+ {
59
65
if (m .getId ().equals (cell .getMorphologyAttr ()))
60
66
return m ;
61
67
}
62
- }
63
- return null ;
68
+ throw new NeuroMLException ("Cannot find morphology: " +cell .getMorphologyAttr ()+" specified as an attribute in cell: " +cell .getId ());
69
+ }
70
+ else if (nml2doc ==null )
71
+ {
72
+ return null ;
73
+ // Cannot get any morphology attribute
74
+ }
75
+ return null ; // may be expected...
64
76
}
65
77
66
78
public static BiophysicalProperties getCellBiophysicalProperties (Cell cell , NeuroMLDocument nml2doc ) {
@@ -80,7 +92,10 @@ else if (cell.getBiophysicalPropertiesAttr() !=null)
80
92
return null ;
81
93
}
82
94
83
-
95
+ /**
96
+ * @deprecated use LinkedHashMap<Integer, Segment> getIdsVsSegments(Cell cell, NeuroMLDocument nml2doc) instead.
97
+ */
98
+ @ Deprecated
84
99
public static LinkedHashMap <Integer , Segment > getIdsVsSegments (Cell cell ) {
85
100
86
101
LinkedHashMap <Integer , Segment > idsVsSegments = new LinkedHashMap <Integer , Segment >();
@@ -90,6 +105,16 @@ public static LinkedHashMap<Integer, Segment> getIdsVsSegments(Cell cell) {
90
105
return idsVsSegments ;
91
106
}
92
107
108
+ public static LinkedHashMap <Integer , Segment > getIdsVsSegments (Cell cell , NeuroMLDocument nml2doc ) throws NeuroMLException {
109
+
110
+ LinkedHashMap <Integer , Segment > idsVsSegments = new LinkedHashMap <Integer , Segment >();
111
+ Morphology morphology = getCellMorphology (cell , nml2doc );
112
+ for (Segment seg : morphology .getSegment ()) {
113
+ idsVsSegments .put (seg .getId (), seg );
114
+ }
115
+ return idsVsSegments ;
116
+ }
117
+
93
118
public static SegmentGroup getSegmentGroup (Cell cell , String id ) throws NeuroMLException {
94
119
for (SegmentGroup sg : cell .getMorphology ().getSegmentGroup ()) {
95
120
if (sg .getId ().equals (id ))
@@ -98,8 +123,13 @@ public static SegmentGroup getSegmentGroup(Cell cell, String id) throws NeuroMLE
98
123
throw new NeuroMLException ("No SegmentGroup with id: " +id +" in cell with id: " +cell .getId ());
99
124
}
100
125
126
+ @ Deprecated
101
127
public static Segment getSegmentWithId (Cell cell , int segmentId ) throws NeuroMLException {
102
- List <Segment > segments = cell .getMorphology ().getSegment ();
128
+ return getSegmentWithId (cell , null , segmentId );
129
+ }
130
+
131
+ public static Segment getSegmentWithId (Cell cell , NeuroMLDocument nml2doc , int segmentId ) throws NeuroMLException {
132
+ List <Segment > segments = getCellMorphology (cell , nml2doc ).getSegment ();
103
133
if (segments .size ()>segmentId ) {
104
134
Segment guess = segments .get (segmentId );
105
135
if (guess .getId ()==segmentId )
@@ -112,16 +142,21 @@ public static Segment getSegmentWithId(Cell cell, int segmentId) throws NeuroMLE
112
142
throw new NeuroMLException ("No Segment with id: " +segmentId +" in cell with id: " +cell .getId ());
113
143
}
114
144
115
- public static LinkedHashMap <String , SegmentGroup > getNamesVsSegmentGroups (Cell cell ) {
145
+ public static LinkedHashMap <String , SegmentGroup > getNamesVsSegmentGroups (Cell cell , NeuroMLDocument nml2doc ) throws NeuroMLException {
116
146
117
147
LinkedHashMap <String , SegmentGroup > namesVsSegmentGroups = new LinkedHashMap <String , SegmentGroup >();
118
- for (SegmentGroup sg : cell . getMorphology ( ).getSegmentGroup ()) {
148
+ for (SegmentGroup sg : getCellMorphology ( cell , nml2doc ).getSegmentGroup ()) {
119
149
namesVsSegmentGroups .put (sg .getId (), sg );
120
150
}
121
151
return namesVsSegmentGroups ;
122
152
}
123
153
124
- public static ArrayList <Integer > getSegmentIdsInGroup (Cell cell , String segmentGroup ) {
154
+ public static LinkedHashMap <String , SegmentGroup > getNamesVsSegmentGroups (Cell cell ) throws NeuroMLException {
155
+
156
+ return getNamesVsSegmentGroups (cell , null );
157
+ }
158
+
159
+ public static ArrayList <Integer > getSegmentIdsInGroup (Cell cell , String segmentGroup ) throws NeuroMLException {
125
160
126
161
for (SegmentGroup sg : cell .getMorphology ().getSegmentGroup ()) {
127
162
if (sg .getId ().equals (segmentGroup )) {
@@ -158,34 +193,45 @@ public static boolean hasSegmentGroup(Cell cell, String segmentGroup) {
158
193
return false ;
159
194
}
160
195
196
+ @ Deprecated
161
197
public static ArrayList <Segment > getSegmentsInGroup (Cell cell , String segmentGroup ) throws NeuroMLException {
198
+ return getSegmentsInGroup (cell , null , segmentGroup );
199
+ }
162
200
163
- for (SegmentGroup sg : cell .getMorphology ().getSegmentGroup ()) {
201
+ public static ArrayList <Segment > getSegmentsInGroup (Cell cell , NeuroMLDocument nml2doc , String segmentGroup ) throws NeuroMLException {
202
+
203
+ for (SegmentGroup sg : CellUtils .getCellMorphology (cell , nml2doc ).getSegmentGroup ()) {
164
204
if (sg .getId ().equals (segmentGroup )) {
165
- LinkedHashMap <String , SegmentGroup > namesVsSegmentGroups = getNamesVsSegmentGroups (cell );
166
- return getSegmentsInGroup (cell , namesVsSegmentGroups , sg );
205
+ LinkedHashMap <String , SegmentGroup > namesVsSegmentGroups = getNamesVsSegmentGroups (cell , nml2doc );
206
+ return getSegmentsInGroup (cell , nml2doc , namesVsSegmentGroups , sg );
167
207
}
168
208
}
169
209
throw new NeuroMLException ("No SegmentGroup: " +segmentGroup +" in cell with id: " +cell .getId ());
170
210
}
171
211
212
+
172
213
public static ArrayList <Segment > getSegmentsInGroup (Cell cell , LinkedHashMap <String , SegmentGroup > namesVsSegmentGroups , SegmentGroup segmentGroup ) throws NeuroMLException {
173
214
215
+ return getSegmentsInGroup (cell , null , namesVsSegmentGroups , segmentGroup );
216
+ }
217
+
218
+ public static ArrayList <Segment > getSegmentsInGroup (Cell cell , NeuroMLDocument nml2doc , LinkedHashMap <String , SegmentGroup > namesVsSegmentGroups , SegmentGroup segmentGroup ) throws NeuroMLException {
219
+
174
220
ArrayList <Segment > segsHere = new ArrayList <Segment >();
175
221
176
222
for (Member memb : segmentGroup .getMember ()) {
177
- segsHere .add (getSegmentWithId (cell , memb .getSegment ()));
223
+ segsHere .add (getSegmentWithId (cell , nml2doc , memb .getSegment ()));
178
224
}
179
225
for (Include inc : segmentGroup .getInclude ()) {
180
226
String sg = inc .getSegmentGroup ();
181
- ArrayList <Segment > segs = getSegmentsInGroup (cell , namesVsSegmentGroups , namesVsSegmentGroups .get (sg ));
227
+ ArrayList <Segment > segs = getSegmentsInGroup (cell , nml2doc , namesVsSegmentGroups , namesVsSegmentGroups .get (sg ));
182
228
segsHere .addAll (segs );
183
229
}
184
230
185
231
return segsHere ;
186
232
}
187
233
188
- public static LinkedHashMap <SegmentGroup , ArrayList <Integer >> getSegmentGroupsVsSegIds (Cell cell ) {
234
+ public static LinkedHashMap <SegmentGroup , ArrayList <Integer >> getSegmentGroupsVsSegIds (Cell cell ) throws NeuroMLException {
189
235
190
236
LinkedHashMap <SegmentGroup , ArrayList <Integer >> sgVsSegId = new LinkedHashMap <SegmentGroup , ArrayList <Integer >>();
191
237
@@ -199,13 +245,33 @@ public static LinkedHashMap<SegmentGroup, ArrayList<Integer>> getSegmentGroupsVs
199
245
return sgVsSegId ;
200
246
}
201
247
248
+ public static LinkedHashMap <SegmentGroup , ArrayList <Integer >> getSegmentGroupsVsSegIds (Cell cell , NeuroMLDocument nml2doc ) throws NeuroMLException {
249
+
250
+ LinkedHashMap <SegmentGroup , ArrayList <Integer >> sgVsSegId = new LinkedHashMap <SegmentGroup , ArrayList <Integer >>();
251
+
252
+ Morphology morphology = getCellMorphology (cell , nml2doc );
253
+
254
+ LinkedHashMap <String , SegmentGroup > namesVsSegmentGroups = getNamesVsSegmentGroups (cell , nml2doc );
255
+
256
+ for (SegmentGroup sg : morphology .getSegmentGroup ()) {
257
+ ArrayList <Integer > segsHere = getSegmentIdsInGroup (namesVsSegmentGroups , sg );
258
+ sgVsSegId .put (sg , segsHere );
259
+ }
260
+
261
+ return sgVsSegId ;
262
+ }
263
+
202
264
public static double distance (Point3DWithDiam p , Point3DWithDiam d ) {
203
265
return Math .sqrt ( Math .pow (p .getX ()-d .getX (),2 ) + Math .pow (p .getY ()-d .getY (),2 ) + Math .pow (p .getZ ()-d .getZ (),2 ) );
204
266
}
205
267
206
268
public static double getFractionAlongSegGroupLength (Cell cell , String segmentGroup , int segmentId , float fractAlongSegment ) throws NeuroMLException {
269
+ return getFractionAlongSegGroupLength (cell , null , segmentGroup , segmentId , fractAlongSegment );
270
+ }
271
+
272
+ public static double getFractionAlongSegGroupLength (Cell cell , NeuroMLDocument nml2doc , String segmentGroup , int segmentId , float fractAlongSegment ) throws NeuroMLException {
207
273
208
- ArrayList <Segment > segs = getSegmentsInGroup (cell , segmentGroup );
274
+ ArrayList <Segment > segs = getSegmentsInGroup (cell , nml2doc , segmentGroup );
209
275
if (segs .size ()==1 )
210
276
{
211
277
if (segs .get (0 ).getId ()!=segmentId )
@@ -272,30 +338,45 @@ public static double getFractionAlongSegGroupLength(Cell cell, String segmentGro
272
338
273
339
public static void main (String [] args ) throws Exception {
274
340
NeuroMLConverter conv = new NeuroMLConverter ();
275
- //String test = "/home/padraig/neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/bask.cell.nml";
341
+
342
+
343
+ ArrayList <String > cellFiles = new ArrayList <String >();
344
+ cellFiles .add ("../neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/bask.cell.nml" );
276
345
//String test = "/home/padraig/neuroConstruct/osb/hippocampus/networks/nc_superdeep/neuroConstruct/generatedNeuroML2/pvbasketcell.cell.nml";
277
- String test = "/Users/padraig/ neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/pyr_4_sym.cell.nml" ;
278
- test = "/Users/padraig/git/GoC_Varied_Inputs/Cells/Golgi/GoC.cell.nml" ;
346
+ cellFiles . add ( "../ neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/pyr_4_sym.cell.nml") ;
347
+ // test = "/Users/padraig/git/GoC_Varied_Inputs/Cells/Golgi/GoC.cell.nml";
279
348
//test = "/home/padraig/neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/bask_soma.cell.nml";
280
- NeuroMLDocument nml2doc = conv .loadNeuroML (new File (test ));
281
349
282
- Cell cell = nml2doc .getCell ().get (0 );
283
- System .out .println ("cell: " + cell .getId ());
350
+ cellFiles .add ("../git/morphology_include/pyr_soma_m_out_b_in.cell.nml" );
284
351
285
- LinkedHashMap <Integer , Segment > ids = getIdsVsSegments (cell );
352
+ for (String cellFile : cellFiles )
353
+ {
354
+ NeuroMLDocument nml2doc = conv .loadNeuroML (new File (cellFile ), true , true );
286
355
287
- System . out . println ( "getIdsVsSegments: " );
288
- for ( Integer id : ids . keySet ()) {
289
- System . out . println ( "ID " + id + ": " + ids . get ( id ));
290
- }
356
+ Cell cell = nml2doc . getCell (). get ( 0 );
357
+ System . out . println ( "-------- Cell loaded: " + cell . getId ()+ " from " + cellFile );
358
+
359
+ LinkedHashMap < Integer , Segment > ids = getIdsVsSegments ( cell , nml2doc );
291
360
292
- LinkedHashMap <SegmentGroup , ArrayList <Integer >> sgVsSegId = getSegmentGroupsVsSegIds (cell );
293
- for (SegmentGroup sg : sgVsSegId .keySet ()) {
294
- System .out .println ("SG " +sg .getId ()+": " +sgVsSegId .get (sg ));
361
+ System .out .println ("getIdsVsSegments: " );
362
+ for (Integer id : ids .keySet ()) {
363
+ System .out .println ("ID " +id +": " +ids .get (id ));
364
+ }
365
+
366
+ System .out .println ("hasUnbranchedNonOverlappingInfo: " +hasUnbranchedNonOverlappingInfo (cell , nml2doc ));
367
+ System .out .println ("getSegmentWithId: " +getSegmentWithId (cell , nml2doc , 0 ));
368
+
369
+ System .out .println ("getSegmentsInGroup: " +getSegmentsInGroup (cell , nml2doc , "soma_group" ));
370
+
371
+ System .out .println ("getFractionAlongSegGroupLength: " +getFractionAlongSegGroupLength (cell , nml2doc , "soma_group" , 0 , 0.1f ));
372
+
373
+ LinkedHashMap <SegmentGroup , ArrayList <Integer >> sgVsSegId = getSegmentGroupsVsSegIds (cell , nml2doc );
374
+ for (SegmentGroup sg : sgVsSegId .keySet ()) {
375
+ System .out .println ("SG " +sg .getId ()+": " +sgVsSegId .get (sg ));
376
+ }
377
+ //getFractionAlongSegGroupLength(cell, "basal2", 8, 0.1f);
378
+ //getFractionAlongSegGroupLength(cell, "some_apicals", 2, 0.5f);
295
379
}
296
- getFractionAlongSegGroupLength (cell , "soma_group" , 0 , 0.1f );
297
- //getFractionAlongSegGroupLength(cell, "basal2", 8, 0.1f);
298
- //getFractionAlongSegGroupLength(cell, "some_apicals", 2, 0.5f);
299
380
300
381
}
301
382
0 commit comments