extend the Cypher + preview_columns for three queries#42
Merged
Conversation
# Extends the v1.10.1 channel/template/technique pattern. Adds:
# - type = pipe-joined parent class labels (n2 -[:INSTANCEOF]-> Class)
# matches v2 prod's `Type` column from SOLR's `types` collection
# - template = `[symbol](short_form)` markdown of the alignment template
# - technique = imaging technique label (channel -[:is_specified_output_of]-> Class)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the get_similar_neurons Cypher query output to align with the v1.10.1 “channel/template/technique” pattern, adding extra metadata columns intended to match v2 production table fields.
Changes:
- Adds
type,template, andtechniquefields to theget_similar_neuronsCypherRETURN. - Updates the depicts match to bind a
channelnode and derivetechniquevia:is_specified_output_of. - Makes
tagsgeneration null-safe by coalescinguniqueFacetsto an empty list.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| WITH n2, r, c2, rx, site, channel, ri, templ, technique | ||
| OPTIONAL MATCH (n2)-[:INSTANCEOF]->(typ:Class) | ||
| WITH n2, r, rx, site, channel, ri, templ, technique, | ||
| apoc.text.join(collect(DISTINCT coalesce(typ.label, '')), '; ') AS type |
Comment on lines
+2476
to
2482
| apoc.text.join(coalesce(n2.uniqueFacets, []), '|') AS tags, | ||
| type, | ||
| REPLACE(apoc.text.format("[%s](%s)",[COALESCE(site.symbol[0],site.label),site.short_form]), '[null](null)', '') AS source, | ||
| REPLACE(apoc.text.format("[%s](%s)",[rx.accession[0], (site.link_base[0] + rx.accession[0])]), '[null](null)', '') AS source_id, | ||
| REPLACE(apoc.text.format("[%s](%s)",[COALESCE(templ.symbol[0],templ.label),templ.short_form]), '[null](null)', '') AS template, | ||
| coalesce(technique.label, '') AS technique, | ||
| REPLACE(apoc.text.format("[](%s)",[COALESCE(n2.symbol[0],n2.label) + " aligned to " + COALESCE(templ.symbol[0],templ.label), REPLACE(COALESCE(ri.thumbnail[0],""),"thumbnailT.png","thumbnail.png"), COALESCE(n2.symbol[0],n2.label) + " aligned to " + COALESCE(templ.symbol[0],templ.label), templ.short_form + "," + n2.short_form]), "[](null)", "") as thumbnail |
Two issues raised: 1. `type` delimiter mismatch — doc says "pipe-joined" but Cypher joined with "; ". Switch to "|" and filter empties so an INSTANCEOF-less row doesn't produce `; ` artefacts. Uses `[l IN collect(DISTINCT typ.label) WHERE l IS NOT NULL AND l <> '']` to drop nulls/empties before the join. 2. Downstream wiring missed new columns. `template` is a markdown link `[symbol](short_form)` so it needs encode_markdown_links the same as name/source/source_id/thumbnail. The non-DataFrame response builder only listed the old keys, silently dropping type/template/technique when return_dataframe=False. Added the three columns to both the headers dict (Type/Template/Imaging Technique, plain text + markdown) and the row key extraction so the API surface matches the Cypher.
Comment on lines
+2467
to
+2472
| OPTIONAL MATCH (n2)<-[:depicts]-(channel:Individual)-[ri:in_register_with]->(:Template)-[:depicts]->(templ:Template) | ||
| OPTIONAL MATCH (channel)-[:is_specified_output_of]->(technique:Class) | ||
| WITH n2, r, c2, rx, site, channel, ri, templ, technique | ||
| OPTIONAL MATCH (n2)-[:INSTANCEOF]->(typ:Class) | ||
| WITH n2, r, rx, site, channel, ri, templ, technique, | ||
| apoc.text.join([l IN collect(DISTINCT typ.label) WHERE l IS NOT NULL AND l <> ''], '|') AS type |
Comment on lines
2507
to
+2514
| "score": {"title": "Score", "type": "numeric", "order": 1, "sort": {0: "Desc"}}, | ||
| "name": {"title": "Name", "type": "markdown", "order": 1, "sort": {1: "Asc"}}, | ||
| "tags": {"title": "Tags", "type": "tags", "order": 2}, | ||
| "source": {"title": "Source", "type": "metadata", "order": 3}, | ||
| "source_id": {"title": "Source ID", "type": "metadata", "order": 4}, | ||
| "type": {"title": "Type", "type": "text", "order": 3}, | ||
| "source": {"title": "Source", "type": "metadata", "order": 4}, | ||
| "source_id": {"title": "Source ID", "type": "metadata", "order": 5}, | ||
| "template": {"title": "Template", "type": "markdown", "order": 6}, | ||
| "technique": {"title": "Imaging Technique", "type": "text", "order": 7}, |
Contributor
Author
There was a problem hiding this comment.
Good catch from the reviewer — I'd left the schema in SimilarMorphologyTo_to_schema unchanged, so term-info previews would still show the old 5-column set even though /run_query now returns the new fields. Fixed in the working tree, bundled into the same script
Reviewer flagged that SimilarMorphologyTo_to_schema's preview_columns still listed only ["id","score","name","tags","thumbnail"] — so the term-info preview wouldn't surface the new type/template/technique columns even though /run_query now returns them. Updated to ["id","name","score","tags","type","template","technique", "thumbnail"], matching the v1.10.1 SimilarMorphologyToPartOf* preview shape plus the new type column this PR adds. source/source_id are deliberately omitted from the preview — they're noisy and only meaningful in the full table.
Reviewer flagged a cartesian-product risk in the previous version:
chained OPTIONAL MATCHes for (xref, site), (channel, ri, templ),
(technique), and (typ) compounded into N × M × K rows per n2 before
RETURN DISTINCT collapsed them. On densely-typed or multi-aligned
neurons this is wasteful, and `type` was being aggregated within the
(channel, technique) grouping rather than once per n2.
Refactored each optional branch into a CALL subquery scoped to n2:
CALL { WITH n2
OPTIONAL MATCH (n2)-[:INSTANCEOF]->(typ:Class)
RETURN apoc.text.join([l IN collect(...) WHERE ...], '|') AS type }
CALL { WITH n2
OPTIONAL MATCH (n2)-[rx:database_cross_reference]->(site:Site)
WHERE site.is_data_source
WITH rx, site LIMIT 1
RETURN rx, site }
CALL { WITH n2
OPTIONAL MATCH (n2)<-[:depicts]-(channel)-[ri:in_register_with]->...
OPTIONAL MATCH (channel)-[:is_specified_output_of]->(technique:Class)
WITH ri, templ, technique LIMIT 1
RETURN ri, templ, technique }
`type` aggregates internally (always 1 row, no LIMIT needed).
Cross-ref and alignment pick a single representative — matches what
the v2 row needs and what prod's `apoc.cypher.run('... LIMIT 5'/'10')`
pattern already does inside the XMI.
`WITH DISTINCT r, n2` upfront drops the c1/c2 cartesian from the
INSTANCEOF anchors. RETURN no longer needs DISTINCT — the row key is
guaranteed unique by construction.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extends the v1.10.1 channel/template/technique pattern. Adds: