Skip to content

links

Links that open cells in other tools.

Neuroglancer draws the meshes of cells in 3D, and Codex lists cells by search. Each takes the whole request in its URL, so building one reads no data and opens no connection.

codex_search_url(query)

Return a Codex search URL that lists the cells a query matches.

Parameters:

Name Type Description Default
query str

What the Codex search box takes: free text, root ids separated by commas, or structured terms such as class == JON.

required

Returns:

Type Description
str

The page needs a Codex login; without one it shows the sign-in.

See Also

neuroglancer_url : Shows the same cells in 3D.

Examples:

>>> codex_search_url("cell_type == LC16")
'https://codex.flywire.ai/app/search?filter_string=cell_type%20%3D%3D%20LC16'
Source code in champalimaud/links.py
def codex_search_url(query: str) -> str:
    """Return a Codex search URL that lists the cells a query matches.

    Parameters
    ----------
    query : str
        What the Codex search box takes: free text, root ids separated
        by commas, or structured terms such as ``class == JON``.

    Returns
    -------
    str
        The page needs a Codex login; without one it shows the sign-in.

    See Also
    --------
    neuroglancer_url : Shows the same cells in 3D.

    Examples
    --------
    >>> codex_search_url("cell_type == LC16")
    'https://codex.flywire.ai/app/search?filter_string=cell_type%20%3D%3D%20LC16'
    """
    return f"{CODEX_SEARCH}?filter_string={quote(query, safe='')}"

neuroglancer_url(root_ids, *, colors=None, side_panel=False)

Return a Neuroglancer URL that shows cells in 3D.

The scene has the brain outline and the meshes of the given cells, over the EM volume, which loads when a slice view is opened. It needs a browser that has WebGL. Open it in its own tab: framed in a page, the viewer drew 20 cells unsteadily on an integrated GPU (Firefox, Intel Arc 130V) where a tab drew 74 smoothly.

Parameters:

Name Type Description Default
root_ids sequence of int

The cells to show, by root id at the release's materialization.

required
colors mapping of int to str

A color by root id; Neuroglancer picks one for each cell not listed.

None
side_panel bool

Open the panel that lists the segments.

False

Returns:

Type Description
str

The state of the viewer is in the URL fragment, so the link opens the same scene for anyone.

See Also

codex_search_url : Lists the same cells in Codex.

Examples:

>>> import json
>>> from urllib.parse import unquote
>>> url = neuroglancer_url(
...     [720575940606173630], colors={720575940606173630: "#009E73"}
... )
>>> state = json.loads(unquote(url.split("#!")[1]))
>>> state["layers"][-1]["segments"]
['720575940606173630']
Source code in champalimaud/links.py
def neuroglancer_url(
    root_ids: Sequence[int],
    *,
    colors: Mapping[int, str] | None = None,
    side_panel: bool = False,
) -> str:
    """Return a Neuroglancer URL that shows cells in 3D.

    The scene has the brain outline and the meshes of the given cells,
    over the EM volume, which loads when a slice view is opened.
    It needs a browser that has WebGL.
    Open it in its own tab:
    framed in a page, the viewer drew 20 cells unsteadily on an
    integrated GPU (Firefox, Intel Arc 130V) where a tab drew 74
    smoothly.

    Parameters
    ----------
    root_ids : sequence of int
        The cells to show, by root id at the release's materialization.
    colors : mapping of int to str, optional
        A color by root id; Neuroglancer picks one for each cell not
        listed.
    side_panel : bool, default False
        Open the panel that lists the segments.

    Returns
    -------
    str
        The state of the viewer is in the URL fragment,
        so the link opens the same scene for anyone.

    See Also
    --------
    codex_search_url : Lists the same cells in Codex.

    Examples
    --------
    >>> import json
    >>> from urllib.parse import unquote
    >>> url = neuroglancer_url(
    ...     [720575940606173630], colors={720575940606173630: "#009E73"}
    ... )
    >>> state = json.loads(unquote(url.split("#!")[1]))
    >>> state["layers"][-1]["segments"]
    ['720575940606173630']
    """
    segmentation = {
        "type": "segmentation",
        "source": f"precomputed://gs://flywire_v141_m{MATERIALIZATION}",
        "tab": "segments",
        # A root id is past 2**53, so a JSON number would lose digits.
        "segments": [str(i) for i in root_ids],
        "name": f"flywire_v141_m{MATERIALIZATION}",
    }
    if colors:
        segmentation["segmentColors"] = {
            str(i): color for i, color in colors.items()
        }
    state = {
        "dimensions": {
            "x": [1.6e-8, "m"],
            "y": [1.6e-8, "m"],
            "z": [4e-8, "m"],
        },
        "projectionScale": 30000,
        "layers": [
            {
                "type": "image",
                "source": (
                    "precomputed://https://bossdb-open-data.s3.amazonaws.com"
                    "/flywire/fafbv14"
                ),
                "tab": "source",
                "name": "EM",
            },
            {
                "type": "segmentation",
                "source": (
                    "precomputed://gs://flywire_neuropil_meshes"
                    "/whole_neuropil/brain_mesh_v3"
                ),
                "objectAlpha": 0.05,
                "hideSegmentZero": False,
                "segments": ["1"],
                "segmentColors": {"1": "#b5b5b5"},
                "name": "brain_mesh_v3",
            },
            segmentation,
        ],
        "showSlices": False,
        "perspectiveViewBackgroundColor": "#ffffff",
        "showDefaultAnnotations": False,
        "selectedLayer": {
            "visible": side_panel,
            "layer": segmentation["name"],
        },
        "layout": "3d",
    }
    fragment = quote(json.dumps(state, separators=(",", ":")))
    return f"{NEUROGLANCER}/#!{fragment}"