Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions LLM_GUIDANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ The `run_query` tool accepts an array of IDs and runs the query on all of them i
| `DownstreamClassConnectivity` | Neuron class FBbt ID | Downstream partner classes with % connected, avg weight (includes data from all datasets) | Fast (pre-indexed) |
| `UpstreamClassConnectivity` | Neuron class FBbt ID | Upstream partner classes with % connected, avg weight (includes data from all datasets) | Fast (pre-indexed) |
| `query_connectivity` | Neuron class names or FBbt IDs | Connections between two neuron classes (includes data from all datasets) | Slow (1–5 min, live) |
| `find_circuit_paths` | FBbt class IDs or VFB neuron IDs (not labels) | Ranked multi-hop pathways from one class/neuron to another, per dataset | Fast (precomputed) |
| `find_circuit_paths` | FBbt class IDs or VFB neuron IDs (not labels) | Ranked multi-hop pathways from one class/neuron to another, per dataset | Fast (precomputed); tens of seconds with `instance_graph` |
| `get_predicted_neurotransmitters` | Neuron class name or FBbt ID | Predicted NT(s) per class (or per instance), with mean confidence, as GO terms; optional per-dataset split | Live (seconds) |
| `get_known_neurotransmitters` | Neuron class name or FBbt ID | Curated NT(s) for the class and subclasses, as GO terms (no confidence) | Live (seconds) |

Expand Down Expand Up @@ -601,7 +601,7 @@ Note that a class label may be several names joined with `|` — a neuron that i
Use it when the user asks how one cell type reaches another through intermediate neurons. For a direct connection between two classes use `query_connectivity`; for "what is downstream of X" use `DownstreamClassConnectivity`.

1. **Get ids.** It takes FBbt class ids or VFB neuron ids only. Resolve names with `search_terms` (`filter_types: ["neuron","class"]`). A broad class (e.g. Kenyon cell) is fine: it expands to the leaf classes beneath it, listed under each dataset's `sources`/`targets`.
2. **Call it with the defaults** (`k` 5, `min_synapses` 5, `exclude_dbs` omitted = `["hb","fafb"]`). It is fast, so there is no need to confirm parameters first.
2. **Call it with the defaults** (`k` 5, `min_synapses` 5, `exclude_dbs` omitted = `["hb","fafb"]`, `instance_graph` off). It is fast, so there is no need to confirm parameters first.
3. **If nothing is found:** check `warnings` and `found_in` (a term absent from a dataset gives no paths there), then try `min_synapses: 1`, then `exclude_dbs: []`. Tell the user what you changed.

**Reading the result.**
Expand All @@ -611,7 +611,7 @@ Use it when the user asks how one cell type reaches another through intermediate
- `level` is `class` when both ends are classes and `neuron` when either end is a VFB neuron id.
- `neurons_left_out`: neurons with no single leaf cell type in that dataset are not in the class graph. If a path the user expects is missing, this may be why.
- In neuron-level paths, a neuron left out of the class graph has `class: null`, `status` (`no_leaf`: typed only to general classes; `multi_leaf`: several leaf types; `only_axis`: only transmitter, lineage or similar classes; `untyped`) and `types` (`[{id, label}]`). Name it by its types rather than calling it untyped.
- `instances` (with `instance_graph: true`): the best individual-neuron chains along a class path, as VFB ids.
- `instances` (with `instance_graph: true`): the best individual-neuron chains along a class path, as VFB ids. This takes tens of seconds on the large connectomes, so only set it when the user asks about individual neurons, with `k` at most 5 and `instance_k` at most 3.

**Why the numbers differ from `query_connectivity`.** `find_circuit_paths` counts each neuron once, under its most specific cell type, and keeps datasets apart. `query_connectivity` with `group_by_class` rolls each connection up to every ancestor class and pools datasets. Both are correct for their purpose; don't compare their figures directly, and say which one you used.

Expand Down Expand Up @@ -670,7 +670,7 @@ For `query_connectivity` the summary stats are already computed for you over the
- "To see which brain regions this neuron connects to, I can run a region connectivity query."
- "To find what connects *back* to this type, I can swap upstream/downstream."
- "To aggregate by neuron class, I can re-run with group_by_class=true."
- "To see the individual neurons along a circuit path, I can re-run find_circuit_paths with instance_graph=true."
- "To see the individual neurons along a circuit path, I can re-run find_circuit_paths with instance_graph=true (this takes up to a minute)."
- "You can view any neuron at `https://v3.virtualflybrain.org/org.geppetto.frontend/geppetto?id={ID}`"

---
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ Find the strongest multi-hop pathways from one neuron class (or neuron) to anoth
- `min_inprop` (number, optional): Minimum input proportion per step (0..1, default 0)
- `normalise` (string, optional): `input` (default) or `output`
- `exclude_dbs` (array, optional): Dataset symbols to exclude (default `["hb","fafb"]`; `[]` for all)
- `instance_graph` (boolean, optional): Add the best individual-neuron chains along each class path
- `instance_k` (number, optional): Neuron chains per class path (default 3, max 10)
- `instance_graph` (boolean, optional): Add the best individual-neuron chains along each class path. Slow: tens of seconds on the large connectomes. With it, `k` is at most 5 and `instance_k` at most 3
- `instance_k` (number, optional): Neuron chains per class path (default 3, max 3)

Set `VFBQUERY_CIRCUIT_BASE` to send these requests to another circuit server (e.g. a local one or p3) instead of `https://v3-cached.virtualflybrain.org`.

Expand Down
20 changes: 20 additions & 0 deletions src/circuitPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ export const CIRCUIT_DEFAULTS = {
export const CIRCUIT_MAX_K = 20;
export const CIRCUIT_MAX_INSTANCE_K = 10;

// instance_graph searches the neuron graph along every class path and takes
// tens of seconds on the large connectomes (22 s for LC12 -> giant fiber at the
// defaults; k=20, instance_k=10 ran past the handler's 60 s timeout). The server
// carries on after the client gives up, so keep requests small until it has a
// time limit (VFBquery#114).
export const CIRCUIT_INSTANCE_MAX_K = 5;
export const CIRCUIT_INSTANCE_MAX_INSTANCE_K = 3;

export interface CircuitPathsArgs {
source?: string | string[];
target?: string | string[];
Expand Down Expand Up @@ -63,6 +71,18 @@ export function buildCircuitParams(args: CircuitPathsArgs): CircuitRequest {
};
}

if (args.instance_graph) {
const tooBig = ([['k', CIRCUIT_INSTANCE_MAX_K], ['instance_k', CIRCUIT_INSTANCE_MAX_INSTANCE_K]] as const)
.filter(([name, max]) => args[name] !== undefined && args[name] !== null && Number(args[name]) > max)
.map(([name, max]) => `${name} at most ${max}`);
if (tooBig.length) {
return {
error: `With instance_graph=true, use ${tooBig.join(' and ')}: neuron chains take tens of seconds `
+ 'on the large connectomes. For more class paths, call again without instance_graph.',
};
}
}

const params = new URLSearchParams();
params.set('source', sources.join(','));
params.set('target', targets.join(','));
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import express from 'express';
import { createHash, randomUUID } from 'node:crypto';
import { shapeRunQueryResult, runQueryFailed } from './runQueryShape.js';
import { shapeCombineResult, shapeXrefResult } from './combineShape.js';
import { buildCircuitParams, CircuitPathsArgs, CIRCUIT_MAX_K, CIRCUIT_MAX_INSTANCE_K } from './circuitPaths.js';
import { buildCircuitParams, CircuitPathsArgs, CIRCUIT_MAX_K, CIRCUIT_INSTANCE_MAX_K, CIRCUIT_INSTANCE_MAX_INSTANCE_K } from './circuitPaths.js';

// Version is single-sourced from package.json so a release tag (forced into
// package.json by CI before the build) flows straight into serverInfo.
Expand Down Expand Up @@ -418,7 +418,7 @@ function setupToolHandlers(server: Server, sessionIdHolder?: RequestContext) {
},
{
name: 'find_circuit_paths',
description: 'Find the strongest multi-hop synaptic pathways from one Drosophila neuron class (or neuron) to another, e.g. "how does LC12 reach the giant fiber?" or "what routes lead from DA1 ORNs to MBON01?". Answers from precomputed graphs, so it is fast (well under a few seconds). Use this for indirect routes; for direct connections between two classes use query_connectivity, and for one-sided partner lists use run_query with UpstreamClassConnectivity / DownstreamClassConnectivity. INPUT: ids only — FBbt class ids, or VFB ids for individual neurons; labels are refused, so resolve names with search_terms (filter_types ["neuron","class"]) first. Several ids per end are allowed. SCORING: each step is weighted by its input proportion (inprop_in: the fraction of the downstream class\'s total synaptic input that comes from the upstream class); a path\'s score is the product of its steps, so a 3-step path at 0.1 per step scores 0.001. Paths are ranked best first; scores are comparable within a dataset, not as absolute strengths. normalise="output" uses the fraction of the upstream class\'s output instead. HOW CLASSES ARE COUNTED: each neuron is assigned to its single most specific (leaf) cell type in that connectome, so broad classes do not act as shortcuts. A broad term such as "Kenyon cell" expands to the leaf classes beneath it (listed under sources/targets). Neurons with no leaf type, or more than one, are left out (neurons_left_out counts them). They can still appear in neuron-level paths, as nodes with class null plus status (no_leaf: only general types; multi_leaf: several leaf types; only_axis: only transmitter/lineage-type classes; untyped) and types (the most specific types they do have). Because of this the figures differ from query_connectivity with group_by_class=true, which rolls connections up to every ancestor class and pools datasets: do not compare the two numbers directly. LEVELS: if both ends are classes the search runs on the class graph; if either end is a VFB neuron id, it runs on the neuron graph (class ends expand to their neurons). DATASETS: each connectome is searched separately and reported in its own block; shared_class_paths lists class paths found in more than one dataset, which are the most robust. instance_graph=true adds the best individual-neuron chains along each class path. RECOMMENDED DEFAULTS: k=5, min_synapses=5, exclude_dbs omitted (= ["hb","fafb"]). If no paths are found, try min_synapses=1, then exclude_dbs=[]. Every response names the data release (run) it came from.',
description: 'Find the strongest multi-hop synaptic pathways from one Drosophila neuron class (or neuron) to another, e.g. "how does LC12 reach the giant fiber?" or "what routes lead from DA1 ORNs to MBON01?". Answers from precomputed graphs, so class and neuron paths take a second or two. Use this for indirect routes; for direct connections between two classes use query_connectivity, and for one-sided partner lists use run_query with UpstreamClassConnectivity / DownstreamClassConnectivity. INPUT: ids only — FBbt class ids, or VFB ids for individual neurons; labels are refused, so resolve names with search_terms (filter_types ["neuron","class"]) first. Several ids per end are allowed. SCORING: each step is weighted by its input proportion (inprop_in: the fraction of the downstream class\'s total synaptic input that comes from the upstream class); a path\'s score is the product of its steps, so a 3-step path at 0.1 per step scores 0.001. Paths are ranked best first; scores are comparable within a dataset, not as absolute strengths. normalise="output" uses the fraction of the upstream class\'s output instead. HOW CLASSES ARE COUNTED: each neuron is assigned to its single most specific (leaf) cell type in that connectome, so broad classes do not act as shortcuts. A broad term such as "Kenyon cell" expands to the leaf classes beneath it (listed under sources/targets). Neurons with no leaf type, or more than one, are left out (neurons_left_out counts them). They can still appear in neuron-level paths, as nodes with class null plus status (no_leaf: only general types; multi_leaf: several leaf types; only_axis: only transmitter/lineage-type classes; untyped) and types (the most specific types they do have). Because of this the figures differ from query_connectivity with group_by_class=true, which rolls connections up to every ancestor class and pools datasets: do not compare the two numbers directly. LEVELS: if both ends are classes the search runs on the class graph; if either end is a VFB neuron id, it runs on the neuron graph (class ends expand to their neurons). DATASETS: each connectome is searched separately and reported in its own block; shared_class_paths lists class paths found in more than one dataset, which are the most robust. instance_graph=true adds the best individual-neuron chains along each class path, but takes tens of seconds on the large connectomes: use it only when the user asks about individual neurons, and then with k at most 5 and instance_k at most 3. RECOMMENDED DEFAULTS: k=5, min_synapses=5, exclude_dbs omitted (= ["hb","fafb"]). If no paths are found, try min_synapses=1, then exclude_dbs=[]. Every response names the data release (run) it came from.',
inputSchema: {
type: 'object',
properties: {
Expand All @@ -432,7 +432,7 @@ function setupToolHandlers(server: Server, sessionIdHolder?: RequestContext) {
},
k: {
type: 'number',
description: `Paths to return per dataset, best first (default 5, max ${CIRCUIT_MAX_K}).`,
description: `Paths to return per dataset, best first (default 5, max ${CIRCUIT_MAX_K}; max ${CIRCUIT_INSTANCE_MAX_K} with instance_graph).`,
default: 5,
},
min_synapses: {
Expand All @@ -458,12 +458,12 @@ function setupToolHandlers(server: Server, sessionIdHolder?: RequestContext) {
},
instance_graph: {
type: 'boolean',
description: 'If true, add the best individual-neuron chains along each class path (instances). Slower (about a second). Default false.',
description: 'If true, add the best individual-neuron chains along each class path (instances). Slow: tens of seconds on the large connectomes, so only when the user asks about individual neurons. With it, k is at most 5 and instance_k at most 3. Default false.',
default: false,
},
instance_k: {
type: 'number',
description: `Neuron chains per class path when instance_graph is true (default 3, max ${CIRCUIT_MAX_INSTANCE_K}).`,
description: `Neuron chains per class path when instance_graph is true (default 3, max ${CIRCUIT_INSTANCE_MAX_INSTANCE_K}).`,
default: 3,
},
},
Expand Down
14 changes: 12 additions & 2 deletions tests/circuitPaths.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ test('exclude_dbs: omitted keeps the default, [] searches every dataset', () =>

test('options are passed through in the endpoint\'s spelling', () => {
const p = params({
source: LC12, target: GF, k: 10, min_synapses: 0, min_inprop: 0.01,
source: LC12, target: GF, k: 4, min_synapses: 0, min_inprop: 0.01,
normalise: 'Output', instance_graph: true, instance_k: 2,
});
assert.deepEqual(p, {
source: LC12, target: GF, k: '10', min_synapses: '0', min_inprop: '0.01',
source: LC12, target: GF, k: '4', min_synapses: '0', min_inprop: '0.01',
normalise: 'output', instance_graph: 'true', instance_k: '2',
});
});
Expand All @@ -65,3 +65,13 @@ test('out-of-range options are refused before the request', () => {
assert.match(buildCircuitParams({ ...base, normalise: 'both' }).error, /normalise/);
assert.match(buildCircuitParams({ ...base, instance_k: 11 }).error, /instance_k/);
});

test('instance_graph keeps k to 5 and instance_k to 3, because it is slow', () => {
assert.deepEqual(params({ source: LC12, target: GF, instance_graph: true, k: 5, instance_k: 3 }),
{ source: LC12, target: GF, k: '5', instance_k: '3', instance_graph: 'true' });
const both = buildCircuitParams({ source: LC12, target: GF, instance_graph: true, k: 20, instance_k: 10 });
assert.match(both.error, /k at most 5 and instance_k at most 3/);
assert.match(buildCircuitParams({ source: LC12, target: GF, instance_graph: true, k: 6 }).error, /^With instance_graph=true, use k at most 5:/);
// Without instance_graph, k can still go to 20
assert.equal(params({ source: LC12, target: GF, k: 20 }).k, '20');
});
Loading