diff --git a/src/vfbquery/vfb_circuit.py b/src/vfbquery/vfb_circuit.py index d1e691b..f01d200 100644 --- a/src/vfbquery/vfb_circuit.py +++ b/src/vfbquery/vfb_circuit.py @@ -19,6 +19,12 @@ neuron chains: paths in the neuron graph that step from a neuron of each class to a neuron of the next. +**Neurons without a class.** Neuron-level paths can pass through neurons left +out of the class graph. Their nodes have ``class: None``, plus ``status`` (why: +``no_leaf``, ``multi_leaf``, ``only_axis`` or ``untyped``) and ``types`` +(``[{id, label}]``, the most specific types they do have) from the run's +``report.tsv``. + **Many sources and targets in one search.** Each graph has two extra vertices, a start joined to every vertex and an end joined from every vertex. A request passes its own weight vector, which is infinite (edge ignored) everywhere @@ -236,6 +242,17 @@ def __init__(self, key, folder, info): # neuron vertex -> class vertex (-1: not assigned), and the reverse self.neuron_class = np.full(self.neuron_graph.n, -1, dtype=np.int32) self.neuron_class[nnames.get_indexer(nc["neuron"])] = cnames.get_indexer(nc["class"]) + # neuron -> (status, [(type id, label)]) for neurons left out of the class graph + self.left_out = {} + report = os.path.join(folder, "report.tsv") + if os.path.exists(report): + rep = _read_tsv(report, {"neuron": str, "status": str, "types": str, "labels": str}) + for n, st, ts, ls in zip(rep["neuron"], rep["status"], rep["types"], rep["labels"]): + ids = ts.split("|") if ts else [] + labels = ls.split("|") if ls else [] + if len(labels) != len(ids): + labels = ids + self.left_out[n] = (st, list(zip(ids, labels))) order = np.argsort(self.neuron_class, kind="stable") bounds = np.searchsorted(self.neuron_class[order], np.arange(len(cnames) + 1)) self.class_members = [order[bounds[i]:bounds[i + 1]] for i in range(len(cnames))] @@ -267,6 +284,11 @@ def neuron_node(self, v): cid = self.class_graph.names[c] node.update({"class": cid, "class_label": self.classes[cid]["label"], "class_symbol": self.classes[cid]["symbol"]}) + elif node["id"] in self.left_out: + # Why the neuron has no class, and the types it does have + status, types = self.left_out[node["id"]] + node.update({"status": status, + "types": [{"id": t, "label": label} for t, label in types]}) return node diff --git a/tests/test_circuit_paths.py b/tests/test_circuit_paths.py index e717e01..6ccff5a 100644 --- a/tests/test_circuit_paths.py +++ b/tests/test_circuit_paths.py @@ -103,6 +103,44 @@ def test_neuron_end_searches_the_neuron_graph(store): assert block["paths"][0]["nodes"][1]["class"] == "C" +def _write_left_out_run(folder): + """x1 has two leaf types (X, Y); z1 is typed only to AB, which A and B subtype.""" + types = dict(TYPES, x1=["X", "Y"], z1=["AB"]) + labels = dict(LABELS, Y="class Y", AB="class AB") + anc = dict(ANC, Y=set()) + edges = EDGES + [("a1", "z1", 6), ("z1", "d1", 6)] + up = dict(UP, z1=10) + down = dict(DOWN, z1=10) + meta = {"built": "2026-11-18T00:00:00Z"} + _, entry = vcc.write_site(os.path.join(folder, "tiny"), dict(meta, run="run-1", connectome="tiny"), + types, up, down, labels, {}, anc, iter(edges), log=lambda *_: None) + vcc.write_manifest(str(folder), "run-1", meta, {"tiny": dict(entry, label="tiny label", symbol="tn")}) + return str(folder) + + +def test_neurons_without_a_class_say_why(tmp_path): + store = vc.load_run(_write_left_out_run(tmp_path), log=lambda *_: None) + _, block = paths(vc.find_paths(store, ["a1"], ["D"])) + nodes = {n["id"]: n for p in block["paths"] for n in p["nodes"]} + assert nodes["x1"]["class"] is None + assert nodes["x1"]["status"] == "multi_leaf" + assert sorted(t["id"] for t in nodes["x1"]["types"]) == ["X", "Y"] + assert {t["id"]: t["label"] for t in nodes["x1"]["types"]}["Y"] == "class Y" + assert nodes["z1"]["status"] == "no_leaf" + assert nodes["z1"]["types"] == [{"id": "AB", "label": "class AB"}] + # Neurons with a class carry neither + assert nodes["d1"]["class"] == "D" and "status" not in nodes["d1"] + + +def test_a_run_without_a_report_still_loads(tmp_path): + folder = _write_left_out_run(tmp_path) + os.remove(os.path.join(folder, "tiny", "report.tsv")) + store = vc.load_run(folder, verify=False, log=lambda *_: None) + _, block = paths(vc.find_paths(store, ["a1"], ["D"])) + x1 = next(n for p in block["paths"] for n in p["nodes"] if n["id"] == "x1") + assert x1["class"] is None and "status" not in x1 + + def test_instance_graph_gives_neuron_chains_along_each_class_path(store): _, block = paths(vc.find_paths(store, ["A"], ["D"], instance_graph=True)) chains = block["paths"][0]["instances"]