From e7191463db66fcc3c2618ccdf004e798e1d3ac6a Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 3 Oct 2026 16:14:49 +0000 Subject: Add ProbeSetXRef endpoints: datasets, probesets, probeset values. The expression (ProbeSet) counterpart to the PublishXRef endpoints: ProbeSetXRef has no single Id column of its own (its primary key is DataId; the natural key is the pair (ProbeSetFreezeId, ProbeSetId)), so a trait here is addressed by dataset name plus ProbeSet.Name instead of a single numeric trait id. * src/db.rs (Dataset): New struct, one ProbeSetFreeze row. (get_group_datasets): New function. Joins ProbeSetFreeze and ProbeFreeze by group Id, matching GeneNetwork2's wqflask.api.router.get_datasets_for_group. (get_dataset_by_name): New function. Matches Name, Name2, FullName, ShortName or numeric Id, matching wqflask.api.router.get_dataset_info's ProbeSet-branch matching logic. A dataset name is globally unique on its own, unlike a group's traits, so this isn't scoped by group. (ProbeSetInfo): New struct, a probe's ProbeSetXRef mapping stats plus its ProbeSet gene annotation. (get_dataset_probeset_info): New function, matching wqflask.api.router.get_trait_info's ProbeSet branch. (ProbeSetValue): New struct. (get_dataset_probeset_values): New function, matching wqflask.api.router.trait_sample_data's ProbeSet branch. * src/lib.rs (DatasetProbesetLookup): New enum, the expression-dataset equivalent of GroupTraitLookup -- distinguishes a missing dataset from a missing probeset in an existing dataset. (group_datasets): New handler for GET /groups/{group}/datasets. (dataset_by_name): New handler for GET /datasets/{dataset}. (get_dataset_probeset_info_result, dataset_probeset_info): New function and handler for GET /datasets/{dataset}/probesets/{probeset}. (get_dataset_probeset_values_result, dataset_probeset_values): New function and handler for GET /datasets/{dataset}/probesets/{probeset}/values. (app): Register all four. * tests/group_datasets.rs, tests/dataset_by_name.rs, tests/dataset_probeset_info.rs, tests/dataset_probeset_values.rs, test/python/test_group_datasets.py, test/python/test_dataset_by_name.py, test/python/test_dataset_probeset_info.py, test/python/test_dataset_probeset_values.py: New files. Br_U_0803_M (dataset) / 100001_at (probeset, gene symbol Cd3g) in BXD are real rows used as fixtures. * tests/openapi.rs, test/python/test_openapi.py: Check the four new paths are in the generated spec. * README.md: Document the four new endpoints and list the new test files. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01XDDpXvZBQat9uSgDeEMJ8d --- test/python/test_dataset_by_name.py | 61 ++++++++++++++++++++++ test/python/test_dataset_probeset_info.py | 79 +++++++++++++++++++++++++++++ test/python/test_dataset_probeset_values.py | 79 +++++++++++++++++++++++++++++ test/python/test_group_datasets.py | 62 ++++++++++++++++++++++ test/python/test_openapi.py | 4 ++ 5 files changed, 285 insertions(+) create mode 100644 test/python/test_dataset_by_name.py create mode 100644 test/python/test_dataset_probeset_info.py create mode 100644 test/python/test_dataset_probeset_values.py create mode 100644 test/python/test_group_datasets.py (limited to 'test/python') diff --git a/test/python/test_dataset_by_name.py b/test/python/test_dataset_by_name.py new file mode 100644 index 0000000..082f758 --- /dev/null +++ b/test/python/test_dataset_by_name.py @@ -0,0 +1,61 @@ +"""Mirrors tests/dataset_by_name.rs. Needs a live MariaDB (SQL_URI); +skips with a message rather than failing when none is reachable, same as +test_group_by_name.py. +""" + +import http.client +import json +import socket +import unittest + +from server_test_case import HOST, PORT, ServerTestCase + + +def database_reachable(): + try: + with socket.create_connection(("127.0.0.1", 3306), timeout=0.5): + return True + except OSError: + return False + + +class DatasetByNameTest(ServerTestCase): + def test_dataset_by_name_returns_dataset_row(self): + if not database_reachable(): + self.skipTest("no database on 127.0.0.1:3306") + + conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10) + try: + conn.request("GET", "/datasets/Br_U_0803_M") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 200) + + dataset = json.loads(body) + self.assertEqual(dataset["name"], "Br_U_0803_M") + self.assertEqual(dataset["full_name"], "Brain U74Av2 08/03 MAS5") + self.assertEqual(dataset["data_scale"], "log2") + + def test_dataset_by_name_unknown_dataset_returns_404(self): + if not database_reachable(): + self.skipTest("no database on 127.0.0.1:3306") + + conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10) + try: + conn.request("GET", "/datasets/not-a-real-dataset") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 404) + + error = json.loads(body) + self.assertEqual(error["status"], 404) + self.assertEqual(error["code"], "dataset_not_found") + self.assertEqual(error["operation_id"], "dataset_by_name") + + +if __name__ == "__main__": + unittest.main() diff --git a/test/python/test_dataset_probeset_info.py b/test/python/test_dataset_probeset_info.py new file mode 100644 index 0000000..cfb219c --- /dev/null +++ b/test/python/test_dataset_probeset_info.py @@ -0,0 +1,79 @@ +"""Mirrors tests/dataset_probeset_info.rs. Needs a live MariaDB +(SQL_URI); skips with a message rather than failing when none is +reachable, same as test_group_by_name.py. +""" + +import http.client +import json +import socket +import unittest + +from server_test_case import HOST, PORT, ServerTestCase + + +def database_reachable(): + try: + with socket.create_connection(("127.0.0.1", 3306), timeout=0.5): + return True + except OSError: + return False + + +class DatasetProbesetInfoTest(ServerTestCase): + def test_dataset_probeset_info_returns_gene_annotation(self): + if not database_reachable(): + self.skipTest("no database on 127.0.0.1:3306") + + conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10) + try: + conn.request("GET", "/datasets/Br_U_0803_M/probesets/100001_at") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 200) + + info = json.loads(body) + self.assertEqual(info["name"], "100001_at") + self.assertEqual(info["symbol"], "Cd3g") + self.assertIsInstance(info["mean"], float) + + def test_dataset_probeset_info_unknown_dataset_returns_404(self): + if not database_reachable(): + self.skipTest("no database on 127.0.0.1:3306") + + conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10) + try: + conn.request("GET", "/datasets/not-a-real-dataset/probesets/100001_at") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 404) + + error = json.loads(body) + self.assertEqual(error["status"], 404) + self.assertEqual(error["code"], "dataset_not_found") + self.assertEqual(error["operation_id"], "dataset_probeset_info") + + def test_dataset_probeset_info_unknown_probeset_in_dataset_returns_404(self): + if not database_reachable(): + self.skipTest("no database on 127.0.0.1:3306") + + conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10) + try: + conn.request("GET", "/datasets/Br_U_0803_M/probesets/not-a-real-probeset") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 404) + + error = json.loads(body) + self.assertEqual(error["status"], 404) + self.assertEqual(error["code"], "probeset_not_found") + self.assertEqual(error["operation_id"], "dataset_probeset_info") + + +if __name__ == "__main__": + unittest.main() diff --git a/test/python/test_dataset_probeset_values.py b/test/python/test_dataset_probeset_values.py new file mode 100644 index 0000000..3477fa7 --- /dev/null +++ b/test/python/test_dataset_probeset_values.py @@ -0,0 +1,79 @@ +"""Mirrors tests/dataset_probeset_values.rs. Needs a live MariaDB +(SQL_URI); skips with a message rather than failing when none is +reachable, same as test_group_by_name.py. +""" + +import http.client +import json +import socket +import unittest + +from server_test_case import HOST, PORT, ServerTestCase + + +def database_reachable(): + try: + with socket.create_connection(("127.0.0.1", 3306), timeout=0.5): + return True + except OSError: + return False + + +class DatasetProbesetValuesTest(ServerTestCase): + def test_dataset_probeset_values_returns_strain_values(self): + if not database_reachable(): + self.skipTest("no database on 127.0.0.1:3306") + + conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10) + try: + conn.request("GET", "/datasets/Br_U_0803_M/probesets/100001_at/values") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 200) + + values = json.loads(body) + self.assertTrue(values) + bxd1 = next(v for v in values if v["name"] == "BXD1") + self.assertIsInstance(bxd1["value"], float) + + def test_dataset_probeset_values_unknown_dataset_returns_404(self): + if not database_reachable(): + self.skipTest("no database on 127.0.0.1:3306") + + conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10) + try: + conn.request("GET", "/datasets/not-a-real-dataset/probesets/100001_at/values") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 404) + + error = json.loads(body) + self.assertEqual(error["status"], 404) + self.assertEqual(error["code"], "dataset_not_found") + self.assertEqual(error["operation_id"], "dataset_probeset_values") + + def test_dataset_probeset_values_unknown_probeset_in_dataset_returns_404(self): + if not database_reachable(): + self.skipTest("no database on 127.0.0.1:3306") + + conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10) + try: + conn.request("GET", "/datasets/Br_U_0803_M/probesets/not-a-real-probeset/values") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 404) + + error = json.loads(body) + self.assertEqual(error["status"], 404) + self.assertEqual(error["code"], "probeset_not_found") + self.assertEqual(error["operation_id"], "dataset_probeset_values") + + +if __name__ == "__main__": + unittest.main() diff --git a/test/python/test_group_datasets.py b/test/python/test_group_datasets.py new file mode 100644 index 0000000..d338075 --- /dev/null +++ b/test/python/test_group_datasets.py @@ -0,0 +1,62 @@ +"""Mirrors tests/group_datasets.rs. Needs a live MariaDB (SQL_URI); +skips with a message rather than failing when none is reachable, same as +test_group_by_name.py. +""" + +import http.client +import json +import socket +import unittest + +from server_test_case import HOST, PORT, ServerTestCase + + +def database_reachable(): + try: + with socket.create_connection(("127.0.0.1", 3306), timeout=0.5): + return True + except OSError: + return False + + +class GroupDatasetsTest(ServerTestCase): + def test_group_datasets_bxd_returns_datasets(self): + if not database_reachable(): + self.skipTest("no database on 127.0.0.1:3306") + + conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10) + try: + conn.request("GET", "/groups/BXD/datasets") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 200) + + datasets = json.loads(body) + self.assertTrue(datasets) + names = {record["name"] for record in datasets} + self.assertIn("Br_U_0803_M", names) + + def test_group_datasets_unknown_group_returns_404(self): + if not database_reachable(): + self.skipTest("no database on 127.0.0.1:3306") + + conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10) + try: + conn.request("GET", "/groups/not-a-real-group/datasets") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 404) + + error = json.loads(body) + self.assertEqual(error["status"], 404) + self.assertEqual(error["code"], "group_not_found") + self.assertEqual(error["operation_id"], "group_datasets") + self.assertEqual(error["next"], "/groups") + + +if __name__ == "__main__": + unittest.main() diff --git a/test/python/test_openapi.py b/test/python/test_openapi.py index 3b4b704..c66a0c8 100644 --- a/test/python/test_openapi.py +++ b/test/python/test_openapi.py @@ -30,6 +30,10 @@ class OpenApiTest(ServerTestCase): "/groups/{group}/strains", "/groups/{group}/traits/{trait_id}", "/groups/{group}/traits/{trait_id}/values", + "/groups/{group}/datasets", + "/datasets/{dataset}", + "/datasets/{dataset}/probesets/{probeset}", + "/datasets/{dataset}/probesets/{probeset}/values", ): self.assertIn(path, doc["paths"]) -- cgit 1.4.1