Beispiel #1
0
            nInputs = len(incoming)
            nOutputs = len(outgoing)
            outgoingIds = [oc.getId() for oc in outgoing]
            incomingIds = [ic.getId() for ic in incoming]

            # get node connections, out/in synapse number, synapse id

            # get branch id
            if branchTable.has_key(nd):
                branch = branchTable[nd]
            else:
                branch = 0

            # get area
            ndArea = abs(
                AreaCalculations.area(nd.getData().getPathIterator(None)) *
                calibration.pixelWidth * calibration.pixelHeight)

            ndLayerIndex = nd.getLayer().getParent().indexOf(nd.getLayer()) + 1
            # save a line of node profile data
            # ['neuron', 'neurite', 'areatreeId', 'nodeId', 'branch', 'layer', 'x', 'y', 'z', 'area', 'nInputs', 'nOutputs', 'input', 'output']
            nodeData = [
                neurite.getParent().getTitle(),
                neurite.getTitle(),
                areatree.getId(),
                nd.getId(), branch, ndLayerIndex, x, y, z,
                nd.getNormalAngle(),
                nd.getCrossRadius(),
                nd.getFlatRadius(), nInputs, nOutputs, incomingIds, outgoingIds
            ]
            foundNeuriteNodes.append(nodeData)
        continue
    areatrees = neurite.findChildrenOfTypeR("areatree")
    for areatree in areatrees:
        areatree = areatree.getObject()
        root = areatree.getRoot()
        if root is None:
            continue

        nEmpty = 0
        nNodes = 0
        layerset = areatree.getLayerSet()
        calibration = layerset.getCalibration()
        affine = areatree.getAffineTransform()
        for nd in root.getSubtreeNodes():
            nNodes += 1
            ndArea = abs( AreaCalculations.area(nd.getData().getPathIterator(None)) )
            if ndArea < 1:
                nEmpty += 1
                fp = array([nd.getX(), nd.getY()], 'f')
                affine.transform(fp, 0, fp, 0, 1)
                x = fp[0]
                y = fp[1]
                notDrawnCo.append(Coordinate(x, y, nd.getLayer(), nd))
                notDrawn.append([nd.getLayer().getParent().indexOf(nd.getLayer()) + 1, neurite.getTitle(), nd.getId()])
        if nEmpty:
            print neurite.getTitle(), 'has ', nEmpty, '/', nNodes, 'nodes not drawn (area too small).'

outfile = open('notDrawn.csv','wb')
writer = csv.writer(outfile)
writer.writerows(notDrawn)
outfile.close()
            d = []
            for tnd in ndIn:
                d.append(MeasurePathDistance(areatree, nd, tnd).getDistance())
            ndOutDistance[nd] = min(d)

        # input synapses
        for nd, d in ndInDistance.iteritems():
            # get node coordinates, from tut on web
            fp = array([nd.getX(), nd.getY()], 'f')
            affine.transform(fp, 0, fp, 0, 1)
            x = fp[0] * calibration.pixelWidth
            y = fp[1] * calibration.pixelHeight
            z = nd.getLayer().getZ() * calibration.pixelWidth  # a TrakEM2 oddity

            # get area
            ndArea = abs( AreaCalculations.area( nd.getData().getPathIterator(None) ) * calibration.pixelWidth * calibration.pixelHeight )

            ndLayerIndex = nd.getLayer().getParent().indexOf(nd.getLayer()) + 1
            # save a line of node profile data
            # ['neuron', 'neurite', 'areatreeId', 'nodeId', 'synapseDirection', 'layer', 'x', 'y', 'z', 'area', 'distance']
            nodeData = [neurite.getParent().getTitle(), neurite.getTitle(), areatree.getId(), nd.getId(), 'incoming', ndLayerIndex, x, y, z, ndArea, d]
            foundNeuriteNodes.append(nodeData)

        # output synapses
        for nd, d in ndOutDistance.iteritems():
            # get node coordinates, from tut on web
            fp = array([nd.getX(), nd.getY()], 'f')
            affine.transform(fp, 0, fp, 0, 1)
            x = fp[0] * calibration.pixelWidth
            y = fp[1] * calibration.pixelHeight
            z = nd.getLayer().getZ() * calibration.pixelWidth  # a TrakEM2 oddity
                outputNeurites = [str(tnTable[t].getTitle()) for t in outs[nd]]
            if nd in ins:
                inputNeurites = [str(tnTable[t].getTitle()) for t in ins[nd]]

            # get node coordinates, from tut on web
            fp = array([nd.getX(), nd.getY()], 'f')
            affine.transform(fp, 0, fp, 0, 1)
            x = fp[0] * calibration.pixelWidth
            y = fp[1] * calibration.pixelHeight
            z = nd.getLayer().getZ() * calibration.pixelWidth  # a TrakEM2 oddity

            # get branch id
            if branchTable.has_key(nd):
                branch = branchTable[nd]
            else:
                branch = 0

            # get area
            ndArea = abs( AreaCalculations.area( nd.getData().getPathIterator(None) ) * calibration.pixelWidth * calibration.pixelHeight )

            ndLayerIndex = nd.getLayer().getParent().indexOf(nd.getLayer()) + 1
            # save a line of node profile data
            # ['neuron', 'neurite', 'areatreeId', 'nodeId', 'branch', 'layer', 'x', 'y', 'z', 'area', 'nSynapseInputs', 'nSynapseOutputs', 'inputNeurites', 'outputNeurites']
            nodeData = [neurite.getParent().getTitle(), neurite.getTitle(), areatree.getId(), nd.getId(), branch, ndLayerIndex, x, y, z, ndArea, nAutoIn, nAutoOut, inputNeurites, outputNeurites]
            foundNeuriteNodes.append(nodeData)

outfile = open('neuritesConnectors01.csv','wb')
writer = csv.writer(outfile)
writer.writerows(foundNeuriteNodes)
outfile.close()
projectRoot = project.getRootProjectThing()
output = [['lobe', 'Z', 'area']]

arealists = projectRoot.findChildrenOfTypeR("area_list")
for arealist in arealists:
    if re.match(r".*lobe", arealist.getTitle()) is None:
        continue
    arealist = arealist.getObject()
    layerset = arealist.getLayerSet()
    calibration = layerset.getCalibration()
    layers = arealist.getLayerRange()
    for layer in layers:
        area = arealist.getArea(layer)
        if area is None:
            A = 0
        else:
            A = abs(
                AreaCalculations.area(area.getPathIterator(None)) *
                calibration.pixelWidth * calibration.pixelHeight)

        output.append(
            [arealist.getTitle(),
             layer.getZ() * calibration.pixelWidth, A])

print 'writing ...'
outfile = open('area.lobes.csv', 'wb')
writer = csv.writer(outfile)
writer.writerows(output)
outfile.close()
print 'done.'
import re
import csv

project = Project.getProjects().get(0)
projectRoot = project.getRootProjectThing()
output = [['lobe', 'Z','area']]

arealists = projectRoot.findChildrenOfTypeR("area_list")
for arealist in arealists:
    if re.match(r".*lobe", arealist.getTitle()) is None:
        continue
    arealist = arealist.getObject()
    layerset = arealist.getLayerSet()
    calibration = layerset.getCalibration()
    layers = arealist.getLayerRange()
    for layer in layers:
        area = arealist.getArea(layer)
        if area is None:
            A = 0
        else:
            A = abs( AreaCalculations.area(area.getPathIterator(None) ) * calibration.pixelWidth * calibration.pixelHeight )
        
        output.append([arealist.getTitle(), layer.getZ()*calibration.pixelWidth, A])

print 'writing ...'
outfile = open('area.lobes.csv','wb')
writer = csv.writer(outfile)
writer.writerows(output)
outfile.close()
print 'done.'