-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix naming neuroncriteria #42
Fix naming neuroncriteria #42
Conversation
property names can now contain special characters, for example "-" as seen in recent database. see https://neo4j.com/docs/cypher-manual/current/syntax/naming/
With the high number of name changes in ROIs and neurons, it would be nice to have this "safety net" for the queries in neuprint-python. |
For this minimal test: from neuprint import Client, fetch_neurons, NeuronCriteria as NC
c = Client(<SERVER>, <DATASET>)
target_inst = 'ER4d_R'
n_target_all, _ = fetch_neurons(NC(instance= target_inst)) the ---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
~/srcs/neuprint-python/neuprint/client.py in wrapper(*args, **kwargs)
227 try:
--> 228 return f(*args, **kwargs)
229 except RequestException as ex:
~/srcs/neuprint-python/neuprint/client.py in _fetch(self, url, json, ispost)
382 r = self.session.get(url, verify=self.verify)
--> 383 r.raise_for_status()
384 return r
~/srcs/neuprint-python/.pixi/envs/default/lib/python3.9/site-packages/requests/models.py in raise_for_status(self)
952 if http_error_msg:
--> 953 raise HTTPError(http_error_msg, response=self)
954
HTTPError: 400 Client Error: Bad Request for url: <SERVER>/api/custom/custom
The above exception was the direct cause of the following exception:
HTTPError Traceback (most recent call last)
/tmp/ipykernel_12951/1932216900.py in <module>
3
4 target_inst = 'ER4d_R'
----> 5 n_target_all, _ = fetch_neurons(NC(instance= target_inst))
~/srcs/neuprint-python/neuprint/client.py in wrapper(client, *args, **kwargs)
211 if client is None:
212 client = default_client()
--> 213 return f(*args, **kwargs, client=client)
214
215 wrapper.__signature__ = inspect.signature(f)
~/srcs/neuprint-python/neuprint/queries/neuroncriteria.py in wrapper(*args, **kwargs)
33 for name in argnames:
34 callargs[name] = copy_as_neuroncriteria(callargs[name], callargs.get('client', None))
---> 35 return f(**callargs)
36
37 wrapper.__signature__ = inspect.signature(f)
~/srcs/neuprint-python/neuprint/queries/neurons.py in fetch_neurons(criteria, client)
128 ORDER BY n.bodyId
129 """
--> 130 neuron_df = client.fetch_custom(q)
131 neuron_df, roi_counts_df = _process_neuron_df(neuron_df, client)
132 return neuron_df, roi_counts_df
~/srcs/neuprint-python/neuprint/client.py in fetch_custom(self, cypher, dataset, format)
420 """
421 url = f"{self.server}/api/custom/custom"
--> 422 return self._fetch_cypher(url, cypher, dataset, format)
423
424 def _fetch_cypher(self, url, cypher, dataset, format='pandas'):
~/srcs/neuprint-python/neuprint/client.py in _fetch_cypher(self, url, cypher, dataset, format)
441 logger.debug(f"Performing cypher query against dataset '{dataset}':\n{cypher}")
442
--> 443 result = self._fetch_json(url,
444 json={"cypher": cypher, "dataset": dataset},
445 ispost=True)
~/srcs/neuprint-python/neuprint/client.py in _fetch_json(self, url, json, ispost)
388
389 def _fetch_json(self, url, json=None, ispost=False):
--> 390 r = self._fetch(url, json=json, ispost=ispost)
391 return ujson.loads(r.content)
392
~/srcs/neuprint-python/neuprint/client.py in wrapper(*args, **kwargs)
269 # mark it as already modified it doesn't get modified twice.
270 new_ex.response_content_appended = True
--> 271 raise new_ex from ex
272 return wrapper
273
HTTPError: Error accessing POST <SERVER>/api/custom/custom
Cypher was:
MATCH (n :Neuron)
WHERE
// -- Basic conditions for segment 'n' --
n.instance = 'ER4d_R'
RETURN n.bodyId as bodyId,
n.instance as instance,
n.type as type,
n.pre as pre,
n.post as post,
n.downstream as downstream,
n.upstream as upstream,
n.size as size,
n.status as status,
n.statusLabel as statusLabel,
n.cellBodyFiber as cellBodyFiber,
n.somaLocation as somaLocation,
n.roiInfo as roiInfo,
n.anteriorCervicalRootPosition as anteriorCervicalRootPosition,
n.assignedOlHex1 as assignedOlHex1,
n.assignedOlHex2 as assignedOlHex2,
n.birthtime as birthtime,
n.class as class,
n.dimorphism as dimorphism,
n.entryNerve as entryNerve,
n.exitNerve as exitNerve,
n.flywireId as flywireId,
n.flywireType as flywireType,
n.fru/dsx as fru/dsx,
n.fruDsx as fruDsx,
n.group as group,
n.hemibrainBodyId as hemibrainBodyId,
n.hemibrainType as hemibrainType,
n.itoleeHl as itoleeHl,
n.location as location,
n.locationType as locationType,
n.mancBodyid as mancBodyid,
n.mancGroup as mancGroup,
n.mancType as mancType,
n.matchingNotes as matchingNotes,
n.mcnsSerial as mcnsSerial,
n.posteriorCervicalRootPosition as posteriorCervicalRootPosition,
n.rootSide as rootSide,
n.serialMotif as serialMotif,
n.somaNeuromere as somaNeuromere,
n.somaSide as somaSide,
n.subclass as subclass,
n.superclass as superclass,
n.synonyms as synonyms,
n.synweight as synweight,
n.trumanHl as trumanHl
ORDER BY n.bodyId
Returned Error (400):
Invalid input '/': expected
","
"CALL"
"CREATE"
"DELETE"
"DETACH"
"FOREACH"
"LIMIT"
"LOAD"
"MATCH"
"MERGE"
"OPTIONAL"
"ORDER"
"REMOVE"
"RETURN"
"SET"
"SKIP"
"UNION"
"UNWIND"
"USE"
"WITH"
<EOF> (line 29, column 28 (offset: 1010))
" n.fru/dsx as fru/dsx,"
^ while the |
Yes, I was just rebasing this PR onto my local development branch. Thank you! (Will push soon...) |
Looks like a similar solution was implemented in |
Adding backticks to names in the NeuronCriteria queries (similar and including the change from #41).
This part is not very well tested, but part of code basis that I am using.