Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method replicating skeleton export #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions catmaid_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,55 @@ def get_skeleton_json( skeleton_id, proj_opts, withtags = True):
d.append([])
return d

def get_treenode_and_connector_geometry(skeleton_id, proj_opts):
"""
See CATMAID code for original js implementation:
http://github.com/catmaid/CATMAID/blob/master/django/applications/catmaid/static/js/widgets/export-widget.js#L449

Parameters
----------
skeleton_id
proj_opts

Returns
-------
dict
dict of the same form as the JSON file used by the 'Treenode and connector geometry' option in the CATMAID
Export widget.
"""
url = proj_opts['baseurl'] + '/{}/{}/1/0/compact-skeleton'.format( proj_opts['project_id'], skeleton_id)
data = requests.get(
url, auth=catmaid_auth_token(proj_opts['token'], proj_opts['authname'], proj_opts['authpass'])
).json()

skeleton = {
'treenodes': dict(),
'connectors': dict()
}

for treenode in data[0]:
skeleton['treenodes'][treenode[0]] = {
'location': treenode[3:6],
'parent_id': treenode[1]
}

for connector in data[1]:
if connector[2] not in [0, 1]:
continue

conn_id = connector[1]
if conn_id not in skeleton['connectors']:
skeleton['connectors'][conn_id] = {
'presynaptic_to': [],
'postsynaptic_to': []
}

skeleton['connectors'][conn_id]['location'] = connector[3:6]
relation = 'postsynaptic_to' if connector[2] == 1 else 'presynaptic_to'
skeleton['connectors'][conn_id][relation].append(connector[0])

return skeleton

def get_connector_info( connector_id, proj_opts):
url = proj_opts['baseurl'] + '/{}/connectors/{}/'.format( proj_opts['project_id'], connector_id )
d = requests.get( url, auth = catmaid_auth_token( proj_opts['token'], proj_opts['authname'], proj_opts['authpass'] ) ).json()
Expand Down