From bcc639207412b539adc2acba9a00e53ce95496cb Mon Sep 17 00:00:00 2001 From: Michael Franklin <22381693+illusional@users.noreply.github.com> Date: Tue, 2 Jul 2024 09:42:13 +1000 Subject: [PATCH] Fix get sequencing groups by analysis IDs (#850) * Commit failing test * Change inner to left join to fix test --------- Co-authored-by: Michael Franklin --- db/python/tables/sequencing_group.py | 2 +- test/test_analysis.py | 68 +++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/db/python/tables/sequencing_group.py b/db/python/tables/sequencing_group.py index 15b550b16..829be7057 100644 --- a/db/python/tables/sequencing_group.py +++ b/db/python/tables/sequencing_group.py @@ -370,7 +370,7 @@ async def get_sequencing_groups_by_analysis_ids( FROM analysis_sequencing_group asg INNER JOIN sequencing_group sg ON sg.id = asg.sequencing_group_id INNER JOIN sample s ON s.id = sg.sample_id - INNER JOIN sequencing_group_external_id sgexid ON sg.id = sgexid.sequencing_group_id + LEFT JOIN sequencing_group_external_id sgexid ON sg.id = sgexid.sequencing_group_id WHERE asg.analysis_id IN :aids GROUP BY sg.id, asg.analysis_id """ diff --git a/test/test_analysis.py b/test/test_analysis.py index 8ea4d458a..3eb2ee484 100644 --- a/test/test_analysis.py +++ b/test/test_analysis.py @@ -189,5 +189,71 @@ async def test_get_sample_cram_path_map_for_seqr(self): ], ) - id_map = await self.al.get_sample_cram_path_map_for_seqr(self.project_id, ['blood'], [part[0].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) + + @run_as_sync + async def test_get_sgs_by_analysis_id_with_no_eids(self): + """ + Test get_sgs_by_analysis_id() + """ + + # duplicate here to ensure sgs don't have any external ids + assay_meta = { + 'sequencing_type': 'genome', + 'sequencing_technology': 'short-read', + 'sequencing_platform': 'illumina', + } + sample = await self.sl.upsert_sample( + SampleUpsertInternal( + external_ids={PRIMARY_EXTERNAL_ORG: 'test_sgs_aid'}, + type='blood', + meta={}, + active=True, + sequencing_groups=[ + SequencingGroupUpsertInternal( + type='genome', + technology='short-read', + platform='illumina', + assays=[ + AssayUpsertInternal( + type='sequencing', + meta=assay_meta, + ) + ], + ), + SequencingGroupUpsertInternal( + type='exome', + technology='short-read', + platform='illumina', + assays=[ + AssayUpsertInternal( + type='sequencing', + meta=assay_meta, + ) + ], + ), + ], + ) + ) + + genome_id = sample.sequencing_groups[0].id + exome_id = sample.sequencing_groups[1].id + + a_id = await self.al.create_analysis( + AnalysisInternal( + type='analysis-runner', + status=AnalysisStatus.UNKNOWN, + sequencing_group_ids=[genome_id, exome_id], + meta={}, + ) + ) + + sgs_by_aid = await self.sgl.get_sequencing_groups_by_analysis_ids([a_id]) + self.assertIn(a_id, sgs_by_aid) + sgs = sorted(sgs_by_aid[a_id], key=lambda sg: sg.id) + + self.assertEqual(sgs[0].id, genome_id) + self.assertEqual(sgs[1].id, exome_id)