def createMorphoMlFile(fileName, cell): ''' Convert to new neuroml structures and write ''' if not muscle_dict.has_key(cell.name): neuroMlwriter = NeuroMlWriter(fileName, cell.name) neuroMlwriter.addCell(cell) neuroMlwriter.writeDocumentToFile() return # # Incomplete code to use the neuroml interface to write the file, # used for muscles, doesn't produce good enough result on neurons yet. # seg0 = cell.segments[0].position soma = Segment(proximal=cvt_pt(seg0.proximal_point), distal=cvt_pt(seg0.distal_point)) soma.name = 'Soma' soma.id = 0 axon_segments = [] for seg1 in cell.segments[1:]: parent = SegmentParent(segments=seg1.parent) if seg1.position.proximal_point is None: p = None else: p = cvt_pt(seg1.position.proximal_point) axon_segment = Segment(proximal = p, distal = cvt_pt(seg1.position.distal_point), parent = parent) axon_segment.id = seg1.id axon_segment.name = seg1.name axon_segments.append(axon_segment) morphology = Morphology() morphology.segments.append(soma) morphology.segments += axon_segments morphology.id = 'morphology_' + cell.name nml_cell = neuroml_Cell() nml_cell.id = cell.name nml_cell.morphology = morphology doc = NeuroMLDocument() doc.cells.append(nml_cell) #addCell(doc, cell) doc.id = "TestNeuroMLDocument" writers.NeuroMLWriter.write(doc, "Output/%s.nml" % fileName)
def createMorphoMlFile(fileName, cell): ''' Convert to new neuroml structures and write ''' if not muscle_dict.has_key(cell.name): neuroMlwriter = NeuroMlWriter(fileName, cell.name) neuroMlwriter.addCell(cell) neuroMlwriter.writeDocumentToFile() return # # Incomplete code to use the neuroml interface to write the file, # used for muscles, doesn't produce good enough result on neurons yet. # seg0 = cell.segments[0].position soma = Segment(proximal=cvt_pt(seg0.proximal_point), distal=cvt_pt(seg0.distal_point)) soma.name = 'Soma' soma.id = 0 axon_segments = [] for seg1 in cell.segments[1:]: parent = SegmentParent(segments=seg1.parent) if seg1.position.proximal_point is None: p = None else: p = cvt_pt(seg1.position.proximal_point) axon_segment = Segment(proximal=p, distal=cvt_pt(seg1.position.distal_point), parent=parent) axon_segment.id = seg1.id axon_segment.name = seg1.name axon_segments.append(axon_segment) morphology = Morphology() morphology.segments.append(soma) morphology.segments += axon_segments morphology.id = 'morphology_' + cell.name nml_cell = neuroml_Cell() nml_cell.id = cell.name nml_cell.morphology = morphology doc = NeuroMLDocument() doc.cells.append(nml_cell) #addCell(doc, cell) doc.id = "TestNeuroMLDocument" writers.NeuroMLWriter.write(doc, "Output/%s.nml" % fileName)
def createMorphoMlFile(fileName, cell): ''' Convert to new neuroml structures and write ''' seg0 = cell.segments[0].position soma = Segment(proximal=cvt_pt(seg0.proximal_point), distal=cvt_pt(seg0.distal_point)) soma.name = 'Soma' soma.id = 0 axon_segments = [] for seg1 in cell.segments[1:]: parent = SegmentParent(segments=seg1.parent) if seg1.position.distal_point is None: p = None else: p = cvt_pt(seg1.position.distal_point) axon_segment = Segment(proximal=p, distal=cvt_pt(seg1.position.distal_point), parent=parent) axon_segment.id = seg1.id axon_segment.name = seg1.name axon_segments.append(axon_segment) morphology = Morphology() morphology.segments.append(soma) morphology.segments += axon_segments morphology.id = 'morphology_' + cell.name nml_cell = neuroml_Cell() nml_cell.id = cell.name nml_cell.morphology = morphology doc = NeuroMLDocument() #doc.name = "Test neuroML document" doc.cells.append(nml_cell) doc.id = fileName writers.NeuroMLWriter.write(doc, "Output/%s.nml" % fileName)
def createMorphoMlFile(fileName, cell): ''' Convert to new neuroml structures and write ''' seg0 = cell.segments[0].position soma = Segment(proximal=cvt_pt(seg0.proximal_point), distal=cvt_pt(seg0.distal_point)) soma.name = 'Soma' soma.id = 0 axon_segments = [] for seg1 in cell.segments[1:]: parent = SegmentParent(segments=seg1.parent) if seg1.position.distal_point is None: p = None else: p = cvt_pt(seg1.position.distal_point) axon_segment = Segment(proximal = p, distal = cvt_pt(seg1.position.distal_point), parent = parent) axon_segment.id = seg1.id axon_segment.name = seg1.name axon_segments.append(axon_segment) morphology = Morphology() morphology.segments.append(soma) morphology.segments += axon_segments morphology.id = 'morphology_' + cell.name nml_cell = neuroml_Cell() nml_cell.id = cell.name nml_cell.morphology = morphology doc = NeuroMLDocument() #doc.name = "Test neuroML document" doc.cells.append(nml_cell) doc.id = fileName writers.NeuroMLWriter.write(doc, "Output/%s.nml" % fileName)
def neuroml_single_cell(skeleton_id, nodes, pre, post): """ Encapsulate a single skeleton into a NeuroML Cell instance. skeleton_id: the ID of the skeleton to which all nodes belong. nodes: a dictionary of node ID vs tuple of node parent ID, location as a tuple of 3 floats, and radius. In nanometers. pre: a dictionary of node ID vs list of connector ID post: a dictionary of node ID vs list of connector ID Returns a Cell with id=skeleton_id. """ # Collect the children of every node successors = defaultdict(list) # parent node ID vs list of children node IDs rootID = None for nodeID, props in nodes.iteritems(): parentID = props[0] if not parentID: rootID = nodeID continue successors[parentID].append(nodeID) # Cache of Point3DWithDiam points = {} def asPoint(nodeID): """ Return the node as a Point3DWithDiam, in micrometers. """ p = points.get(nodeID) if not p: props = nodes[nodeID] radius = props[2] if radius < 0: radius = 0.1 # FUTURE Will have to change loc = props[1] # Point in micrometers p = Point3DWithDiam(loc[0] / 1000.0, loc[1] / 1000.0, loc[2] / 1000.0, radius) points[nodeID] = p return p # Starting from the root node, iterate towards the end nodes, adding a segment # for each parent-child pair. segments = [] segment_id = 1 todo = [rootID] # VERY CONFUSINGLY, the Segment.parent is a SegmentParent with the same id as the parent Segment. An unseemly overheady way to reference the parent Segment. while todo: nodeID = todo.pop() children = successors[nodeID] if not children: continue p1 = asPoint(nodeID) parent = segments[-1] if segments else None segment_parent = SegmentParent(segments=parent.id) if parent else None for childID in children: p2 = asPoint(childID) segment_id += 1 segment = Segment(proximal=p1, distal=p2, parent=segment_parent) segment.id = segment_id segment.name = "%s-%s" % (nodeID, childID) segments.append(segment) todo.append(childID) # Pack the segments into a Cell morphology = Morphology() morphology.segments.extend(segments) morphology.id = "Skeleton #%s" % skeleton_id # Synapses: TODO requires input from Padraig Gleeson cell = Cell() cell.name = 'Cell' cell.id = skeleton_id cell.morphology = morphology return cell
def neuroml_single_cell(skeleton_id, nodes, pre, post): """ Encapsulate a single skeleton into a NeuroML Cell instance. skeleton_id: the ID of the skeleton to which all nodes belong. nodes: a dictionary of node ID vs tuple of node parent ID, location as a tuple of 3 floats, and radius. In nanometers. pre: a dictionary of node ID vs list of connector ID post: a dictionary of node ID vs list of connector ID Returns a Cell with id=skeleton_id. """ # Collect the children of every node successors = defaultdict( list) # parent node ID vs list of children node IDs rootID = None for nodeID, props in nodes.iteritems(): parentID = props[0] if not parentID: rootID = nodeID continue successors[parentID].append(nodeID) # Cache of Point3DWithDiam points = {} def asPoint(nodeID): """ Return the node as a Point3DWithDiam, in micrometers. """ p = points.get(nodeID) if not p: props = nodes[nodeID] radius = props[2] if radius < 0: radius = 0.1 # FUTURE Will have to change loc = props[1] # Point in micrometers p = Point3DWithDiam(loc[0] / 1000.0, loc[1] / 1000.0, loc[2] / 1000.0, radius) points[nodeID] = p return p # Starting from the root node, iterate towards the end nodes, adding a segment # for each parent-child pair. segments = [] segment_id = 1 todo = [rootID] # VERY CONFUSINGLY, the Segment.parent is a SegmentParent with the same id as the parent Segment. An unseemly overheady way to reference the parent Segment. while todo: nodeID = todo.pop() children = successors[nodeID] if not children: continue p1 = asPoint(nodeID) parent = segments[-1] if segments else None segment_parent = SegmentParent(segments=parent.id) if parent else None for childID in children: p2 = asPoint(childID) segment_id += 1 segment = Segment(proximal=p1, distal=p2, parent=segment_parent) segment.id = segment_id segment.name = "%s-%s" % (nodeID, childID) segments.append(segment) todo.append(childID) # Pack the segments into a Cell morphology = Morphology() morphology.segments.extend(segments) morphology.id = "Skeleton #%s" % skeleton_id # Synapses: TODO requires input from Padraig Gleeson cell = Cell() cell.name = 'Cell' cell.id = skeleton_id cell.morphology = morphology return cell