Skip to content

extend the Cypher + preview_columns for three queries#42

Merged
Robbie1977 merged 5 commits into
mainfrom
feature/extend-preview-columns-for-v2-parity
May 28, 2026
Merged

extend the Cypher + preview_columns for three queries#42
Robbie1977 merged 5 commits into
mainfrom
feature/extend-preview-columns-for-v2-parity

Conversation

@Robbie1977
Copy link
Copy Markdown
Contributor

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)

# 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)
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and technique fields to the get_similar_neurons Cypher RETURN.
  • Updates the depicts match to bind a channel node and derive technique via :is_specified_output_of.
  • Makes tags generation null-safe by coalescing uniqueFacets to an empty list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/vfbquery/vfb_queries.py Outdated
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](%s '%s')](%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]( 'null')](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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread src/vfbquery/vfb_queries.py Outdated
Comment thread src/vfbquery/vfb_queries.py Outdated
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},
Copy link
Copy Markdown
Contributor Author

@Robbie1977 Robbie1977 May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/vfbquery/vfb_queries.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Robbie1977 Robbie1977 merged commit 0107c22 into main May 28, 2026
0 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants