Skip to content

Commit

Permalink
Changes to correctly validate cells with external morph/biophys
Browse files Browse the repository at this point in the history
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">
  • Loading branch information
pgleeson committed May 29, 2024
1 parent e9d6a4c commit 23132a9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 17 deletions.
41 changes: 39 additions & 2 deletions src/main/java/org/neuroml/model/util/CellUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.neuroml.model.Point3DWithDiam;
import org.neuroml.model.Segment;
import org.neuroml.model.SegmentGroup;
import org.neuroml.model.Morphology;
import org.neuroml.model.BiophysicalProperties;

/**
*
Expand Down Expand Up @@ -44,6 +46,41 @@ public static boolean hasUnbranchedNonOverlappingInfo(Cell cell)
return false;
}

public static Morphology getCellMorphology(Cell cell, NeuroMLDocument nml2doc) {

if (cell.getMorphology()!=null) {

return cell.getMorphology();
}

else if (cell.getMorphologyAttr() !=null)
{
for (Morphology m: nml2doc.getMorphology()) {
if (m.getId().equals(cell.getMorphologyAttr()))
return m;
}
}
return null;
}

public static BiophysicalProperties getCellBiophysicalProperties(Cell cell, NeuroMLDocument nml2doc) {

if (cell.getBiophysicalProperties()!=null) {

return cell.getBiophysicalProperties();
}

else if (cell.getBiophysicalPropertiesAttr() !=null)
{
for (BiophysicalProperties bp: nml2doc.getBiophysicalProperties()) {
if (bp.getId().equals(cell.getBiophysicalPropertiesAttr()))
return bp;
}
}
return null;
}


public static LinkedHashMap<Integer, Segment> getIdsVsSegments(Cell cell) {

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

Cell cell = nml2.getCell().get(0);
Cell cell = nml2doc.getCell().get(0);
System.out.println("cell: " + cell.getId());

LinkedHashMap<Integer, Segment> ids = getIdsVsSegments(cell);
Expand Down
51 changes: 36 additions & 15 deletions src/main/java/org/neuroml/model/util/NeuroML2Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.neuroml.model.SegmentGroup;
import org.neuroml.model.Species;
import org.neuroml.model.Standalone;
import org.neuroml.model.Morphology;
import org.neuroml.model.BiophysicalProperties;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

Expand Down Expand Up @@ -139,22 +141,22 @@ public void validateWithTests(File xmlFile) throws SAXException, IOException, Ne
return;
}
NeuroMLConverter conv = new NeuroMLConverter();
NeuroMLDocument nml2 = conv.loadNeuroML(xmlFile, true, false);
validateWithTests(nml2);
NeuroMLDocument nml2doc = conv.loadNeuroML(xmlFile, true, false);
validateWithTests(nml2doc);

}

/*
* TODO: Needs to be moved to a separate package for validation!
*/
public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
public void validateWithTests(NeuroMLDocument nml2doc) throws NeuroMLException
{
// Checks the areas the Schema just can't reach...

//////////////////////////////////////////////////////////////////
// <include ...>
//////////////////////////////////////////////////////////////////
for (IncludeType include: nml2.getInclude()) {
for (IncludeType include: nml2doc.getInclude()) {
File inclFile = new File(baseDirectory, include.getHref());

test(TEST_INCLUDED_FILES_EXIST, "Included file: "+include.getHref()
Expand All @@ -164,7 +166,7 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
LinkedHashMap<String,Standalone> standalones = null;
try
{
standalones = NeuroMLConverter.getAllStandaloneElements(nml2);
standalones = NeuroMLConverter.getAllStandaloneElements(nml2doc);
}
catch (NeuroMLException ne)
{
Expand All @@ -186,16 +188,18 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
//////////////////////////////////////////////////////////////////

HashMap<String, ArrayList<Integer>> cellidsVsSegs = new HashMap<String, ArrayList<Integer>>();
for (Cell cell: nml2.getCell()){
for (Cell cell: nml2doc.getCell()){

// Morphologies
ArrayList<Integer> segIds = new ArrayList<Integer>();
ArrayList<String> segGroups = new ArrayList<String>();

boolean rootFound = false;
int numParentless = 0;
if (cell.getMorphology() != null) {
for(Segment segment: cell.getMorphology().getSegment()) {
Morphology morphology = CellUtils.getCellMorphology(cell, nml2doc);

if (morphology != null) {
for(Segment segment: morphology.getSegment()) {
int segId = segment.getId();

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

for(SegmentGroup segmentGroup: cell.getMorphology().getSegmentGroup()) {
for(SegmentGroup segmentGroup: morphology.getSegmentGroup()) {

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

Expand Down Expand Up @@ -245,7 +249,7 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
}
}

for(SegmentGroup segmentGroup: cell.getMorphology().getSegmentGroup()) {
for(SegmentGroup segmentGroup: morphology.getSegmentGroup()) {
segGroups.add(segmentGroup.getId());
for (Include inc: segmentGroup.getInclude()) {
// This second time time, all segment groups are known, so fail if included group missing
Expand All @@ -257,8 +261,10 @@ public void validateWithTests(NeuroMLDocument nml2) throws NeuroMLException
//TODO: test for morphology attribute!
}

if (cell.getBiophysicalProperties()!=null) {
MembraneProperties mp = cell.getBiophysicalProperties().getMembraneProperties();
BiophysicalProperties bp = CellUtils.getCellBiophysicalProperties(cell, nml2doc);

if (bp!=null) {
MembraneProperties mp = bp.getMembraneProperties();

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

IntracellularProperties ip = cell.getBiophysicalProperties().getIntracellularProperties();
IntracellularProperties ip = bp.getIntracellularProperties();

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


for (Network network: nml2.getNetwork()) {
for (Network network: nml2doc.getNetwork()) {

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

if (warnings.length()==0)
warnings.append(NO_WARNINGS);

String testFail = "failed!";
if (validity.indexOf(testFail)>=0)
{

int num = (validity.length() - validity.toString().replaceAll(testFail,"").length())/testFail.length();
if (num==1)
validity.append("\n1 failure in validation!");
else
validity.append("\n"+num+" failures in validation!");
}


}

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


public static void main(String[] args) throws Exception {
File f = new File("../neuroConstruct/osb/showcase/BlueBrainProjectShowcase/NMC/NeuroML2/CaDynamics_E2_NML2.nml");
//File f = new File("../git/morphology_include/pyr_soma_m_in_b_in.cell.nml");
//File f = new File("../git/morphology_include/pyr_soma_m_out_b_in.cell.nml");
//File f = new File("../git/morphology_include/pyr_soma_m_in_b_out.cell.nml");
File f = new File("../git/morphology_include/pyr_soma_m_out_b_out.cell.nml");
//File f = new File("../neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/pyr_4_sym.cell.nml");
//File f = new File("../neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/MediumNet.net.nml");
//File f = new File("../OpenCortex/examples/Deterministic.net.nml");
Expand Down

0 comments on commit 23132a9

Please sign in to comment.