Client¶
All communication to the neuPrint server is peformed using a
Client
object, which holds your authorization
credentials, the dataset name to use, and other connection settings.
(To obtain your authorization credentials, see the Quickstart.)
For commonly used queries, see Queries.
Or you can implement your own cypher queries using fetch_custom()
.
Example
In [1]: from neuprint import Client, fetch_custom, fetch_neurons
In [2]: # Create a default client.
...: # It will be implicitly used for all subsequent queries as
...: long as it remains the only client you've created.
...: c = Client('neuprint.janelia.org', dataset='hemibrain:v1.2.1')
In [3]: fetch_custom("""\
...: MATCH (n: Neuron)
...: WHERE n.status = "Traced" AND NOT n.cropped
...: RETURN n.bodyId as bodyId, n.type as type, n.instance as instance
...: ORDER BY n.type, n.instance
...: """)
Out[3]:
bodyId type instance
0 511051477 5th s-LNv 5th s-LNv
1 947590512 ADL01a_pct ADL01a_pct(ADL01)_R
2 1100952886 ADL01b_pct ADL01b_pct(ADL01)_R
3 1228484534 ADL01b_pct ADL01b_pct(ADL01)_R
4 1290563000 ADL01b_pct ADL01b_pct(ADL01)_R
... ... ... ...
21658 2346523421 None None
21659 2397377415 None None
21660 2429314661 None None
21661 2464541644 None None
21662 2404203061 None None
[21663 rows x 3 columns]
Tip
All cypher queries are logged, but the messages are not
shown in the console by default. To display them, see
setup_debug_logging()
.
Obtain the default Client object to use. |
|
|
Set (or overwrite) the default Client. |
Unset the default Client, leaving no default in place. |
|
List all |
|
Simple debug logging configuration. |
|
Client
methods correspond directly to built-in
neuprintHTTP API endpoints.
|
Client object for interacting with the neuprint database. |
|
Query the neuprint server with a custom Cypher query. |
Fetch the list of REST API endpoints supported by the server. |
|
Fetch auto-generated REST API documentation, as YAML text. |
|
Returns whether or not the server is public. |
|
Returns the version of the |
|
Fetch the address of the neo4j database that the neuprint server is using. |
|
|
Fetch basic information about the available datasets on the server. |
Fetch secondary data instances avaiable through neupint http |
|
Fetch the database version |
|
Fetch basic information about your user profile, including your access level. |
|
Fetch your user authentication token. |
|
|
Return information about today's cell type of the day. |
|
Fetch the pre-computed traced "completeness" statistics for each primary ROI in the dataset. |
|
Fetch the pre-computed connectivity statistics between primary ROIs in the dataset. |
|
Fetch a mesh for the given ROI, in |
|
Fetch the skeleton for a neuron or segment. |
|
Fetch a value from the |
|
Post a value from the |
- class neuprint.client.Client(server, dataset=None, token=None, verify=True)[source]¶
Client object for interacting with the neuprint database.
When you create the first
Client
, it becomes the defaultClient
to be used with allneuprint-python
functions if you don’t explicitly specify one. But if you create multipleClient
objects, the default client is cleared and you must explicitly pass aclient
parameter to all query functions.- Parameters
server – URL of neuprintHttp server
token – neuPrint token. Either pass explitily as an argument or set as
NEUPRINT_APPLICATION_CREDENTIALS
environment variable. Your token can be retrieved by clicking on your account in the NeuPrint web interface.verify – If
True
(default), enforce signed credentials.dataset – The dataset to run all queries against, e.g. ‘hemibrain’. If not provided, the server will use a default dataset for all queries.
- fetch_custom(cypher, dataset='', format='pandas')[source]¶
Query the neuprint server with a custom Cypher query.
- Parameters
cypher – A cypher query string
dataset –
Deprecated. Please provide your dataset as a Client constructor argument.
Which neuprint dataset to query against. If None provided, the client’s default dataset is used.
format – Either
'pandas'
or'json'
. Whether to load the results into apandas.DataFrame
, or return the server’s raw JSON response as a Pythondict
.
- Returns
Either json or DataFrame, depending on
format
.
- fetch_daily_type(format='pandas')[source]¶
Return information about today’s cell type of the day.
The server updates the completeness numbers each day. A different cell type is randomly picked and an exemplar is chosen from this type.
- Returns
If
format='json'
, a dictionary is returned with keys['info', 'connectivity', 'skeleton']
. Ifformat='pandas'
, three values are returned:(info, connectivity, skeleton)
, whereconnectivity
andskeleton
are DataFrames.
- fetch_database()[source]¶
Fetch the address of the neo4j database that the neuprint server is using.
- fetch_datasets(reload_cache=False)[source]¶
Fetch basic information about the available datasets on the server.
- Parameters
reload_cache – The result from each unique neuprint server is cached locally and re-used by all Clients, but you can invalidate the entire cache by setting reload_cache to True, causing it to be repopulated during this call.
- Returns
dict, keyed by dataset name
- fetch_profile()[source]¶
Fetch basic information about your user profile, including your access level.
- fetch_raw_keyvalue(instance, key)[source]¶
Fetch a value from the
neuprintHTTP
server. The data address is given by both the instance name and key. (For admins and experts only.)
- fetch_roi_completeness(format='pandas')[source]¶
Fetch the pre-computed traced “completeness” statistics for each primary ROI in the dataset.
The completeness statistics indicate how many synapses belong to Traced neurons.
Note
These results are not computed on-the-fly. They are computed periodically and cached.
- fetch_roi_connectivity(format='pandas')[source]¶
Fetch the pre-computed connectivity statistics between primary ROIs in the dataset.
Note
These results are not computed on-the-fly. They are computed periodically and cached.
- fetch_roi_mesh(roi, export_path=None)[source]¶
Fetch a mesh for the given ROI, in
.obj
format.- Parameters
roi – Name of an ROI
export_path – Optional. Writes the
.obj
file to the given path.
- Returns
bytes The contents of the fetched
.obj
mesh file.
Note
ROI meshes are intended for visualization only. (They are not suitable for quantitative analysis.)
- fetch_skeleton(body, heal=False, export_path=None, format='pandas', with_distances=False)[source]¶
Fetch the skeleton for a neuron or segment.
- Parameters
body (int) – A neuron or segment ID
heal (bool) –
If
True
and the skeleton is fragmented, ‘heal’ it by connecting its fragments into a single tree. The fragments are joined by selecting the minimum spanning tree after joining all fragments via their pairwise nearest neighbors. Seeheal_skeleton()
for more details.If you want the healing procedure to refrain from connecting very distant fragments, set
heal
to a maximum allowed distance, e.g.heal=1000.0
format (str) – Either ‘pandas’, ‘swc’ (similar to CSV), or ‘nx’ (
networkx.DiGraph
).export_path (str) – Optional. Writes the
.swc
file to disk. (SWC format is written, regardless of the returnedformat
.)with_distances – Only valid when format is
pandas
ornx
. If True, a ‘distance’ column (or edge attribute) will be added to the dataframe (or nx.Graph), indicating the distances from each node to its parent node. In DataFrame results, root nodes will be assigned a distance ofnp.inf
. Distances are computed AFTER healing is performed. Distances will not be present in any exported SWC file.
- Returns
Either a string (swc), a DataFrame (pandas), or
networkx.DiGraph
(nx).
- neuprint.client.default_client()[source]¶
Obtain the default Client object to use. This function returns a separate copy of the default client for each thread (and process).
There’s usually no need to call this function. It is automatically called by all query functions if you haven’t passed in an explict client argument.
- neuprint.client.set_default_client(client)[source]¶
Set (or overwrite) the default Client.
There’s usually no need to call this function. It’s is automatically called when your first
Client
is created, but you can call it again to replace the default.
- neuprint.client.clear_default_client()[source]¶
Unset the default Client, leaving no default in place.
- neuprint.client.setup_debug_logging()[source]¶
Simple debug logging configuration. Useful for interactive terminal sessions.
Warning
Replaces your current logging setup. If you’ve already set up logging for your app, don’t call this function. Enable neuprint debug logging via:
import logging logging.getLogger('neuprint.client').setLevel(logging.DEBUG)
To disable cypher logging again, increase the logging severity threshold:
import logging logging.getLogger('neuprint.client').setLevel(logging.INFO)
Example
In [1]: from neuprint.client import setup_debug_logging ...: from neuprint import fetch_neurons, NeuronCriteria as NC ...: ...: setup_debug_logging() ...: neuron_df, roi_df = fetch_neurons(NC(type='MBON.*', rois=['MB(R)'])) [2020-01-30 08:48:20,367] DEBUG Performing cypher query against dataset 'hemibrain:v1.2.1': MATCH (n :Neuron) // -- Basic conditions for segment 'n' -- WHERE n.type =~ 'MBON.*' AND (n.`MB(R)`) RETURN n ORDER BY n.bodyId