Skip to content

Commit 72c56e1

Browse files
committed
Improved handling of cells with external morphology/biophysics
1 parent 23132a9 commit 72c56e1

File tree

2 files changed

+121
-39
lines changed

2 files changed

+121
-39
lines changed

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

Lines changed: 119 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@ public static boolean isUnbranchedNonOverlapping(SegmentGroup sg) {
3434
sg.getNeuroLexId().equals(NEUROML2_NEUROLEX_UNBRANCHED_NONOVERLAPPING_SEG_GROUP);
3535
}
3636

37-
public static boolean hasUnbranchedNonOverlappingInfo(Cell cell)
37+
@Deprecated
38+
public static boolean hasUnbranchedNonOverlappingInfo(Cell cell) throws NeuroMLException
3839
{
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())
4047
{
4148
if (isUnbranchedNonOverlapping(sg))
4249
{
@@ -46,21 +53,26 @@ public static boolean hasUnbranchedNonOverlappingInfo(Cell cell)
4653
return false;
4754
}
4855

49-
public static Morphology getCellMorphology(Cell cell, NeuroMLDocument nml2doc) {
56+
public static Morphology getCellMorphology(Cell cell, NeuroMLDocument nml2doc) throws NeuroMLException {
5057

5158
if (cell.getMorphology()!=null) {
52-
5359
return cell.getMorphology();
5460
}
55-
5661
else if (cell.getMorphologyAttr() !=null)
57-
{
58-
for (Morphology m: nml2doc.getMorphology()) {
62+
{
63+
for (Morphology m: nml2doc.getMorphology())
64+
{
5965
if (m.getId().equals(cell.getMorphologyAttr()))
6066
return m;
6167
}
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...
6476
}
6577

6678
public static BiophysicalProperties getCellBiophysicalProperties(Cell cell, NeuroMLDocument nml2doc) {
@@ -80,7 +92,10 @@ else if (cell.getBiophysicalPropertiesAttr() !=null)
8092
return null;
8193
}
8294

83-
95+
/**
96+
* @deprecated use LinkedHashMap<Integer, Segment> getIdsVsSegments(Cell cell, NeuroMLDocument nml2doc) instead.
97+
*/
98+
@Deprecated
8499
public static LinkedHashMap<Integer, Segment> getIdsVsSegments(Cell cell) {
85100

86101
LinkedHashMap<Integer, Segment> idsVsSegments = new LinkedHashMap<Integer, Segment>();
@@ -90,6 +105,16 @@ public static LinkedHashMap<Integer, Segment> getIdsVsSegments(Cell cell) {
90105
return idsVsSegments;
91106
}
92107

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+
93118
public static SegmentGroup getSegmentGroup(Cell cell, String id) throws NeuroMLException {
94119
for (SegmentGroup sg: cell.getMorphology().getSegmentGroup()) {
95120
if (sg.getId().equals(id))
@@ -98,8 +123,13 @@ public static SegmentGroup getSegmentGroup(Cell cell, String id) throws NeuroMLE
98123
throw new NeuroMLException("No SegmentGroup with id: "+id+" in cell with id: "+cell.getId());
99124
}
100125

126+
@Deprecated
101127
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();
103133
if (segments.size()>segmentId) {
104134
Segment guess = segments.get(segmentId);
105135
if (guess.getId()==segmentId)
@@ -112,16 +142,21 @@ public static Segment getSegmentWithId(Cell cell, int segmentId) throws NeuroMLE
112142
throw new NeuroMLException("No Segment with id: "+segmentId+" in cell with id: "+cell.getId());
113143
}
114144

115-
public static LinkedHashMap<String, SegmentGroup> getNamesVsSegmentGroups(Cell cell) {
145+
public static LinkedHashMap<String, SegmentGroup> getNamesVsSegmentGroups(Cell cell, NeuroMLDocument nml2doc) throws NeuroMLException {
116146

117147
LinkedHashMap<String, SegmentGroup> namesVsSegmentGroups = new LinkedHashMap<String, SegmentGroup>();
118-
for (SegmentGroup sg : cell.getMorphology().getSegmentGroup()) {
148+
for (SegmentGroup sg : getCellMorphology(cell, nml2doc).getSegmentGroup()) {
119149
namesVsSegmentGroups.put(sg.getId(), sg);
120150
}
121151
return namesVsSegmentGroups;
122152
}
123153

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 {
125160

126161
for (SegmentGroup sg : cell.getMorphology().getSegmentGroup()) {
127162
if (sg.getId().equals(segmentGroup)) {
@@ -158,34 +193,45 @@ public static boolean hasSegmentGroup(Cell cell, String segmentGroup) {
158193
return false;
159194
}
160195

196+
@Deprecated
161197
public static ArrayList<Segment> getSegmentsInGroup(Cell cell, String segmentGroup) throws NeuroMLException {
198+
return getSegmentsInGroup(cell, null, segmentGroup);
199+
}
162200

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()) {
164204
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);
167207
}
168208
}
169209
throw new NeuroMLException("No SegmentGroup: "+segmentGroup+" in cell with id: "+cell.getId());
170210
}
171211

212+
172213
public static ArrayList<Segment> getSegmentsInGroup(Cell cell, LinkedHashMap<String, SegmentGroup> namesVsSegmentGroups, SegmentGroup segmentGroup) throws NeuroMLException {
173214

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+
174220
ArrayList<Segment> segsHere = new ArrayList<Segment>();
175221

176222
for (Member memb : segmentGroup.getMember()) {
177-
segsHere.add(getSegmentWithId(cell, memb.getSegment()));
223+
segsHere.add(getSegmentWithId(cell, nml2doc, memb.getSegment()));
178224
}
179225
for (Include inc : segmentGroup.getInclude()) {
180226
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));
182228
segsHere.addAll(segs);
183229
}
184230

185231
return segsHere;
186232
}
187233

188-
public static LinkedHashMap<SegmentGroup, ArrayList<Integer>> getSegmentGroupsVsSegIds(Cell cell) {
234+
public static LinkedHashMap<SegmentGroup, ArrayList<Integer>> getSegmentGroupsVsSegIds(Cell cell) throws NeuroMLException {
189235

190236
LinkedHashMap<SegmentGroup, ArrayList<Integer>> sgVsSegId = new LinkedHashMap<SegmentGroup, ArrayList<Integer>>();
191237

@@ -199,13 +245,33 @@ public static LinkedHashMap<SegmentGroup, ArrayList<Integer>> getSegmentGroupsVs
199245
return sgVsSegId;
200246
}
201247

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+
202264
public static double distance(Point3DWithDiam p, Point3DWithDiam d) {
203265
return Math.sqrt( Math.pow(p.getX()-d.getX(),2) + Math.pow(p.getY()-d.getY(),2) + Math.pow(p.getZ()-d.getZ(),2) );
204266
}
205267

206268
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 {
207273

208-
ArrayList<Segment> segs = getSegmentsInGroup(cell, segmentGroup);
274+
ArrayList<Segment> segs = getSegmentsInGroup(cell, nml2doc, segmentGroup);
209275
if (segs.size()==1)
210276
{
211277
if(segs.get(0).getId()!=segmentId)
@@ -272,30 +338,45 @@ public static double getFractionAlongSegGroupLength(Cell cell, String segmentGro
272338

273339
public static void main(String[] args) throws Exception {
274340
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");
276345
//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";
279348
//test = "/home/padraig/neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/bask_soma.cell.nml";
280-
NeuroMLDocument nml2doc = conv.loadNeuroML(new File(test));
281349

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");
284351

285-
LinkedHashMap<Integer, Segment> ids = getIdsVsSegments(cell);
352+
for(String cellFile : cellFiles)
353+
{
354+
NeuroMLDocument nml2doc = conv.loadNeuroML(new File(cellFile), true, true);
286355

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);
291360

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);
295379
}
296-
getFractionAlongSegGroupLength(cell, "soma_group", 0, 0.1f);
297-
//getFractionAlongSegGroupLength(cell, "basal2", 8, 0.1f);
298-
//getFractionAlongSegGroupLength(cell, "some_apicals", 2, 0.5f);
299380

300381
}
301382

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ public static void main(String[] args) throws Exception {
560560
//File f = new File("../git/morphology_include/pyr_soma_m_in_b_in.cell.nml");
561561
//File f = new File("../git/morphology_include/pyr_soma_m_out_b_in.cell.nml");
562562
//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");
563+
//File f = new File("../git/morphology_include/pyr_soma_m_out_b_out.cell.nml");
564+
File f = new File("../NeuroML2/examples/NML2_FullNeuroML.nml");
564565
//File f = new File("../neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/pyr_4_sym.cell.nml");
565566
//File f = new File("../neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/MediumNet.net.nml");
566567
//File f = new File("../OpenCortex/examples/Deterministic.net.nml");

0 commit comments

Comments
 (0)