crantpy.queries.neurons module#
NeuronCriteria class for filtering neurons based on Seatable annotations. This class allows filtering neurons based on various criteria defined in the Seatable annotations table. Filtering for multiple criteria is done using a logical AND, i.e. only neurons that match all criteria will be selected. Not providing any criteria will return all neurons in the annotations table. This class is part of the CRANTB project and is designed to work with Seatable’s API to fetch and filter neuron data.
- class crantpy.queries.neurons.NeuronCriteria(*, regex=False, case=False, verbose=False, clear_cache=False, match_all=False, exact=True, dataset=None, **criteria)[source]#
Bases:
object
Parses filter queries into root IDs using Seatable.
This class allows filtering neurons based on various criteria defined in the Seatable annotations table.
Filtering for multiple criteria is done using a logical AND, i.e. only neurons that match all criteria will be selected.
Not providing any criteria will return all neurons in the annotations table.
- Parameters:
regex (bool, default False) – Whether to interpret string criteria as regex.
case (bool, default False) – Whether to interpret string criteria as case sensitive (only applies when regex=True).
verbose (bool, default False) – Whether to print information about the query process.
clear_cache (bool, default False) – Whether to force reloading annotations from Seatable, bypassing the cache.
match_all (bool, default False) – When filtering by a list of values on a column that contains lists (e.g., status=[‘DAMAGED’, ‘TRACING_ISSUE’]), setting match_all=True will only return neurons where the column contains all the specified values. If False (default), it returns neurons where the column contains any of the specified values.
exact (bool, default True) – Whether to match values exactly. If False, substring matching is enabled.
dataset (str, optional) – The dataset to fetch annotations from.
**criteria (dict) – Filtering criteria where keys are column names from NeuronCriteria.available_fields() and values are the desired values or lists of values to filter by.
Examples
>>> from crantbseg.crantb.annotations import NeuronCriteria as NC
>>> # Check available fields >>> NC.available_fields() ['root_id', 'nucleus_id', ...]
>>> # Get all neurons (will print a warning) >>> all_neurons = NC()
>>> # Get neurons by cell class >>> ol_neurons = NC(cell_class='olfactory_projection_neuron') >>> # Get neurons by multiple cell types using regex >>> pns = NC(cell_type=['PN_.*', 'mPN_.*'], regex=True)
>>> # Get neurons by side and status (any status in the list) >>> left_proofread = NC(side='L', status=['BACKBONE_PROOFREAD', 'PRELIM_PROOFREAD'])
>>> # Get neurons by side and status (must have BOTH statuses) >>> left_damaged_and_tracing = NC(side='L', status=['DAMAGED', 'TRACING_ISSUE'], match_all=True)
>>> # Use in functions expecting root IDs >>> neuron_data = some_function(NC(cell_class='picky_neuron'))
- property annotations: pandas.DataFrame#
Return annotations table (DataFrame), loading if necessary.
- Returns:
DataFrame containing the annotations from Seatable.
- Return type:
pd.DataFrame
- classmethod available_fields()[source]#
Return all available fields for selection.
- Returns:
List of field names that can be used for filtering.
- Return type:
List[str]
- get_roots()[source]#
Return all root IDs matching the given criteria.
- Returns:
Array of root IDs matching the given criteria.
- Return type:
- Raises:
NoMatchesError – If no neurons are found matching the given criteria.
- property is_empty: bool#
Returns True if no criteria are specified.
- Returns:
True if no criteria are specified, False otherwise.
- Return type:
- to_neuroglancer(**kwargs)[source]#
Create a neuroglancer URL for neurons matching the criteria.
This is a convenience method that generates a neuroglancer visualization URL for all neurons that match the current filter criteria.
- Parameters:
**kwargs – Additional arguments passed to encode_url(). Common options: - seg_colors: Color scheme for segments - layout: Layout type (“3d”, “xy-3d”, “xy”, “4panel”) - coords: Center position [x, y, z] - open: Whether to open in browser - to_clipboard: Whether to copy to clipboard - shorten: Whether to create shortened URL
- Returns:
Neuroglancer URL for the matching neurons.
- Return type:
Examples
>>> from crantpy import NeuronCriteria >>> nc = NeuronCriteria(cell_class='olfactory_projection_neuron') >>> url = nc.to_neuroglancer(seg_colors=np.arange(len(nc.get_roots()))) >>> >>> # With custom settings >>> url = nc.to_neuroglancer(layout='4panel', open=True, shorten=True)
See also
crantpy.utils.neuroglancer.encode_url
Full documentation of available parameters
- crantpy.queries.neurons.get_annotations(neurons, dataset=None, clear_cache=False, proofread_only=False)[source]#
Get annotations from Seatable.
- Parameters:
neurons (int, str, list of int/str, or NeuronCriteria) – Neuron root ID(s) or a NeuronCriteria instance specifying which neurons to fetch. Accepts a single ID, a list/array of IDs, or a NeuronCriteria object.
dataset (str, optional) – Dataset to fetch annotations from.
clear_cache (bool, default False) – Whether to force reloading annotations from Seatable, bypassing the cache.
proofread_only (bool, default False) – Whether to return only annotations marked as proofread.
- Returns:
DataFrame containing the annotations for the specified neurons.
- Return type:
pd.DataFrame
- Raises:
ValueError – If the input type is invalid.
NoMatchesError – If no matching neurons are found.
- crantpy.queries.neurons.is_proofread(neurons, dataset=None, clear_cache=False)[source]#
Check if the specified neurons are proofread.
- Parameters:
neurons (Neurons = Neurons = str | int | np.int64 | navis.BaseNeuron | Iterables of previous types | navis.NeuronList | NeuronCriteria) – Neurons to check for proofread status.
dataset (str, optional) – Dataset to fetch annotations from.
clear_cache (bool, default False) – Whether to force updating annotations from Seatable, bypassing the cache.
- Returns:
A boolean array indicating whether each neuron is proofread.
- Return type:
np.ndarray
- crantpy.queries.neurons.parse_neuroncriteria(*args, **kwargs)#
Deprecated: parse_neuroncriteria has moved to crantpy.utils.decorators.
This function will be removed in a future version. Please update your imports:
OLD: from crantpy.queries.neurons import parse_neuroncriteria NEW: from crantpy.utils.decorators import parse_neuroncriteria