Skip to content

Commit 0c874e9

Browse files
committed
Adding annotations
1 parent e23adb6 commit 0c874e9

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

catmaid_interface.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ def get_catmaid_url( proj_opts, xyz, nodeid=None, skid=None, tool='tracingtool',
4343
strs = [baseurl,pid_str,x_str,y_str,z_str,tool_str,sid_str,zoom_str]
4444
return '&'.join(strs)
4545

46-
47-
48-
49-
50-
5146
# get_neuron_name: Given a skeleton ID, fetch the neuron name
5247
def get_neuron_name( skeleton_id, proj_opts ):
5348
url = proj_opts['baseurl'] + '/{}/skeleton/{}/neuronname'.format( proj_opts['project_id'], skeleton_id)
@@ -210,7 +205,13 @@ def get_skeleton_statistics( skid, proj_opts ):
210205
d = requests.get( url, auth = catmaid_auth_token( proj_opts['token'], proj_opts['authname'], proj_opts['authpass'] ) ).json()
211206
return d
212207

213-
#######
208+
def get_annotations( skid_list, proj_opts ):
209+
url = proj_opts['baseurl'] + '/{}/annotations/forskeletons'.format( proj_opts['project_id'] )
210+
opts = {}
211+
for i, id in enumerate( skid_list ):
212+
opts['skeleton_ids[{}]'.format(i)] = id
213+
d = requests.post( url, data = opts, auth = catmaid_auth_token( proj_opts['token'], proj_opts['authname'], proj_opts['authpass'] ) ).json()
214+
return d
214215

215216
# Parse a file to a list of skeleton ids.
216217
def import_ids(filename):

neuron_analytics.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def neuron_graph(id_list, proj_opts):
2222

2323
return g
2424

25-
2625
def neuron_graph_from_annotations(annotation_list, proj_opts, anno_dict=None, append_annotations=True):
2726
# Build a neuron graph from a readable list of annotation strings
2827
if anno_dict is None:
@@ -44,7 +43,6 @@ def neuron_graph_from_annotations(annotation_list, proj_opts, anno_dict=None, ap
4443

4544
return g
4645

47-
4846
def append_annotation_list(g, annotation_list, proj_opts, anno_dict=None):
4947
# Given a list of annotations (as a string), add a node property to each
5048
# skeleton containing which annotations they have
@@ -65,7 +63,6 @@ def append_annotation_list(g, annotation_list, proj_opts, anno_dict=None):
6563
print('Not a valid key: ' + anno + ' (skipping)')
6664
return g
6765

68-
6966
def write_node_info(g, filename, delimiter=','):
7067
f_nodeinfo = open(filename, 'w')
7168
for id, node in g.nodes_iter(data=True):
@@ -257,6 +254,16 @@ def __init__(self, conn_ids, proj_opts ):
257254
conndata = ci.get_connector_data( post_conn_ids, proj_opts )
258255
self.connectors = { dat[0] : dat[1] for dat in conndata }
259256

257+
def annotations_from_neurons( neurons, proj_opts ):
258+
anno_dat = ci.get_annotations( [nrn.id for nrn in neurons], proj_opts )
259+
anno_dict = {}
260+
for anno_id in anno_dat['annotations']:
261+
anno_dict[ int(anno_id) ] = {'str' : anno_dat['annotations'][anno_id], 'skids': [] }
262+
for skid in anno_dat['skeletons']:
263+
for anno_info in anno_dat['skeletons'][skid]:
264+
anno_dict[ anno_info['id'] ][ 'skids' ].append( int(skid) )
265+
return anno_dict
266+
260267
def neurons_from_annotations( annotation_list, proj_opts ):
261268
anno_dict = ci.get_annotation_dict( proj_opts )
262269
id_list = ci.get_ids_from_annotation( [anno_dict[anno] for anno in annotation_list], proj_opts )
@@ -266,16 +273,15 @@ def neurons_from_annotations( annotation_list, proj_opts ):
266273
def neurons_from_id_list(id_list, proj_opts ):
267274
# Given a list of ids, build a list of NeuronObjs
268275
# associated with them, if one is already pre-existing
269-
neurons = [NeuronObj(id, proj_opts) for id in id_list]
276+
neurons = { id : NeuronObj(id, proj_opts) for id in id_list}
270277
return neurons
271278

272279
def get_adjacency_matrix( neurons, input_normalized = False ):
273280
# Build a weighted adjacency matrix from neurons
274281
A = np.zeros( (len(neurons), len(neurons)) )
275-
skid_to_ind = { skid:ii for ii, skid in enumerate([nrn.id for nrn in neurons])}
276-
ind_to_skid = { ii:skid for ii, skid in enumerate([nrn.id for nrn in neurons])}
277-
ids = [nrn.id for nrn in neurons]
278-
for nrn in neurons:
282+
skid_to_ind = { skid:ii for ii, skid in enumerate(neurons) }
283+
ind_to_skid = { ii:skid for ii, skid in enumerate(neurons)}
284+
for nrn in neurons.values():
279285
for conn_id in nrn.outputs.target_ids:
280286
for targ in nrn.outputs.target_ids[conn_id]:
281287
if targ in ids:
@@ -308,7 +314,7 @@ def find_ids_by_name( neurons, name_pattern ):
308314
ids_found = []
309315
return [ nrn.id for nrn in neurons if re.search(name_pattern, nrn.name) is not None ]
310316

311-
def number_inputs( neurons ):
317+
def number_ginputs( neurons ):
312318
return [nrn.inputs.num() for nrn in neurons]
313319

314320
def number_outputs( neurons ):

0 commit comments

Comments
 (0)