Repository: EdinburghGenomics/clarity_scripts

Issue:
Matching species field is missing aggregated
https://github.com/EdinburghGenomics/clarity_scripts/blob/5b85e1e462c701d9e01f9a786d82688cfab4d391/scripts/populate_review_step.py#L209

Need to add the `aggregated` in the field name

Discussion:

Patch:
diff --git a/scripts/populate_review_step.py b/scripts/populate_review_step.py
index 9cccfd0..3c0e723 100644
--- a/scripts/populate_review_step.py
+++ b/scripts/populate_review_step.py
@@ -206,7 +206,7 @@ class PullSampleInfo(PullInfo):
         ('SR % Mapped', 'aggregated.pc_mapped_reads'),
         ('SR % Duplicates', 'aggregated.pc_duplicate_reads'),
         ('SR Mean Coverage', 'aggregated.mean_coverage'),
-        ('SR Species Found', 'matching_species'),
+        ('SR Species Found', 'aggregated.matching_species'),
         ('SR Sex Check Match', 'aggregated.gender_match'),
         ('SR Genotyping Match', 'aggregated.genotype_match'),
         ('SR Freemix', 'sample_contamination.freemix'),
@@ -237,12 +237,10 @@ class PullSampleInfo(PullInfo):
         return artifacts
 
     def field_from_entity(self, entity, api_field):
-        # TODO: remove once Rest API has a sensible field for species found
-        if api_field == 'matching_species':
-            species = entity[api_field]
-            return ', '.join(species)
-
-        return super().field_from_entity(entity, api_field)
+        field = super().field_from_entity(entity, api_field)
+        if api_field == 'aggregated.matching_species':
+            return ', '.join(field)
+        return field
 
 
 class PushInfo(StepPopulator):


Test patch:
diff --git a/tests/test_populate_review_step.py b/tests/test_populate_review_step.py
index 6e6c8e0..d6b8ec2 100644
--- a/tests/test_populate_review_step.py
+++ b/tests/test_populate_review_step.py
@@ -150,13 +150,15 @@ class TestPullSampleInfo(TestPopulator):
         'sample_id': 'a_sample',
         'user_sample_id': 'a_user_sample_id',
         'clean_yield_in_gb': 5,
-        'aggregated': {'clean_pc_q30': 70,
-                       'pc_mapped_reads': 75,
-                       'pc_duplicate_reads': 5,
-                       'mean_coverage': 30,
-                       'gender_match': 'Match',
-                       'genotype_match': 'Match'},
-        'matching_species': ['Homo sapiens', 'Thingius thingy'],
+        'aggregated': {
+            'clean_pc_q30': 70,
+            'pc_mapped_reads': 75,
+            'pc_duplicate_reads': 5,
+            'mean_coverage': 30,
+            'gender_match': 'Match',
+            'genotype_match': 'Match',
+            'matching_species': ['Homo sapiens', 'Thingius thingy'],
+        },
         'sample_contamination': {'freemix': 0.1},
         'reviewed': 'pass',
         'review_comments': 'alright',
@@ -197,7 +199,7 @@ class TestPullSampleInfo(TestPopulator):
             assert poa.return_value[1].udf['SR Useable Comments'] == 'AR: Review failed'
 
     def test_field_from_entity(self):
-        obs = self.epp.field_from_entity(self.fake_rest_entity, 'matching_species')
+        obs = self.epp.field_from_entity(self.fake_rest_entity, 'aggregated.matching_species')
         assert obs == 'Homo sapiens, Thingius thingy'