From 6a0c58a24ac7d4c32b7aa20479843ace20852816 Mon Sep 17 00:00:00 2001 From: EddieLF <34049565+EddieLF@users.noreply.github.com> Date: Wed, 19 Jun 2024 10:46:19 +1000 Subject: [PATCH] Get_cram_paths external IDs fix (#828) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix analysis table get_cram_paths function with external_id changes * Bump version: 7.1.0 → 7.1.1 * Also rename p.id; return only the primary external_id Add a test case that exercises this code. * Rename table alias to the conventional 'peid.' --------- Co-authored-by: John Marshall --- .bumpversion.cfg | 2 +- api/server.py | 2 +- db/python/tables/analysis.py | 12 +++++++----- deploy/python/version.txt | 2 +- setup.py | 2 +- test/test_analysis.py | 24 ++++++++++++++++++++++++ web/package.json | 2 +- 7 files changed, 36 insertions(+), 10 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 73c00e4b3..4eda41cd7 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 7.1.0 +current_version = 7.1.1 commit = True tag = False parse = (?P\d+)\.(?P\d+)\.(?P[A-z0-9-]+) diff --git a/api/server.py b/api/server.py index 82b8d32fd..707100960 100644 --- a/api/server.py +++ b/api/server.py @@ -20,7 +20,7 @@ from db.python.utils import get_logger # This tag is automatically updated by bump2version -_VERSION = '7.1.0' +_VERSION = '7.1.1' logger = get_logger() diff --git a/db/python/tables/analysis.py b/db/python/tables/analysis.py index 8cb6c4512..34d99174b 100644 --- a/db/python/tables/analysis.py +++ b/db/python/tables/analysis.py @@ -13,6 +13,7 @@ to_db_json, ) from models.enums import AnalysisStatus +from models.models import PRIMARY_EXTERNAL_ORG from models.models.analysis import AnalysisInternal from models.models.audit_log import AuditLogInternal from models.models.project import ProjectId @@ -413,12 +414,13 @@ async def get_sample_cram_path_map_for_seqr( ) -> List[dict[str, str]]: """Get (ext_sample_id, cram_path, internal_id) map""" - values: dict[str, Any] = {'project': project} + values: dict[str, Any] = {'project': project, 'PRIMARY_EXTERNAL_ORG': PRIMARY_EXTERNAL_ORG} filters = [ 'a.active', 'a.type = "cram"', 'a.status = "completed"', - 'p.project = :project', + 'peid.project = :project', + 'peid.name = :PRIMARY_EXTERNAL_ORG', ] if sequencing_types: if len(sequencing_types) == 1: @@ -431,16 +433,16 @@ async def get_sample_cram_path_map_for_seqr( filters.append('JSON_VALUE(a.meta, "$.sequencing_type") ' + seq_check) if participant_ids: - filters.append('p.id IN :pids') + filters.append('peid.participant_id IN :pids') values['pids'] = list(participant_ids) _query = f""" -SELECT p.external_id as participant_id, a.output as output, sg.id as sequencing_group_id +SELECT peid.external_id as participant_id, a.output as output, sg.id as sequencing_group_id FROM analysis a INNER JOIN analysis_sequencing_group a_sg ON a_sg.analysis_id = a.id INNER JOIN sequencing_group sg ON a_sg.sequencing_group_id = sg.id INNER JOIN sample s ON sg.sample_id = s.id -INNER JOIN participant p ON s.participant_id = p.id +INNER JOIN participant_external_id peid ON s.participant_id = peid.participant_id WHERE {' AND '.join(filters)} ORDER BY a.timestamp_completed DESC; diff --git a/deploy/python/version.txt b/deploy/python/version.txt index a3fcc7121..21c8c7b46 100644 --- a/deploy/python/version.txt +++ b/deploy/python/version.txt @@ -1 +1 @@ -7.1.0 +7.1.1 diff --git a/setup.py b/setup.py index b5f0be4f6..c2078672e 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ setup( name=PKG, # This tag is automatically updated by bump2version - version='7.1.0', + version='7.1.1', description='Python API for interacting with the Sample API system', long_description=readme, long_description_content_type='text/markdown', diff --git a/test/test_analysis.py b/test/test_analysis.py index 46d4b7bfc..5e55328e4 100644 --- a/test/test_analysis.py +++ b/test/test_analysis.py @@ -3,6 +3,7 @@ from db.python.layers.analysis import AnalysisLayer from db.python.layers.assay import AssayLayer +from db.python.layers.participant import ParticipantLayer from db.python.layers.sample import SampleLayer from db.python.layers.sequencing_group import SequencingGroupLayer from db.python.tables.analysis import AnalysisFilter @@ -12,6 +13,7 @@ PRIMARY_EXTERNAL_ORG, AnalysisInternal, AssayUpsertInternal, + ParticipantUpsertInternal, SampleUpsertInternal, SequencingGroupUpsertInternal, ) @@ -20,6 +22,8 @@ class TestAnalysis(DbIsolatedTest): """Test sample class""" + # pylint: disable=too-many-instance-attributes + @run_as_sync async def setUp(self) -> None: # don't need to await because it's tagged @run_as_sync @@ -28,6 +32,7 @@ async def setUp(self) -> None: self.sgl = SequencingGroupLayer(self.connection) self.asl = AssayLayer(self.connection) self.al = AnalysisLayer(self.connection) + self.pl = ParticipantLayer(self.connection) sample = await self.sl.upsert_sample( SampleUpsertInternal( @@ -167,3 +172,22 @@ async def test_get_analysis(self): ] self.assertEqual(analyses, expected) + + @run_as_sync + async def test_get_sample_cram_path_map_for_seqr(self): + """ + Exercise get_sample_cram_path_map_for_seqr() + """ + + part = await self.pl.upsert_participants( + [ + ParticipantUpsertInternal( + external_ids={PRIMARY_EXTERNAL_ORG: 'PEXT1'}, + meta={}, + samples=[SampleUpsertInternal(id=self.sample_id)], + ), + ], + ) + + id_map = await self.al.get_sample_cram_path_map_for_seqr(self.project_id, ['blood'], [part[0].id]) + self.assertIsInstance(id_map, list) diff --git a/web/package.json b/web/package.json index c4d981a98..7c8165709 100644 --- a/web/package.json +++ b/web/package.json @@ -1,6 +1,6 @@ { "name": "metamist", - "version": "7.1.0", + "version": "7.1.1", "private": true, "dependencies": { "@apollo/client": "^3.7.3",