Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To v1.10.1; helper methods for handling when morphology/biophysProps outside cell element #41

Merged
merged 6 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/javadocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ jobs:
uses: actions/checkout@v4
with:
repository: NeuroML/NeuroML2
ref: development
ref: ${{ github.ref }}
path: NeuroML2

- name: Checkout org.neuroml.model.injectingplugin
uses: actions/checkout@v4
with:
repository: NeuroML/org.neuroml.model.injectingplugin
ref: development
ref: ${{ github.ref }}
path: org.neuroml.model.injectingplugin

- name: Install NeuroML deps
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.neuroml.model</groupId>
<artifactId>org.neuroml.model</artifactId>
<version>1.10.0</version>
<version>1.10.1</version>
<packaging>bundle</packaging>
<properties>
<build.version2>2.3.1</build.version2>
Expand All @@ -19,12 +19,12 @@
<dependency>
<groupId>org.neuroml.model.injectingplugin</groupId>
<artifactId>org.neuroml.model.injectingplugin</artifactId>
<version>1.10.0</version>
<version>1.10.1</version>
</dependency>
<dependency>
<groupId>org.neuroml.core</groupId>
<artifactId>neuroml2-base-definitions</artifactId>
<version>1.10.0</version>
<version>1.10.1</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -64,7 +64,7 @@
&lt;br /&gt;
&lt;br /&gt;
</top>
<bottom>Copyright NeuroML Contributors 2023</bottom>
<bottom>Copyright NeuroML Contributors 2024</bottom>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -105,7 +105,7 @@
</goals>
<configuration>
<resourceBundles>
<resourcebundle>org.neuroml.core:neuroml2-base-definitions:1.10.0</resourcebundle>
<resourcebundle>org.neuroml.core:neuroml2-base-definitions:1.10.1</resourcebundle>
</resourceBundles>
</configuration>
</execution>
Expand Down Expand Up @@ -198,7 +198,7 @@
<plugin>
<groupId>org.neuroml.model.injectingplugin</groupId>
<artifactId>org.neuroml.model.injectingplugin</artifactId>
<version>1.10.0</version>
<version>1.10.1</version>
</plugin>
</plugins>
</configuration>
Expand Down
178 changes: 148 additions & 30 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 All @@ -32,9 +34,16 @@ public static boolean isUnbranchedNonOverlapping(SegmentGroup sg) {
sg.getNeuroLexId().equals(NEUROML2_NEUROLEX_UNBRANCHED_NONOVERLAPPING_SEG_GROUP);
}

public static boolean hasUnbranchedNonOverlappingInfo(Cell cell)
@Deprecated
public static boolean hasUnbranchedNonOverlappingInfo(Cell cell) throws NeuroMLException
{
for (SegmentGroup sg : cell.getMorphology().getSegmentGroup())
return hasUnbranchedNonOverlappingInfo(cell, null);
}

public static boolean hasUnbranchedNonOverlappingInfo(Cell cell, NeuroMLDocument nml2doc) throws NeuroMLException {

Morphology morphology = getCellMorphology(cell, nml2doc);
for (SegmentGroup sg : morphology.getSegmentGroup())
{
if (isUnbranchedNonOverlapping(sg))
{
Expand All @@ -44,6 +53,49 @@ public static boolean hasUnbranchedNonOverlappingInfo(Cell cell)
return false;
}

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

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;
}
throw new NeuroMLException("Cannot find morphology: "+cell.getMorphologyAttr()+" specified as an attribute in cell: "+cell.getId());
}
else if (nml2doc==null)
{
return null;
// Cannot get any morphology attribute
}
return null; // may be expected...
}

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;
}

/**
* @deprecated use getIdsVsSegments(Cell cell, NeuroMLDocument nml2doc) instead.
*/
@Deprecated
public static LinkedHashMap<Integer, Segment> getIdsVsSegments(Cell cell) {

LinkedHashMap<Integer, Segment> idsVsSegments = new LinkedHashMap<Integer, Segment>();
Expand All @@ -53,6 +105,16 @@ public static LinkedHashMap<Integer, Segment> getIdsVsSegments(Cell cell) {
return idsVsSegments;
}

public static LinkedHashMap<Integer, Segment> getIdsVsSegments(Cell cell, NeuroMLDocument nml2doc) throws NeuroMLException {

LinkedHashMap<Integer, Segment> idsVsSegments = new LinkedHashMap<Integer, Segment>();
Morphology morphology = getCellMorphology(cell, nml2doc);
for (Segment seg : morphology.getSegment()) {
idsVsSegments.put(seg.getId(), seg);
}
return idsVsSegments;
}

public static SegmentGroup getSegmentGroup(Cell cell, String id) throws NeuroMLException {
for (SegmentGroup sg: cell.getMorphology().getSegmentGroup()) {
if (sg.getId().equals(id))
Expand All @@ -61,8 +123,13 @@ public static SegmentGroup getSegmentGroup(Cell cell, String id) throws NeuroMLE
throw new NeuroMLException("No SegmentGroup with id: "+id+" in cell with id: "+cell.getId());
}

@Deprecated
public static Segment getSegmentWithId(Cell cell, int segmentId) throws NeuroMLException {
List<Segment> segments = cell.getMorphology().getSegment();
return getSegmentWithId(cell, null, segmentId);
}

public static Segment getSegmentWithId(Cell cell, NeuroMLDocument nml2doc, int segmentId) throws NeuroMLException {
List<Segment> segments = getCellMorphology(cell, nml2doc).getSegment();
if (segments.size()>segmentId) {
Segment guess = segments.get(segmentId);
if (guess.getId()==segmentId)
Expand All @@ -75,16 +142,21 @@ public static Segment getSegmentWithId(Cell cell, int segmentId) throws NeuroMLE
throw new NeuroMLException("No Segment with id: "+segmentId+" in cell with id: "+cell.getId());
}

public static LinkedHashMap<String, SegmentGroup> getNamesVsSegmentGroups(Cell cell) {
public static LinkedHashMap<String, SegmentGroup> getNamesVsSegmentGroups(Cell cell, NeuroMLDocument nml2doc) throws NeuroMLException {

LinkedHashMap<String, SegmentGroup> namesVsSegmentGroups = new LinkedHashMap<String, SegmentGroup>();
for (SegmentGroup sg : cell.getMorphology().getSegmentGroup()) {
for (SegmentGroup sg : getCellMorphology(cell, nml2doc).getSegmentGroup()) {
namesVsSegmentGroups.put(sg.getId(), sg);
}
return namesVsSegmentGroups;
}

public static ArrayList<Integer> getSegmentIdsInGroup(Cell cell, String segmentGroup) {
public static LinkedHashMap<String, SegmentGroup> getNamesVsSegmentGroups(Cell cell) throws NeuroMLException {

return getNamesVsSegmentGroups(cell, null);
}

public static ArrayList<Integer> getSegmentIdsInGroup(Cell cell, String segmentGroup) throws NeuroMLException {

for (SegmentGroup sg : cell.getMorphology().getSegmentGroup()) {
if (sg.getId().equals(segmentGroup)) {
Expand Down Expand Up @@ -121,34 +193,45 @@ public static boolean hasSegmentGroup(Cell cell, String segmentGroup) {
return false;
}

@Deprecated
public static ArrayList<Segment> getSegmentsInGroup(Cell cell, String segmentGroup) throws NeuroMLException {
return getSegmentsInGroup(cell, null, segmentGroup);
}

for (SegmentGroup sg : cell.getMorphology().getSegmentGroup()) {
public static ArrayList<Segment> getSegmentsInGroup(Cell cell, NeuroMLDocument nml2doc, String segmentGroup) throws NeuroMLException {

for (SegmentGroup sg : CellUtils.getCellMorphology(cell, nml2doc).getSegmentGroup()) {
if (sg.getId().equals(segmentGroup)) {
LinkedHashMap<String, SegmentGroup> namesVsSegmentGroups = getNamesVsSegmentGroups(cell);
return getSegmentsInGroup(cell, namesVsSegmentGroups, sg);
LinkedHashMap<String, SegmentGroup> namesVsSegmentGroups = getNamesVsSegmentGroups(cell, nml2doc);
return getSegmentsInGroup(cell, nml2doc, namesVsSegmentGroups, sg);
}
}
throw new NeuroMLException("No SegmentGroup: "+segmentGroup+" in cell with id: "+cell.getId());
}


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

return getSegmentsInGroup(cell, null, namesVsSegmentGroups, segmentGroup);
}

public static ArrayList<Segment> getSegmentsInGroup(Cell cell, NeuroMLDocument nml2doc, LinkedHashMap<String, SegmentGroup> namesVsSegmentGroups, SegmentGroup segmentGroup) throws NeuroMLException {

ArrayList<Segment> segsHere = new ArrayList<Segment>();

for (Member memb : segmentGroup.getMember()) {
segsHere.add(getSegmentWithId(cell, memb.getSegment()));
segsHere.add(getSegmentWithId(cell, nml2doc, memb.getSegment()));
}
for (Include inc : segmentGroup.getInclude()) {
String sg = inc.getSegmentGroup();
ArrayList<Segment> segs = getSegmentsInGroup(cell, namesVsSegmentGroups, namesVsSegmentGroups.get(sg));
ArrayList<Segment> segs = getSegmentsInGroup(cell, nml2doc, namesVsSegmentGroups, namesVsSegmentGroups.get(sg));
segsHere.addAll(segs);
}

return segsHere;
}

public static LinkedHashMap<SegmentGroup, ArrayList<Integer>> getSegmentGroupsVsSegIds(Cell cell) {
public static LinkedHashMap<SegmentGroup, ArrayList<Integer>> getSegmentGroupsVsSegIds(Cell cell) throws NeuroMLException {

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

Expand All @@ -162,13 +245,33 @@ public static LinkedHashMap<SegmentGroup, ArrayList<Integer>> getSegmentGroupsVs
return sgVsSegId;
}

public static LinkedHashMap<SegmentGroup, ArrayList<Integer>> getSegmentGroupsVsSegIds(Cell cell, NeuroMLDocument nml2doc) throws NeuroMLException {

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

Morphology morphology = getCellMorphology(cell, nml2doc);

LinkedHashMap<String, SegmentGroup> namesVsSegmentGroups = getNamesVsSegmentGroups(cell, nml2doc);

for (SegmentGroup sg : morphology.getSegmentGroup()) {
ArrayList<Integer> segsHere = getSegmentIdsInGroup(namesVsSegmentGroups, sg);
sgVsSegId.put(sg, segsHere);
}

return sgVsSegId;
}

public static double distance(Point3DWithDiam p, Point3DWithDiam d) {
return Math.sqrt( Math.pow(p.getX()-d.getX(),2) + Math.pow(p.getY()-d.getY(),2) + Math.pow(p.getZ()-d.getZ(),2) );
}

public static double getFractionAlongSegGroupLength(Cell cell, String segmentGroup, int segmentId, float fractAlongSegment) throws NeuroMLException {
return getFractionAlongSegGroupLength(cell, null, segmentGroup, segmentId, fractAlongSegment);
}

public static double getFractionAlongSegGroupLength(Cell cell, NeuroMLDocument nml2doc, String segmentGroup, int segmentId, float fractAlongSegment) throws NeuroMLException {

ArrayList<Segment> segs = getSegmentsInGroup(cell, segmentGroup);
ArrayList<Segment> segs = getSegmentsInGroup(cell, nml2doc, segmentGroup);
if (segs.size()==1)
{
if(segs.get(0).getId()!=segmentId)
Expand Down Expand Up @@ -235,30 +338,45 @@ public static double getFractionAlongSegGroupLength(Cell cell, String segmentGro

public static void main(String[] args) throws Exception {
NeuroMLConverter conv = new NeuroMLConverter();
//String test = "/home/padraig/neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/bask.cell.nml";


ArrayList<String> cellFiles = new ArrayList<String>();
cellFiles.add("../neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/bask.cell.nml");
//String test = "/home/padraig/neuroConstruct/osb/hippocampus/networks/nc_superdeep/neuroConstruct/generatedNeuroML2/pvbasketcell.cell.nml";
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";
cellFiles.add("../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));

Cell cell = nml2.getCell().get(0);
System.out.println("cell: " + cell.getId());
cellFiles.add("../git/morphology_include/pyr_soma_m_out_b_in.cell.nml");

LinkedHashMap<Integer, Segment> ids = getIdsVsSegments(cell);
for(String cellFile : cellFiles)
{
NeuroMLDocument nml2doc = conv.loadNeuroML(new File(cellFile), true, true);

System.out.println("getIdsVsSegments: ");
for (Integer id: ids.keySet()) {
System.out.println("ID "+id+": "+ids.get(id));
}
Cell cell = nml2doc.getCell().get(0);
System.out.println("-------- Cell loaded: " + cell.getId()+" from "+cellFile);

LinkedHashMap<SegmentGroup, ArrayList<Integer>> sgVsSegId = getSegmentGroupsVsSegIds(cell);
for (SegmentGroup sg: sgVsSegId.keySet()) {
System.out.println("SG "+sg.getId()+": "+sgVsSegId.get(sg));
LinkedHashMap<Integer, Segment> ids = getIdsVsSegments(cell, nml2doc);

System.out.println("getIdsVsSegments: ");
for (Integer id: ids.keySet()) {
System.out.println("ID "+id+": "+ids.get(id));
}

System.out.println("hasUnbranchedNonOverlappingInfo: "+hasUnbranchedNonOverlappingInfo(cell, nml2doc));
System.out.println("getSegmentWithId: "+getSegmentWithId(cell, nml2doc, 0));

System.out.println("getSegmentsInGroup: "+getSegmentsInGroup(cell, nml2doc, "soma_group"));

System.out.println("getFractionAlongSegGroupLength: "+getFractionAlongSegGroupLength(cell, nml2doc, "soma_group", 0, 0.1f));

LinkedHashMap<SegmentGroup, ArrayList<Integer>> sgVsSegId = getSegmentGroupsVsSegIds(cell, nml2doc);
for (SegmentGroup sg: sgVsSegId.keySet()) {
System.out.println("SG "+sg.getId()+": "+sgVsSegId.get(sg));
}
//getFractionAlongSegGroupLength(cell, "basal2", 8, 0.1f);
//getFractionAlongSegGroupLength(cell, "some_apicals", 2, 0.5f);
}
getFractionAlongSegGroupLength(cell, "soma_group", 0, 0.1f);
//getFractionAlongSegGroupLength(cell, "basal2", 8, 0.1f);
//getFractionAlongSegGroupLength(cell, "some_apicals", 2, 0.5f);

}

Expand Down
Loading