|
1 | 1 | #!/usr/bin/python
|
2 | 2 | # This is a simple HTTP server that provides an API for various computations
|
3 |
| -# on the HDF5 data files. |
| 3 | +# performed on the server side. |
4 | 4 | #
|
5 | 5 | # Usage:
|
6 | 6 | # ./computation-server.py ../lightsheet/
|
|
19 | 19 | # HTTP path.
|
20 | 20 | lightsheet_dir = "../lightsheet/"
|
21 | 21 |
|
| 22 | +# Directory with JSON backbone data |
| 23 | +backbone_data_dir = "meteor/data/" |
| 24 | +# Neuron position data - either .json file or a directory with .nml files |
| 25 | +neurons_data = "meteor/data/neurons.json" |
| 26 | + |
22 | 27 | http_port = 8002
|
23 | 28 |
|
24 | 29 |
|
@@ -81,6 +86,34 @@ def of_all(self, box, wholenorm = 0, chnorm = 0):
|
81 | 86 | return values
|
82 | 87 |
|
83 | 88 |
|
| 89 | +import poselib |
| 90 | +import nmllib |
| 91 | + |
| 92 | +class NeuronPositions: |
| 93 | + """ |
| 94 | + List of neuron positions corresponding to a given worm pose and backbone. |
| 95 | + """ |
| 96 | + def __init__(self, hdf5file, frameno): |
| 97 | + bbfilename = backbone_data_dir + hdf5file + '-' + str(frameno) + '-backbone.json' |
| 98 | + (points, edgedists) = poselib.bbLoad(bbfilename) |
| 99 | + (spline, bblength) = poselib.bbToSpline(points) |
| 100 | + self.bbpoints = poselib.bbTraceSpline(spline, bblength) |
| 101 | + |
| 102 | + def neurons_by_pose(self, poseinfo): |
| 103 | + pneurons = [] |
| 104 | + for n in self.neurons: |
| 105 | + pn_pos = poselib.projTranslateByBb(poselib.projCoord(n["pos"], poseinfo), self.bbpoints, n["name"], poseinfo) |
| 106 | + if pn_pos is None: |
| 107 | + continue |
| 108 | + pn = n.copy() |
| 109 | + pn["pos"] = pn_pos |
| 110 | + pn["diameter"] = poselib.projDiameter(n["diameter"], poseinfo) |
| 111 | + pneurons.append(pn) |
| 112 | + return pneurons |
| 113 | + |
| 114 | + neurons = nmllib.load_neurons(neurons_data) |
| 115 | + |
| 116 | + |
84 | 117 | from flask import *
|
85 | 118 | from functools import update_wrapper
|
86 | 119 | app = Flask(__name__)
|
@@ -136,6 +169,13 @@ def box_intensity(filename, channel, boxcoords):
|
136 | 169 | chnorm = request.args.has_key('chnorm')
|
137 | 170 | )})
|
138 | 171 |
|
| 172 | +@app.route('/<string:filename>/neuron-positions/<int:frameno>/<string:poseinfo_s>') |
| 173 | +@crossdomain(origin='*') |
| 174 | +def neuron_positions(filename, frameno, poseinfo_s): |
| 175 | + npos = NeuronPositions(filename, frameno) |
| 176 | + poseinfo = dict(zip(["zoom", "shift", "angle"], [float(f) for f in poseinfo_s.split(',')])) |
| 177 | + return nmllib.jsondump_neurons(npos.neurons_by_pose(poseinfo)) |
| 178 | + |
139 | 179 | if __name__ == '__main__':
|
140 | 180 | # app.run(port = http_port)
|
141 | 181 | app.run(port = http_port, debug = True)
|
0 commit comments