40
40
import org .neuroml .model .SegmentGroup ;
41
41
import org .neuroml .model .Species ;
42
42
import org .neuroml .model .Standalone ;
43
+ import org .neuroml .model .Morphology ;
44
+ import org .neuroml .model .BiophysicalProperties ;
43
45
import org .w3c .dom .Element ;
44
46
import org .xml .sax .SAXException ;
45
47
@@ -139,22 +141,22 @@ public void validateWithTests(File xmlFile) throws SAXException, IOException, Ne
139
141
return ;
140
142
}
141
143
NeuroMLConverter conv = new NeuroMLConverter ();
142
- NeuroMLDocument nml2 = conv .loadNeuroML (xmlFile , true , false );
143
- validateWithTests (nml2 );
144
+ NeuroMLDocument nml2doc = conv .loadNeuroML (xmlFile , true , false );
145
+ validateWithTests (nml2doc );
144
146
145
147
}
146
148
147
149
/*
148
150
* TODO: Needs to be moved to a separate package for validation!
149
151
*/
150
- public void validateWithTests (NeuroMLDocument nml2 ) throws NeuroMLException
152
+ public void validateWithTests (NeuroMLDocument nml2doc ) throws NeuroMLException
151
153
{
152
154
// Checks the areas the Schema just can't reach...
153
155
154
156
//////////////////////////////////////////////////////////////////
155
157
// <include ...>
156
158
//////////////////////////////////////////////////////////////////
157
- for (IncludeType include : nml2 .getInclude ()) {
159
+ for (IncludeType include : nml2doc .getInclude ()) {
158
160
File inclFile = new File (baseDirectory , include .getHref ());
159
161
160
162
test (TEST_INCLUDED_FILES_EXIST , "Included file: " +include .getHref ()
@@ -164,7 +166,7 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
164
166
LinkedHashMap <String ,Standalone > standalones = null ;
165
167
try
166
168
{
167
- standalones = NeuroMLConverter .getAllStandaloneElements (nml2 );
169
+ standalones = NeuroMLConverter .getAllStandaloneElements (nml2doc );
168
170
}
169
171
catch (NeuroMLException ne )
170
172
{
@@ -186,16 +188,18 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
186
188
//////////////////////////////////////////////////////////////////
187
189
188
190
HashMap <String , ArrayList <Integer >> cellidsVsSegs = new HashMap <String , ArrayList <Integer >>();
189
- for (Cell cell : nml2 .getCell ()){
191
+ for (Cell cell : nml2doc .getCell ()){
190
192
191
193
// Morphologies
192
194
ArrayList <Integer > segIds = new ArrayList <Integer >();
193
195
ArrayList <String > segGroups = new ArrayList <String >();
194
196
195
197
boolean rootFound = false ;
196
198
int numParentless = 0 ;
197
- if (cell .getMorphology () != null ) {
198
- for (Segment segment : cell .getMorphology ().getSegment ()) {
199
+ Morphology morphology = CellUtils .getCellMorphology (cell , nml2doc );
200
+
201
+ if (morphology != null ) {
202
+ for (Segment segment : morphology .getSegment ()) {
199
203
int segId = segment .getId ();
200
204
201
205
test (TEST_REPEATED_IDS , "Current segment ID: " +segId , !segIds .contains (segId ));
@@ -212,7 +216,7 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
212
216
test (WARN_ROOT_ID_0 , "" , rootFound );
213
217
test (TEST_ONE_SEG_MISSING_PARENT , "" , (numParentless ==1 ));
214
218
215
- for (SegmentGroup segmentGroup : cell . getMorphology () .getSegmentGroup ()) {
219
+ for (SegmentGroup segmentGroup : morphology .getSegmentGroup ()) {
216
220
217
221
test (TEST_REPEATED_GROUPS , "SegmentGroup: " +segmentGroup .getId (), !segGroups .contains (segmentGroup .getId ()));
218
222
@@ -245,7 +249,7 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
245
249
}
246
250
}
247
251
248
- for (SegmentGroup segmentGroup : cell . getMorphology () .getSegmentGroup ()) {
252
+ for (SegmentGroup segmentGroup : morphology .getSegmentGroup ()) {
249
253
segGroups .add (segmentGroup .getId ());
250
254
for (Include inc : segmentGroup .getInclude ()) {
251
255
// This second time time, all segment groups are known, so fail if included group missing
@@ -257,8 +261,10 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
257
261
//TODO: test for morphology attribute!
258
262
}
259
263
260
- if (cell .getBiophysicalProperties ()!=null ) {
261
- MembraneProperties mp = cell .getBiophysicalProperties ().getMembraneProperties ();
264
+ BiophysicalProperties bp = CellUtils .getCellBiophysicalProperties (cell , nml2doc );
265
+
266
+ if (bp !=null ) {
267
+ MembraneProperties mp = bp .getMembraneProperties ();
262
268
263
269
//TODO: consolidate!
264
270
for (ChannelDensity cd : mp .getChannelDensity ()) {
@@ -292,7 +298,7 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
292
298
test (TEST_ION_CHANNEL_EXISTS , "Ion channel: " +cd .getIonChannel ()+" in " +cd .getId ()+" not found!" , standaloneIds .contains (cd .getIonChannel ()));
293
299
}
294
300
295
- IntracellularProperties ip = cell . getBiophysicalProperties () .getIntracellularProperties ();
301
+ IntracellularProperties ip = bp .getIntracellularProperties ();
296
302
297
303
for (Species sp : ip .getSpecies ()) {
298
304
/* See PospischilEtAl2008/NeuroML2/cells/LTS/LTS.cell.nml for example.
@@ -306,7 +312,7 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
306
312
}
307
313
308
314
309
- for (Network network : nml2 .getNetwork ()) {
315
+ for (Network network : nml2doc .getNetwork ()) {
310
316
311
317
ArrayList <String > allNetElementIds = new ArrayList <String >();
312
318
//////////////////////////////////////////////////////////////////
@@ -463,6 +469,18 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
463
469
464
470
if (warnings .length ()==0 )
465
471
warnings .append (NO_WARNINGS );
472
+
473
+ String testFail = "failed!" ;
474
+ if (validity .indexOf (testFail )>=0 )
475
+ {
476
+
477
+ int num = (validity .length () - validity .toString ().replaceAll (testFail ,"" ).length ())/testFail .length ();
478
+ if (num ==1 )
479
+ validity .append ("\n 1 failure in validation!" );
480
+ else
481
+ validity .append ("\n " +num +" failures in validation!" );
482
+ }
483
+
466
484
467
485
}
468
486
@@ -539,7 +557,10 @@ public static void testValidity(File xmlFile, StreamSource schemaFileSource) thr
539
557
540
558
541
559
public static void main (String [] args ) throws Exception {
542
- File f = new File ("../neuroConstruct/osb/showcase/BlueBrainProjectShowcase/NMC/NeuroML2/CaDynamics_E2_NML2.nml" );
560
+ //File f = new File("../git/morphology_include/pyr_soma_m_in_b_in.cell.nml");
561
+ //File f = new File("../git/morphology_include/pyr_soma_m_out_b_in.cell.nml");
562
+ //File f = new File("../git/morphology_include/pyr_soma_m_in_b_out.cell.nml");
563
+ File f = new File ("../git/morphology_include/pyr_soma_m_out_b_out.cell.nml" );
543
564
//File f = new File("../neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/pyr_4_sym.cell.nml");
544
565
//File f = new File("../neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/MediumNet.net.nml");
545
566
//File f = new File("../OpenCortex/examples/Deterministic.net.nml");
0 commit comments