@@ -12,16 +12,33 @@ def _get_nc():
1212
1313
1414def _resolve_neuron_type_label (nc , label ):
15- """Resolve a neuron type label to a VFB short_form ID.
15+ """Resolve a neuron type label or FBbt ID to a VFB short_form ID.
1616
17- Tries exact label match first, then case-insensitive.
17+ Accepts FBbt IDs (e.g. "FBbt_00003789"), exact labels, synonym matches,
18+ or case-insensitive labels.
1819
1920 :param nc: Neo4jConnect instance
20- :param label: Neuron type label (e.g. "Kenyon cell")
21+ :param label: Neuron type label (e.g. "Kenyon cell") or FBbt ID
2122 :return: short_form ID (e.g. "FBbt_00003686")
2223 :raises ValueError: if label not found
2324 """
24- # Exact match
25+ import re
26+
27+ # Direct FBbt ID lookup
28+ if re .match (r'^FBbt_\d+$' , label ):
29+ results = nc .commit_list ([
30+ f"MATCH (n:Class:Neuron {{short_form: '{ label } '}}) "
31+ f"RETURN n.short_form LIMIT 1"
32+ ])
33+ dc = dict_cursor (results )
34+ if dc :
35+ return dc [0 ]["n.short_form" ]
36+ raise ValueError (
37+ f"Neuron class not found for ID '{ label } '. "
38+ "Check the ID is a valid neuron class (not an anatomy region)."
39+ )
40+
41+ # Exact label match
2542 results = nc .commit_list ([
2643 f"MATCH (n:Class:Neuron) WHERE n.label = '{ label } ' "
2744 f"RETURN n.short_form LIMIT 1"
@@ -30,7 +47,7 @@ def _resolve_neuron_type_label(nc, label):
3047 if dc :
3148 return dc [0 ]["n.short_form" ]
3249
33- # Case-insensitive fallback
50+ # Case-insensitive label fallback
3451 results = nc .commit_list ([
3552 f"MATCH (n:Class:Neuron) WHERE toLower(n.label) = toLower('{ label } ') "
3653 f"RETURN n.short_form, n.label LIMIT 5"
@@ -39,6 +56,15 @@ def _resolve_neuron_type_label(nc, label):
3956 if dc :
4057 return dc [0 ]["n.short_form" ]
4158
59+ # Synonym match (catches short names like "Tm1")
60+ results = nc .commit_list ([
61+ f"MATCH (n:Class:Neuron) WHERE '{ label } ' IN n.synonym "
62+ f"RETURN n.short_form LIMIT 1"
63+ ])
64+ dc = dict_cursor (results )
65+ if dc :
66+ return dc [0 ]["n.short_form" ]
67+
4268 raise ValueError (
4369 f"Neuron type not found in VFB: '{ label } '. "
4470 "Use list_connectome_datasets() or check spelling."
0 commit comments