Skip to content

Commit 23132a9

Browse files
committed
Changes to correctly validate cells with external morph/biophys
e.g. <include href="pyr_4_sym_soma_morph.nml"/> <include href="pyr_biophysics.nml"/> <cell id="pyr_4_sym_soma" morphology="morphology_pyr_soma" biophysicalProperties="biophys">
1 parent e9d6a4c commit 23132a9

File tree

2 files changed

+75
-17
lines changed

2 files changed

+75
-17
lines changed

src/main/java/org/neuroml/model/util/CellUtils.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.neuroml.model.Point3DWithDiam;
1414
import org.neuroml.model.Segment;
1515
import org.neuroml.model.SegmentGroup;
16+
import org.neuroml.model.Morphology;
17+
import org.neuroml.model.BiophysicalProperties;
1618

1719
/**
1820
*
@@ -44,6 +46,41 @@ public static boolean hasUnbranchedNonOverlappingInfo(Cell cell)
4446
return false;
4547
}
4648

49+
public static Morphology getCellMorphology(Cell cell, NeuroMLDocument nml2doc) {
50+
51+
if (cell.getMorphology()!=null) {
52+
53+
return cell.getMorphology();
54+
}
55+
56+
else if (cell.getMorphologyAttr() !=null)
57+
{
58+
for (Morphology m: nml2doc.getMorphology()) {
59+
if (m.getId().equals(cell.getMorphologyAttr()))
60+
return m;
61+
}
62+
}
63+
return null;
64+
}
65+
66+
public static BiophysicalProperties getCellBiophysicalProperties(Cell cell, NeuroMLDocument nml2doc) {
67+
68+
if (cell.getBiophysicalProperties()!=null) {
69+
70+
return cell.getBiophysicalProperties();
71+
}
72+
73+
else if (cell.getBiophysicalPropertiesAttr() !=null)
74+
{
75+
for (BiophysicalProperties bp: nml2doc.getBiophysicalProperties()) {
76+
if (bp.getId().equals(cell.getBiophysicalPropertiesAttr()))
77+
return bp;
78+
}
79+
}
80+
return null;
81+
}
82+
83+
4784
public static LinkedHashMap<Integer, Segment> getIdsVsSegments(Cell cell) {
4885

4986
LinkedHashMap<Integer, Segment> idsVsSegments = new LinkedHashMap<Integer, Segment>();
@@ -240,9 +277,9 @@ public static void main(String[] args) throws Exception {
240277
String test = "/Users/padraig/neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/pyr_4_sym.cell.nml";
241278
test = "/Users/padraig/git/GoC_Varied_Inputs/Cells/Golgi/GoC.cell.nml";
242279
//test = "/home/padraig/neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/bask_soma.cell.nml";
243-
NeuroMLDocument nml2 = conv.loadNeuroML(new File(test));
280+
NeuroMLDocument nml2doc = conv.loadNeuroML(new File(test));
244281

245-
Cell cell = nml2.getCell().get(0);
282+
Cell cell = nml2doc.getCell().get(0);
246283
System.out.println("cell: " + cell.getId());
247284

248285
LinkedHashMap<Integer, Segment> ids = getIdsVsSegments(cell);

src/main/java/org/neuroml/model/util/NeuroML2Validator.java

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import org.neuroml.model.SegmentGroup;
4141
import org.neuroml.model.Species;
4242
import org.neuroml.model.Standalone;
43+
import org.neuroml.model.Morphology;
44+
import org.neuroml.model.BiophysicalProperties;
4345
import org.w3c.dom.Element;
4446
import org.xml.sax.SAXException;
4547

@@ -139,22 +141,22 @@ public void validateWithTests(File xmlFile) throws SAXException, IOException, Ne
139141
return;
140142
}
141143
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);
144146

145147
}
146148

147149
/*
148150
* TODO: Needs to be moved to a separate package for validation!
149151
*/
150-
public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
152+
public void validateWithTests(NeuroMLDocument nml2doc) throws NeuroMLException
151153
{
152154
// Checks the areas the Schema just can't reach...
153155

154156
//////////////////////////////////////////////////////////////////
155157
// <include ...>
156158
//////////////////////////////////////////////////////////////////
157-
for (IncludeType include: nml2.getInclude()) {
159+
for (IncludeType include: nml2doc.getInclude()) {
158160
File inclFile = new File(baseDirectory, include.getHref());
159161

160162
test(TEST_INCLUDED_FILES_EXIST, "Included file: "+include.getHref()
@@ -164,7 +166,7 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
164166
LinkedHashMap<String,Standalone> standalones = null;
165167
try
166168
{
167-
standalones = NeuroMLConverter.getAllStandaloneElements(nml2);
169+
standalones = NeuroMLConverter.getAllStandaloneElements(nml2doc);
168170
}
169171
catch (NeuroMLException ne)
170172
{
@@ -186,16 +188,18 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
186188
//////////////////////////////////////////////////////////////////
187189

188190
HashMap<String, ArrayList<Integer>> cellidsVsSegs = new HashMap<String, ArrayList<Integer>>();
189-
for (Cell cell: nml2.getCell()){
191+
for (Cell cell: nml2doc.getCell()){
190192

191193
// Morphologies
192194
ArrayList<Integer> segIds = new ArrayList<Integer>();
193195
ArrayList<String> segGroups = new ArrayList<String>();
194196

195197
boolean rootFound = false;
196198
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()) {
199203
int segId = segment.getId();
200204

201205
test(TEST_REPEATED_IDS, "Current segment ID: "+segId, !segIds.contains(segId));
@@ -212,7 +216,7 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
212216
test(WARN_ROOT_ID_0, "", rootFound);
213217
test(TEST_ONE_SEG_MISSING_PARENT, "", (numParentless==1));
214218

215-
for(SegmentGroup segmentGroup: cell.getMorphology().getSegmentGroup()) {
219+
for(SegmentGroup segmentGroup: morphology.getSegmentGroup()) {
216220

217221
test(TEST_REPEATED_GROUPS, "SegmentGroup: "+segmentGroup.getId(), !segGroups.contains(segmentGroup.getId()));
218222

@@ -245,7 +249,7 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
245249
}
246250
}
247251

248-
for(SegmentGroup segmentGroup: cell.getMorphology().getSegmentGroup()) {
252+
for(SegmentGroup segmentGroup: morphology.getSegmentGroup()) {
249253
segGroups.add(segmentGroup.getId());
250254
for (Include inc: segmentGroup.getInclude()) {
251255
// 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
257261
//TODO: test for morphology attribute!
258262
}
259263

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();
262268

263269
//TODO: consolidate!
264270
for (ChannelDensity cd: mp.getChannelDensity()) {
@@ -292,7 +298,7 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
292298
test(TEST_ION_CHANNEL_EXISTS, "Ion channel: "+cd.getIonChannel()+" in "+cd.getId()+" not found!", standaloneIds.contains(cd.getIonChannel()));
293299
}
294300

295-
IntracellularProperties ip = cell.getBiophysicalProperties().getIntracellularProperties();
301+
IntracellularProperties ip = bp.getIntracellularProperties();
296302

297303
for (Species sp: ip.getSpecies()) {
298304
/* See PospischilEtAl2008/NeuroML2/cells/LTS/LTS.cell.nml for example.
@@ -306,7 +312,7 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
306312
}
307313

308314

309-
for (Network network: nml2.getNetwork()) {
315+
for (Network network: nml2doc.getNetwork()) {
310316

311317
ArrayList<String> allNetElementIds = new ArrayList<String>();
312318
//////////////////////////////////////////////////////////////////
@@ -463,6 +469,18 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
463469

464470
if (warnings.length()==0)
465471
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("\n1 failure in validation!");
480+
else
481+
validity.append("\n"+num+" failures in validation!");
482+
}
483+
466484

467485
}
468486

@@ -539,7 +557,10 @@ public static void testValidity(File xmlFile, StreamSource schemaFileSource) thr
539557

540558

541559
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");
543564
//File f = new File("../neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/pyr_4_sym.cell.nml");
544565
//File f = new File("../neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/MediumNet.net.nml");
545566
//File f = new File("../OpenCortex/examples/Deterministic.net.nml");

0 commit comments

Comments
 (0)