catpy.applications package¶
Submodules¶
Module contents¶
-
class
catpy.applications.
CatmaidClientApplication
(catmaid_client)[source]¶ Bases:
catpy.client.AbstractCatmaidClient
An application which uses the CATMAID interface. Users should subclass this when creating their own applications.
Attributes: - base_url
- project_id
Methods
fetch
(*args, **kwargs)Interact with the CATMAID server in a manner very similar to the javascript CATMAID.fetch API. from_json
(credentials, *args, **kwargs)Return a CatmaidClientApplication instance whose underlying CatmaidClient object is instantiated from the JSON file as per its own from_json method. get
(relative_url[, params, raw])Get data from a running instance of CATMAID. post
(relative_url[, data, raw])Post data to a running instance of CATMAID. -
base_url
¶
-
fetch
(*args, **kwargs)¶ Interact with the CATMAID server in a manner very similar to the javascript CATMAID.fetch API.
Parameters: - relative_url : str or tuple of str
URL to send the request to, relative to the base_url. If a tuple is passed, its elements will be joined with ‘/’.
- method: {‘GET’, ‘POST’}, optional
HTTP method to use (the default is ‘GET’)
- data: dict or str, optional
JSON-like key/value data to be included in the request as a payload (defaults to empty)
- raw: bool, optional
Whether to return the response as a string regardless of its content-type (by default, JSON responses will be parsed)
- kwargs
Extra keyword arguments to pass to requests.Session.get/post(), depending on method
Returns: - dict or list or str
Data returned from CATMAID. JSON responses will be parsed unless raw is True; all other responses will be returned as strings.
-
classmethod
from_json
(credentials, *args, **kwargs)[source]¶ Return a CatmaidClientApplication instance whose underlying CatmaidClient object is instantiated from the JSON file as per its own from_json method.
Parameters: - path : str
Path to the JSON credentials file
- args, kwargs
Arguments passed to constructor of concrete subclass
Returns: - CatmaidClient
Instance of the API, authenticated with
-
project_id
¶
-
class
catpy.applications.
ExportWidget
(catmaid_client)[source]¶ Bases:
catpy.applications.base.CatmaidClientApplication
Attributes: - base_url
- project_id
Methods
fetch
(*args, **kwargs)Interact with the CATMAID server in a manner very similar to the javascript CATMAID.fetch API. from_json
(credentials, *args, **kwargs)Return a CatmaidClientApplication instance whose underlying CatmaidClient object is instantiated from the JSON file as per its own from_json method. get
(relative_url[, params, raw])Get data from a running instance of CATMAID. get_connector_archive
(*args, **kwargs)Not implemented: requires an async job get_networkx
(*skeleton_ids)Get a networkx MultiDiGraph of the given skeletons. get_networkx_dict
(*skeleton_ids)Get the data for a networkx graph of the given skeletons in node-link format. get_neuroml
(skeleton_ids[, skeleton_inputs])Get NeuroML v1.8.1 (level 3, NetworkML) for the given skeletons, possibly with their input synapses constrained to another set of skeletons. get_swc
(skeleton_id[, linearize_ids])Get a single skeleton in SWC format. get_treenode_and_connector_geometry
(…)Get the treenode and connector information for the given skeletons. get_treenode_archive
(*args, **kwargs)Not implemented: requires an async job post
(relative_url[, data, raw])Post data to a running instance of CATMAID. -
get_networkx
(*skeleton_ids)[source]¶ Get a networkx MultiDiGraph of the given skeletons.
Parameters: - skeleton_ids : array-like of (int or str)
Returns: - networkx.MultiDiGraph
-
get_networkx_dict
(*skeleton_ids)[source]¶ Get the data for a networkx graph of the given skeletons in node-link format.
In networkx 1.x, as used by CATMAID and therefore returned by this method, “source” and “target” in the dicts in “links” refer to nodes by their indices in the “nodes” array.
See
convert_nodelink_data
function to convert into networkx 2.x-compatible format.Parameters: - skeleton_ids : array-like of (int or str)
Returns: - dict
-
get_neuroml
(skeleton_ids, skeleton_inputs=())[source]¶ Get NeuroML v1.8.1 (level 3, NetworkML) for the given skeletons, possibly with their input synapses constrained to another set of skeletons.
- N.B. If len(skeleton_ids) > 1, skeleton_inputs will be ignored and only synapses within the first skeleton
- set will be used in the model.
Parameters: - skeleton_ids : array-like
Skeletons whose NeuroML to return
- skeleton_inputs : array-like, optional
If specified, only input synapses from these skeletons will be added to the NeuroML
Returns: - str
NeuroML output string
-
get_swc
(skeleton_id, linearize_ids=False)[source]¶ Get a single skeleton in SWC format.
Parameters: - skeleton_id : int or str
- linearize_ids : bool
Returns: - str
-
get_treenode_and_connector_geometry
(*skeleton_ids)[source]¶ Get the treenode and connector information for the given skeletons. The returned dictionary will be of the form
- {
- “skeletons”: {
- skeleton_id1: {
- “treenodes”: {
- treenode_id1: {
- “location”: [x, y, z], “parent_id”: id_of_parent_treenode
}, treenode_id2: …
}, “connectors”: {
- connector_id1: {
- “location”: [x, y, z], “presynaptic_to”: [list, of, treenode, ids], “postsynaptic_to”: [list, of, treenode, ids]
}, connector_id2: …
}
}, skeleton_id2: …
}
}
Parameters: - skeleton_ids : array-like of (int or str)
Returns: - dict
-
class
catpy.applications.
NameResolver
(catmaid_client)[source]¶ Bases:
catpy.applications.base.CatmaidClientApplication
Catmaid client application which looks up integer database IDs for string names for various objects.
For convenience, lookup methods short-circuit if given an int (i.e. you can transparently use either the ID or the name of an object).
HTTP responses are cached where possible, so there may be a performance benefit to sharing NameResolver instances. Furthermore, subsequent lookups of IDs of the same object type (e.g. stack, user) should be much faster than the first.
Lookup methods ensure that one object matches the given name/title for the given project, raising a NoMatchingNamesException if there are zero matches, and a MultipleMatchingNamesException if there are more than one, both of which subclass NameResolverException, which subclasses ValueError.
Attributes: - base_url
- project_id
Methods
fetch
(*args, **kwargs)Interact with the CATMAID server in a manner very similar to the javascript CATMAID.fetch API. from_json
(credentials, *args, **kwargs)Return a CatmaidClientApplication instance whose underlying CatmaidClient object is instantiated from the JSON file as per its own from_json method. get
(relative_url[, params, raw])Get data from a running instance of CATMAID. get_neuron_names
(*skeleton_ids)Get a dict of skeleton IDs to neuron names. post
(relative_url[, data, raw])Post data to a running instance of CATMAID. get_neuron_name get_stack_id get_user_id
-
class
catpy.applications.
RelationIdentifier
(catmaid_client)[source]¶ Bases:
catpy.applications.base.CatmaidClientApplication
Class to convert connector relation IDs to ConnectorRelation enums and back.
The mappings are cached on the class, and so do not need to be re-fetched for new instances.
The mappings are retrieved on a per-project basis.
Attributes: - base_url
- project_id
Methods
fetch
(*args, **kwargs)Interact with the CATMAID server in a manner very similar to the javascript CATMAID.fetch API. from_id
(relation_id[, project_id])Return the ConnectorRelation for the given relation ID. from_json
(credentials, *args, **kwargs)Return a CatmaidClientApplication instance whose underlying CatmaidClient object is instantiated from the JSON file as per its own from_json method. get
(relative_url[, params, raw])Get data from a running instance of CATMAID. populate_mappings
(project_id)Populate the id-relation mappings cache for the given project post
(relative_url[, data, raw])Post data to a running instance of CATMAID. to_id
(relation[, project_id])Return the integer ID for the given ConnectorRelation. -
from_id
(relation_id, project_id=None)[source]¶ Return the ConnectorRelation for the given relation ID. If
project_id
is given and you know this project’s mappings are already populated (possibly via a different instance), this can be used as a class method.Parameters: - relation_id
- project_id
Returns: - ConnectorRelation
-
id_to_relation
= {}¶
-
populate_mappings
(project_id)[source]¶ Populate the id-relation mappings cache for the given project
-
relation_to_id
= {}¶