From 54f138802bed2040531b3da3df0b30895d881bc8 Mon Sep 17 00:00:00 2001 From: Pjotr Date: Thu, 8 Oct 2026 06:53:15 +0000 Subject: * src/routes/publications.rs: add GET /publications/{pubmed_id}/traits. Lists the published traits (across groups) a publication reports. Datasets the caller may not view are left out, using the same check as GET /traits/{dataset} (traits.rs is_authorised is now pub(crate)). * src/db.rs (TraitInfo, trait_info_sql): TraitInfo gains `dataset`, `abbreviation` (Phenotype.Post_publication_abbreviation, else Pre) and `url` (the GeneNetwork show_trait page). The three TraitInfo queries now share one SELECT. New get_group_traits_by_abbreviation and get_publication_traits. * src/routes/groups.rs (group_traits): add ?abbreviation= filter. * src/db.rs (Group), src/routes/groups.rs (groups): groups carry `family` and `species`; add family, species and q filters. * src/routes/search.rs (search): add `page` (gn3's page unsorted, a page of the ranked list with `sort`); declare `pubmed_id`; hits gain `abbreviation` next to `locus` (get_publish_annotations). * src/db.rs (LRS_PER_LOD): LOD = LRS / 4.604, the divisor the benchmark's RDF data uses (was 4.61). * tests, test/python, test/data/benchmark_search.json, README.md: cover all of the above; tests/benchmark.rs now also answers rows 11, 16, 25, 30, 34 and 37 of small_benchmark.csv, and compares LOD exactly. Co-Authored-By: Claude Sonnet 5.5 --- test/python/test_search.py | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'test/python/test_search.py') diff --git a/test/python/test_search.py b/test/python/test_search.py index bfd1d38..aea1e20 100644 --- a/test/python/test_search.py +++ b/test/python/test_search.py @@ -49,6 +49,10 @@ class Gn3StubHandler(http.server.BaseHTTPRequestHandler): with open(SEROTONIN_FIXTURE, "rb") as fixture: body = fixture.read() self.send_response(http.client.OK) + elif "alcohol" in query.get("query", [""])[0] and query.get("page") == ["2"]: + # Past the end: an unsorted /search forwards `page` to gn3. + body = b"[]" + self.send_response(http.client.OK) elif "boom" in query.get("query", [""])[0]: body = b'{"error": "gn3 exploded"}' self.send_response(http.client.INTERNAL_SERVER_ERROR) @@ -176,7 +180,7 @@ class SearchTest(ServerTestCase): lods = [hit["lod"] for hit in hits] self.assertEqual(lods, sorted(lods, reverse=True)) for hit in hits: - self.assertAlmostEqual(hit["lod"], hit["lrs"] / 4.61) + self.assertAlmostEqual(hit["lod"], hit["lrs"] / 4.604) male_midbrain = [ hit @@ -189,7 +193,7 @@ class SearchTest(ServerTestCase): if "5-hydroxytryptamine (5-HT, serotonin) level" in hit["description"] ) self.assertEqual(serotonin["name"], "17985") - self.assertAlmostEqual(serotonin["lod"], 2.603, places=3) + self.assertAlmostEqual(serotonin["lod"], 2.6063, places=4) self.assertAlmostEqual(serotonin["additive"], -1.3041, places=4) self.assertEqual(serotonin["geno_chr"], "16") @@ -197,14 +201,16 @@ class SearchTest(ServerTestCase): # has the higher LOD: "serotonin" is ambiguous between the two. top = male_midbrain[0] self.assertEqual(top["name"], "17994") - self.assertAlmostEqual(top["lod"], 3.577, places=3) + self.assertAlmostEqual(top["lod"], 3.5819, places=4) self.assertAlmostEqual(top["additive"], 233.99, places=2) # The peak marker's name comes from PublishXRef (needs a live # MariaDB); without one `locus` is null and the above still holds. + self.assertEqual(serotonin["pubmed_id"], 24102824) if database_reachable(): self.assertEqual(serotonin["locus"], "rsm10000012461") self.assertEqual(top["locus"], "rsm10000013922") + self.assertEqual(serotonin["abbreviation"], "5HT_MB_M") def test_search_orders_ascending(self): self.require_auth() @@ -218,6 +224,32 @@ class SearchTest(ServerTestCase): self.assertEqual(lrs[0], min_lrs) self.assertEqual(lrs, sorted(lrs)) + def test_search_pages(self): + # Unsorted, `page` is forwarded to gn3 (the stub's page 2 is + # empty); sorted, pages come from the ranked list (the recorded + # 119 serotonin hits: 100, then 19, then none). + self.require_auth() + + status, body = self.get("/search?q=alcohol&page=2") + self.assertEqual(status, http.client.OK) + self.assertEqual(body["data"], []) + + sorted_uri = ( + "/search?q=serotonin%20AND%20midbrain%20AND%20group:BXD" + "&sort=lod&limit=100" + ) + _, page1 = self.get(sorted_uri) + _, page2 = self.get(sorted_uri + "&page=2") + _, page3 = self.get(sorted_uri + "&page=3") + self.assertEqual(len(page1["data"]), 100) + self.assertEqual(len(page2["data"]), 19) + self.assertEqual(page3["data"], []) + self.assertGreaterEqual(page1["data"][-1]["lod"], page2["data"][0]["lod"]) + + status, body = self.get("/search?q=alcohol&page=0") + self.assertEqual(status, http.client.BAD_REQUEST) + self.assertIn("page", body["detail"]) + def test_search_forwards_gn3_parse_errors(self): self.require_auth() -- cgit 1.4.1