Skip to content

Commit

Permalink
Make sure to always pull neuron ID from server
Browse files Browse the repository at this point in the history
- and use neurons/from-models to query multiple IDs at once
  • Loading branch information
schlegelp committed Apr 9, 2019
2 parents ad8abd0 + 82831b9 commit 8327f05
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
52 changes: 36 additions & 16 deletions pymaid/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,19 @@ def _get_skeletons_in_bbox(self, **GET):
""" Use to get list of skeleton in bounding box. Does need postdata.
"""
return self.make_url(self.project_id, 'skeletons', 'in-bounding-box',
**GET)
**GET)

def _get_connector_in_bbox_url(self, **GET):
""" Use to parse url for retrieving list of connectors in bounding
box (can use GET or POST).
"""
return self.make_url(self.project_id, 'connectors', 'in-bounding-box', **GET)

def _get_neuron_ids_url(self, **GET):
""" Use to parse url for retrieving neuron IDs for a bunch of skeleton
IDs.
"""
return self.make_url(self.project_id, 'neurons', 'from-models', **GET)


@cache.undo_on_error
Expand Down Expand Up @@ -2416,10 +2428,12 @@ def remove_annotations(x, annotations, remote_instance=None):

remove_annotations_postdata = {}

for i in range(len(x)):
# This requires neuron IDs (skeleton ID + 1)
neuron_ids = get_neuron_id(x, remote_instance=remote_instance)

for i, s in enumerate(len(x)):
# This requires neuron IDs
key = 'entity_ids[%i]' % i
remove_annotations_postdata[key] = str(int(x[i]) + 1)
remove_annotations_postdata[key] = neuron_ids[str(s)]

for i in range(len(an_ids)):
key = 'annotation_ids[%i]' % i
Expand Down Expand Up @@ -2488,9 +2502,11 @@ def add_annotations(x, annotations, remote_instance=None):

add_annotations_postdata = {}

for i in range(len(x)):
neuron_ids = get_neuron_id(x, remote_instance=remote_instance)

for i, s in enumerate(len(x)):
key = 'entity_ids[%i]' % i
add_annotations_postdata[key] = str(int(x[i]) + 1)
add_annotations_postdata[key] = neuron_ids[str(s)]

for i in range(len(annotations)):
key = 'annotations[%i]' % i
Expand Down Expand Up @@ -2753,13 +2769,14 @@ def get_annotation_details(x, remote_instance=None):
# neuron_id can be requested via neuron_names
url_list = list()
postdata = list()
neuron_ids = get_neuron_id(skids, remote_instance=remote_instance)

for s in skids:
remote_get_neuron_name = remote_instance._get_single_neuronname_url(s)
neuronid = remote_instance.fetch(remote_get_neuron_name)['neuronid']
nid = neuron_ids.get(str(s))

url_list.append(remote_instance._get_annotation_table_url())
postdata.append(dict(neuron_id=int(neuronid)))
postdata.append(dict(neuron_id=int(nid)))

# Get data
annotations = [e['aaData'] for e in remote_instance.fetch(
Expand Down Expand Up @@ -5465,12 +5482,11 @@ def rename_neurons(x, new_names, remote_instance=None, no_prompt=False):

url_list = []
postdata = []
neuron_ids = get_neuron_id(x, remote_instance=remote_instance)
for skid, name in zip(x, new_names):
# Renaming works with neuron ID, which we can get via this API endpoint
remote_get_neuron_name = remote_instance._get_single_neuronname_url(
skid)
neuron_id = remote_instance.fetch(remote_get_neuron_name)['neuronid']
url_list.append(remote_instance._rename_neuron_url(neuron_id))
nid = neuron_ids[str(skid)]
url_list.append(remote_instance._rename_neuron_url(nid))
postdata.append({'name': name})

# Get data
Expand Down Expand Up @@ -5848,16 +5864,20 @@ def get_neuron_id(x, remote_instance=None):
Returns
-------
dict
``{skeleton_id: neuron_id, ... }``
``{skeleton_id (str): neuron_id (int), ... }``
"""

remote_instance = utils._eval_remote_instance(remote_instance)

skids = utils.eval_skids(x, remote_instance=remote_instance)

urls = [remote_instance._get_single_neuronname_url(s) for s in skids]
url = remote_instance._get_neuron_ids_url()
post = {'model_ids[{}]'.format(i): s for i, s in enumerate(skids)}

resp = remote_instance.fetch(url, post=post)

return resp


resp = remote_instance.fetch(urls)

return {s: n.get('neuronid', n) for s, n in zip(skids, resp)}
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ networkx==2.2
pandas==0.24.1
plotly==3.7.1
pypng==0.0.18
pyqt5==5.11.3
pyqt5==5.12.1
requests_futures==0.9.9
requests==2.21.0
Shapely==1.6.4.post2
Expand Down

0 comments on commit 8327f05

Please sign in to comment.