fafbseg.flywire.synapses.get_adjacency#

fafbseg.flywire.synapses.get_adjacency(sources, targets=None, materialization='auto', neuropils=None, filtered=True, min_score=None, batch_size=1000, *, dataset=None, progress=True)[source]#

Fetch adjacency matrix.

Notes

As of May 2023, CAVE provides “views” of materialized tables. This includes a view with neuron edges (as opposed to individual synaptic connections) which can be much faster to query. We will automatically use this view _if_:

  1. filtered=True (default is True)

  2. min_score=None or min_score=50 (default is None)

  3. neuropils=None (default is None)

  4. mat!=’live’ (default is “auto” which can end up as “live”)

Parameters:
  • sources (int | list of int | Neuron/List | NeuronCriteria) – Either FlyWire segment ID (i.e. root ID), a list thereof or a Neuron/List. For neurons, the .id is assumed to be the root ID. If you have a neuron (in FlyWire space) but don’t know its ID, use fafbseg.flywire.neuron_to_segments() first.

  • targets (int | list of int | Neuron/List | NeuronCriteria, optional) – Either FlyWire segment ID (i.e. root ID), a list thereof or a Neuron/List. For neurons, the .id is assumed to be the root ID. If you have a neuron (in FlyWire space) but don’t know its ID, use fafbseg.flywire.neuron_to_segments() first. If None, will assume `targets = sources.

  • neuropils (str | list of str, optional) – Provide neuropil (e.g. 'AL_R') or list thereof (e.g. ['AL_R', 'AL_L']) to filter connectivity to these ROIs. Prefix neuropil with a tilde (e.g. ~AL_R) to exclude it.

  • filtered (bool) – Whether to use the filtered synapse table. Briefly, this filter removes redundant and low confidence (<= 50 cleft score) synapses. See also https://tinyurl.com/4j9v7t86 (links to CAVE website).

  • min_score (int) – Minimum “cleft score”. Buhmann et al. used a threshold of 30 in their paper. However, for FlyWire analyses that threshold was raised to 50 (see also filtered).

  • batch_size (int) – Number of IDs to query per batch. Too large batches can lead to truncated tables: currently individual queries do not return more than 200_000 connections. If you see a warning that this limit has been exceeded, decrease the batch size!

  • materialization (int | str, optional) –

    Which materialization to query:
    • ’auto’ (default) tries to find the most recent materialization version at which all the query IDs existed

    • ’latest’ uses the latest materialized table

    • ’live’ queries against the live data - this will be much slower!

    • pass an integer (e.g. 447) to use a specific materialization version

  • dataset ("public" | "production" | "sandbox", optional) – Against which FlyWire dataset to query. If None will fall back to the default dataset (see set_default_dataset()).

Returns:

adjacency – Adjacency matrix. Rows (sources) and columns (targets) are in the same order as input.

Return type:

pd.DataFrame

See also

get_connectivity()

Use this function to fetch all up- and/or downstream partners for a set of neurons.

Examples

Get connections between given root IDs:

>>> from fafbseg import flywire
>>> adj = flywire.get_adjacency(sources=720575940631406673,
...                             targets=720575940603231916)
Using materialization version 783.
>>> adj
target              720575940603231916
source
720575940631406673                   5