Skip to content

Commit 6145bd5

Browse files
committed
computation-server: Return positions of neurons for a given worm pose on a given frame
1 parent 860d2f1 commit 6145bd5

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

computation-server.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/python
22
# 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.
44
#
55
# Usage:
66
# ./computation-server.py ../lightsheet/
@@ -19,6 +19,11 @@
1919
# HTTP path.
2020
lightsheet_dir = "../lightsheet/"
2121

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+
2227
http_port = 8002
2328

2429

@@ -81,6 +86,34 @@ def of_all(self, box, wholenorm = 0, chnorm = 0):
8186
return values
8287

8388

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+
84117
from flask import *
85118
from functools import update_wrapper
86119
app = Flask(__name__)
@@ -136,6 +169,13 @@ def box_intensity(filename, channel, boxcoords):
136169
chnorm = request.args.has_key('chnorm')
137170
)})
138171

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+
139179
if __name__ == '__main__':
140180
# app.run(port = http_port)
141181
app.run(port = http_port, debug = True)

0 commit comments

Comments
 (0)