Skip to content

Raw synapses for one cell

One row per synaptic contact, with 3D positions (nm), detection scores, and transmitter probabilities. collect keeps only id, pre_pt_root_id, post_pt_root_id and counts rows per pair; this shows what those counts are made of.

# Default to the first LC16 cell in the census;
# paste any root id to look at another cell.
root_input = mo.ui.text(
    value=str(root_ids_of_type(load_census(), "LC16")[0]),
    label="root id",
)
fetch_btn = mo.ui.run_button(label="fetch synapses")
mo.hstack([root_input, fetch_btn], justify="start")
def raw_synapses(root_id: int):
    """Every synapse into or out of root_id with all detail columns,
    plus role IN or OUT; self-contacts dropped.

    CAVE hands the rows back as a pandas frame.
    """
    m = cave_materialize()
    columns = [
        "id",
        "pre_pt_root_id",
        "post_pt_root_id",
        "pre_pt_position",
        "post_pt_position",
        "connection_score",
        "cleft_score",
        "valid_nt",
        *NT_COLS,
    ]
    outgoing = m.query_table(
        Sources.TRANSMITTER_TABLE,
        filter_in_dict={"pre_pt_root_id": [root_id]},
        select_columns=columns,
    )
    incoming = m.query_table(
        Sources.TRANSMITTER_TABLE,
        filter_in_dict={"post_pt_root_id": [root_id]},
        select_columns=columns,
    )
    outgoing["role"] = "OUT"
    incoming["role"] = "IN"
    return drop_self_edges(pd.concat([incoming, outgoing], ignore_index=True))
mo.stop(not fetch_btn.value)
raw = raw_synapses(int(root_input.value))
raw["role"].value_counts()
# The most likely transmitter per synapse, as a new column rather
# than a mutation of raw (marimo does not rerun cells on mutation).
_top_nt = raw[NT_COLS].idxmax(axis=1)
mo.ui.table(raw.assign(top_nt=_top_nt), page_size=20)
ancestor-stopped: This cell wasn't run because an ancestor was stopped with `mo.stop`: