Repository navigation
Gene search: several genes and homologs (G3-832, G3-834); fixed identifier choice in gene values (G3-836) - #41
Conversation
…ed one first (G3-836)
GET /genesets/{id}/values?gene_id_type=N returns one identifier of the requested type per
gene, chosen by DISTINCT ON with no ORDER BY, so whichever row Postgres met first won.
GS412566's gene uploaded as ENSMUSG00000089945 came back as ENSMUSG00000038729, which the
Strain Recommender's mESC reference does not hold, so it dropped the gene.
The choice is now ordered: the identifier the uploader used (gsv_source_list, ignoring
case), then the preferred one (ode_pref), then the lowest ode_ref_id. Across species,
map_geneset_homology kept the last homolog returned, in no defined order; the homologs now
come preferred first, then by id, and the first is kept. The rule is on the endpoint.
…r homologs (G3-832, G3-834) `gene` on GET /genesets/search is now a list (repeat the parameter; one still works), at most five, with `gene_match` all (the default) or any. The score cutoffs apply to each gene's own score in the gene set; threshold_mode "first" orders by how many genes pass, so gene sets where all pass lead. `homology` (on by default) widens each gene through extsrc.homology, as ABBA does, so TP53 finds mouse gene sets holding Trp53; false searches the exact gene only. The cutoffs apply to whichever gene matched. Each result of a gene search carries `matched_genes`: which of its genes matched each searched gene, whether it is a homolog, and its score.
… results say which gene matched (G3-832, G3-834) The gene field reads genes as the text search reads words: spaces, commas or AND mean all, OR in capitals means any; AND with OR, or more than five genes, is refused with a message. A homolog checkbox (on by default) sits next to it, both kept in the URL and shared with the analyze page's gene set picker. Each result names the gene it matched, e.g. "Trp53 (homolog of TP53)".
Test Coverage Report |
There was a problem hiding this comment.
🟡 Changes recommended
A moderate active issue means the documented priority rule still fails for gene-symbol requests because the symbol-only prefilter excludes non-preferred uploaded identifiers before ordering.
1 open issue
What changed in this PR
This PR extends gene-set search with multiple genes, configurable homolog matching, per-gene score filtering, and matched-gene annotations, while making gene identifier and homolog selection deterministic.
Changes:
- Adds
all/anymulti-gene search with a five-gene limit, threshold ordering, URL support, and shared UI controls. - Enables homolog-aware searches by default and displays matched-gene metadata in results.
- Adds deterministic identifier and homolog selection rules with backend and frontend test coverage.
| File | Description |
|---|---|
| ui/src/app/search/search-filters.ts | Parses multi-gene expressions, serializes homology settings, and formats matched-gene descriptions. |
| ui/src/app/search/search-filters.spec.ts | Tests multi-gene parsing, homology URL state, descriptions, and matched-gene formatting. |
| ui/src/app/models/gene-set.ts | Adds the optional matched-gene result model. |
| ui/src/app/components/searchfilters/search-filters.component.ts | Adds multi-gene and homolog filter controls with contextual cutoff labels. |
| ui/src/app/components/genesetsearch/geneset-search.component.ts | Updates search help text for multi-gene and homolog searches. |
| ui/src/app/components/genesetsearch/geneset-search.component.spec.ts | Updates search help-text test coverage. |
| ui/src/app/components/genesetlist/genesetlist.component.ts | Exposes matched-gene formatting to the result template. |
| ui/src/app/components/genesetlist/genesetlist.component.html | Displays which genes matched each result. |
| tests/services/test_genset.py | Tests deterministic first-homolog retention during mapping. |
| tests/controllers/test_genesets_search.py | Tests multi-gene request parsing and matched-gene response propagation. |
| src/geneweaver/api/services/geneset.py | Keeps the first ordered homolog for each gene during cross-species mapping. |
| src/geneweaver/api/schemas/search.py | Defines multi-gene, homology, cutoff, and search validation fields. |
| src/geneweaver/api/controller/genesets.py | Documents deterministic identifier and homolog selection behavior. |
| packages/db/tests/unit/query/search/test_genesets.py | Tests generated SQL for multi-gene, threshold, homology, and matched-gene behavior. |
| packages/db/tests/unit/geneset_value/test_by_geneset_id_and_identifier.py | Tests deterministic identifier ordering and parameter binding. |
| packages/db/tests/unit/gene/test_get_homolog_ids_by_ode_id.py | Tests deterministic homolog ordering. |
| packages/db/src/geneweaver/db/query/search/search.py | Builds multi-gene, homolog-aware search SQL and matched-gene result columns. |
| packages/db/src/geneweaver/db/geneset_value.py | Adds deterministic identifier selection ordering. |
| packages/db/src/geneweaver/db/gene.py | Orders homolog identifiers by preference and reference ID. |
Review effort: Lite
| ORDER BY g.ode_gene_id, g.gdb_id, | ||
| -- 1. the identifier the uploader used | ||
| EXISTS ( | ||
| SELECT 1 FROM unnest(gsv.gsv_source_list) AS uploaded(id) | ||
| WHERE lower(uploaded.id) = lower(g.ode_ref_id) | ||
| ) DESC, |
There was a problem hiding this comment.
Fixed in d52e70f, partly as suggested.
Removing the filter alone would make an alias in the upload replace the official symbol. The gene set page has always shown the official symbol, and changing that is a display decision that doesn't belong in G3-836. So the preferred-symbol rule stays, but it's now the first ORDER BY key inside the DISTINCT ON instead of a WHERE filter:
- A gene with a preferred symbol shows it, as before.
- A gene with no preferred symbol now gets the uploaded symbol, or else the lowest one.
The filter used to drop those genes entirely, both when symbols were requested and when symbols were the fallback type. On dev that's 5 genes, all in gene sets (GS135132, GS224150, GS403640, GS224970, GS223142).
I ran the old and new query side by side on dev data:
- those 5 genes come back;
- no other row changes, including AKAP2 in GS404648, GS227189 and GS405734.
Tests added for the symbol ordering and for "no ode_pref in the WHERE". The rule is documented in the docstring and on GET /genesets/{id}/values.
…set's values (G3-836) by_geneset_id_and_identifier kept only preferred symbols with a WHERE filter, so a gene whose symbols are all non-preferred lost its row whenever symbols were requested, or were the fallback type. On dev that is 5 genes, all in gene sets (GS135132, GS224150, GS403640, GS224970, GS223142). The preferred symbol is now the first ORDER BY key inside the DISTINCT ON instead of a filter. Symbols still show the official symbol ahead of an alias in the upload, as the gene set page always has; a gene with no preferred symbol now falls through to the uploaded symbol, then the lowest. Checked against dev with the old and new query side by side: those 5 genes come back, and no other row changes. Raised by Copilot's review on #41.
Review follow-up (2026-11-11)The review (PASS on
Copilot's comment (symbol filter): fixed in d52e70f. See the reply on the thread.
|
…3-832) Each control in the gene set search filters (species, curation tier, score type, size, genes, homologs, the score cutoffs and both ways of using them) has an info icon. Its tooltip opens on hover and on keyboard focus, and the icon's label gives screen readers the same text. The text lives in FILTER_HELP beside the filters themselves. The tier wording follows odestatic.curation_levels, and the cutoff wording follows gene_threshold_filter: a cutoff applies only to its own score type, to each searched gene, with AND every gene passing and with OR one. The homology help no longer uses TP53 as its example: on dev "Tp53" is an alternate name of mouse Trp53, so TP53 matches it directly and is not a homolog match. Drd2 finding zebrafish drd2a is.
…every group sharing its name (G3-834) Homologs came from every homology group of every gene whose identifier matched, in any species, so another species' gene that only shares the name brought in an unrelated group. On dev, Th matched fly Trxr1 by its alias "TH" and added 590 gene sets holding Txnrd2; Comt matched fly comatose, officially "comt", and added 1,149 holding Nsf. Now a group is used when it is the one the identifier names in the most species: ranked by species with it as a gene's official symbol, then by species matching it at all, ties all kept. The group of a mouse or human gene the identifier officially names is always used too, so a typed mouse or human symbol never loses its own gene's homologs. Direct matches are unchanged. On dev (signed out): Th 4,279 -> 3,673 (only worm cat-2 added), Comt 4,810 -> 3,658, Drd2 4,504 unchanged; the count query runs in the same ~0.3 s. The API's homology description and two UI comments gave TP53 -> Trp53 as a homolog example, but Trp53 matches TP53 directly by alias; they now use Drd2 -> dop-3.
Brings in PR 40. One conflict, in filterProblem (ui/src/app/search/search-filters.ts): main added the p/q 0-to-1 range check and this branch returns the gene-parsing error. Both are kept: the range check first, then parseGenes(filters.gene).error.

Summary
Three of the five tickets get code here. G3-833 and G3-835 have no changes in this PR (reasons below).
G3-836: gene values pick a gene's identifier by a fixed rule
GET /genesets/{id}/values?gene_id_type=Npicked one identifier per gene withDISTINCT ONand noORDER BY, so the choice was arbitrary. It is now ordered:gsv_source_list, ignoring case), if it is of the requested type;ode_pref);ode_ref_id.Symbols are the one exception: when gene symbols are requested, or a gene has no identifier of the requested type and falls back to its symbol, the official (preferred) symbol comes first, ahead of an alias the uploader typed, so the gene set page keeps showing official symbols (d52e70f). A gene with no preferred symbol still gets a row; before d52e70f a filter dropped 5 such genes on dev.
Cross-species mapping (
map_geneset_homology) used to keep the last homolog returned. It now keeps the first, with homologs ordered preferred first, then by id. The rule is documented on the endpoint. Noall_idsoption was added; the ticket listed it as optional.G3-832: several genes in one search
geneonGET /genesets/searchis now a list. Repeat the parameter (gene=Drd2&gene=Tp53); onegenestill works. At most 5. The API trims each gene, drops blanks and removes duplicates, ignoring case.gene_match:all(default) orany.threshold_mode=firstorders by how many genes pass, so gene sets where all pass come first.Drd2, Tp53/Drd2 AND Tp53(spaces and semicolons too) as all, andDrd2 OR Thas any. Mixing AND with OR, or giving more than 5 genes, is refused with a message. The field is kept in the URL and shared with the analyze page's gene set picker.FILTER_HELPinsearch-filters.ts.G3-834: homologs in gene search
homologyis on by default in the API (the DB query builder's own default is off). Each gene is widened throughextsrc.homology, soDrd2also finds zebrafish gene sets holding drd2a and worm gene sets holding dop-3.homology=falsesearches the exact gene only. (TP53is not an example: "Tp53" is an alternate name of mouse Trp53, so it matches directly.)matched_genes(query,gene,homolog,value), and the results table shows e.g. Matched: Drd2, dop-3 (homolog of Drd2).homology=offwhen cleared.Fixed: homologs came from genes that only share the name
Before 30ec9b5, homologs came from every group of every matching gene, so another species' gene that only shares the name brought in an unrelated group. Measured on dev with this PR deployed, signed out:
On dev, 4,610 of 23,869 mouse and human official symbols match genes in more than one homology group. 414 tie for the top rank and keep all their tied groups; they are mostly mouse and human genes that Homologene puts in separate groups. Without the mouse/human clause, 41 symbols would have lost their own gene's group. The count query takes the same time as before (about 0.3 s warm for Th, Tp53, Trp53 and Clcnkb).
Known, left as it is
Thfinds fly gene sets holding Trxr1 even with homologs off, labelled by the gene that matched (Trxr1). This predates the PR and is needed for alias and ID lookups (TP53 → mouse Trp53). Narrowing it would also drop real matches, such as zebrafish comta forcomt.Not in this PR
Testing
pytest packages/db/tests/unit: 56,007 passed.pytest tests: 732 passed, 30 skipped, and 1 failed:test_namespace_integrity.py::test_first_party_subpackage_is_importable[client], which already failed at 56cb8f1, before 30ec9b5. Whether it also fails onmainwas not rechecked.jest: 416 passed at 56cb8f1 (the info icons added 6). 30ec9b5 changes only comments in the UI. The production build reports the same initial-bundle budget error as unchangedmain(1.72 MB); this change adds about 3 kB.firstordering,matched_genes;