From 150b0b6f7b07c132f022a0d76903598c2befbd45 Mon Sep 17 00:00:00 2001 From: Reza Date: Mon, 28 Aug 2023 22:58:00 -0700 Subject: [PATCH 1/9] processed -> output, classified -> input --- tests/integration/test_integration.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 0d9c985..7693aaf 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -33,7 +33,9 @@ def test_run(self): Modality.FLAIR, Modality.ADC, ] - pipeline_dir = DefaultALFEDataDir(output=self.output_dir, input=self.input_dir) + pipeline_dir = DefaultALFEDataDir( + output_dir=self.output_dir, input_dir=self.input_dir + ) for modality in modalities: pipeline_dir.create_dir('input', accession, modality) From 79e39ac599771692f68a907d2ad2da67bc3957f6 Mon Sep 17 00:00:00 2001 From: Reza Date: Tue, 29 Aug 2023 14:53:53 -0700 Subject: [PATCH 2/9] fixed a bug in segmentation comp --- pyalfe/tasks/segmentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyalfe/tasks/segmentation.py b/pyalfe/tasks/segmentation.py index 3c02772..10cdc64 100644 --- a/pyalfe/tasks/segmentation.py +++ b/pyalfe/tasks/segmentation.py @@ -205,7 +205,7 @@ def run(self, accession): image_type=f'{self.image_type_output}_comp', sub_dir_name=self.segmentation_dir, ) - self.label_segmentation_components([seg_path], [comp_path]) + self.label_segmentation_components(seg_path, comp_path) class SingleModalitySegmentation(MultiModalitySegmentation): From e82e77312cef4677e6e3d0c20e495972b9a9aacb Mon Sep 17 00:00:00 2001 From: Reza Date: Tue, 29 Aug 2023 19:08:26 -0700 Subject: [PATCH 3/9] updated the integration test path assert --- tests/integration/test_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 7693aaf..8268481 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -84,7 +84,7 @@ def test_run(self): segmentation_path = pipeline_dir.get_output_image( accession, modality, - image_type='CNNAbnormalMap_seg', + image_type='abnormal_seg', sub_dir_name='abnormalmap', ) self.assertTrue( From 0b7064a86f20687cb8439cb59b312ff6c7e7cf12 Mon Sep 17 00:00:00 2001 From: Reza Date: Wed, 30 Aug 2023 17:18:22 -0700 Subject: [PATCH 4/9] created separate asserts for summary and individual lesion quants in the integration test. --- tests/integration/test_integration.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 8268481..8c19ef4 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -91,12 +91,19 @@ def test_run(self): os.path.exists(segmentation_path), msg=f'{segmentation_path} does not exist.', ) - quantification_path = pipeline_dir.get_quantification_file( + summary_quantification_path = pipeline_dir.get_quantification_file( accession, modality, 'SummaryLesionMeasures' ) + individual_quantification_path = pipeline_dir.get_quantification_file( + accession, modality, 'IndividualLesionMeasures' + ) + self.assertTrue( - os.path.exists(quantification_path), - msg=f'{quantification_path} does not exist.', + os.path.exists(summary_quantification_path), + msg=f'{summary_quantification_path} does not exist.', ) - quantification = pd.read_csv(quantification_path) - self.assertEqual(quantification.dropna().shape, (14, 2)) + summary_quantification = pd.read_csv(summary_quantification_path) + self.assertEqual(summary_quantification.dropna().shape, (53, 2)) + + individual_quantification = pd.read_csv(individual_quantification_path) + self.assertEqual(individual_quantification.dropna().shape, (226, 51)) From c8a71e4eacd3e3dab212caac1f39952b17a3b0bc Mon Sep 17 00:00:00 2001 From: Reza Date: Thu, 7 Sep 2023 22:25:50 -0700 Subject: [PATCH 5/9] added template region volumes --- pyalfe/tasks/quantification.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pyalfe/tasks/quantification.py b/pyalfe/tasks/quantification.py index 5f5103e..b22bc95 100644 --- a/pyalfe/tasks/quantification.py +++ b/pyalfe/tasks/quantification.py @@ -101,11 +101,17 @@ def load_template_images(self, accession, target): resampling_origin=Modality.T1, sub_dir_name=roi_sub_dir, ) - print(template_image_to_target_file) + if os.path.exists(template_image_to_target_file): target_images[roi_key], _ = self.load(template_image_to_target_file) + self.logger.info( + 'loaded template: ' + template_image_to_target_file + ) target_images[roi_key] = np.round(target_images[roi_key]) else: + self.logger.info( + 'missing template: ' + template_image_to_target_file + ) target_images[roi_key] = None return target_images @@ -117,7 +123,7 @@ def get_radiomics(self, skullstripped_file, lesion_seg_file): return {} def get_brain_volume_stats( - self, brain_mask, tissue_seg, ventricles_seg, voxel_volume + self, brain_mask, tissue_seg, ventricles_seg, template_images, voxel_volume ): stats = {} brain_indices = np.where(brain_mask == 1)[0] @@ -134,6 +140,15 @@ def get_brain_volume_stats( len(np.where(tissue_seg == tissue)[0]) * voxel_volume ) + for template_key, template_image in template_images.items(): + if 'regions' not in roi_dict[template_key]: + continue + regions = roi_dict[template_key]['regions'] + for region_key, region_values in regions.items(): + stats[f'volume_of_{region_key}'] = ( + np.sum(np.isin(template_image, region_values)) * voxel_volume + ) + return stats def get_lesion_stats( @@ -219,6 +234,7 @@ def get_lesion_stats( stats[ f'ninety_five_percentile_{modality_name.lower()}_signal' ] = np.percentile(modality_image[lesion_indices], 95) + if Modality.T1 in modality_images and Modality.T1Post in modality_images: t1_image = modality_images[Modality.T1] t1post_image = modality_images[Modality.T1Post] @@ -279,6 +295,8 @@ def run(self, accession): else: tissue_seg, _ = self.load(tissue_seg_file) + template_images = self.load_template_images(accession, Modality.T1) + ventricles_seg_file = self.pipeline_dir.get_output_image( accession=accession, modality=Modality.T1, image_type='VentriclesSeg' ) From 573709fb06d6d1401b695e686e141dfc4c6bddc9 Mon Sep 17 00:00:00 2001 From: Reza Date: Fri, 8 Sep 2023 11:04:51 -0700 Subject: [PATCH 6/9] updated test_get_brain_volume_stats --- tests/unit/test_tasks.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_tasks.py b/tests/unit/test_tasks.py index 3fc7718..a3bbe90 100644 --- a/tests/unit/test_tasks.py +++ b/tests/unit/test_tasks.py @@ -584,6 +584,11 @@ def test_get_brain_volume_stats(self): brain_seg = np.array([0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0]) tissue_seg = np.array([0, 0, 1, 2, 3, 4, 5, 6, 1, 0, 0]) ventricles_seg = np.array([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]) + template_images = { + 'template': np.array([0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 0.0]), + 'lobes': np.array([0, 1, 2, 3, 4, 5, 6, 6, 2, 3]), + 'CorpusCallosum': np.array([0, 1, 2, 3, 4, 5, 4, 3, 0, 0]), + } task = Quantification( pipeline_dir=self.pipeline_dir, @@ -593,7 +598,7 @@ def test_get_brain_volume_stats(self): ) volume_stats = task.get_brain_volume_stats( - brain_seg, tissue_seg, ventricles_seg, voxel_volume=2.0 + brain_seg, tissue_seg, ventricles_seg, template_images, voxel_volume=2.0 ) self.assertEqual(14.0, volume_stats['total_brain_volume']) From 49388dcf58b04512c34c5536013fa0cd63543906 Mon Sep 17 00:00:00 2001 From: Reza Date: Fri, 8 Sep 2023 13:13:36 -0700 Subject: [PATCH 7/9] changed the checkout action in the test workflows --- .github/workflows/integration-test.yml | 8 +++++++- .github/workflows/tests.yml | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 205a9e1..354ca66 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -15,8 +15,14 @@ jobs: python-version: [ "3.9", "3.11" ] steps: + - name: Get branch + uses: xt0rted/pull-request-comment-branch@v2 + id: comment-branch + - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 + with: + ref: ${{ steps.comment-branch.outputs.head_ref }} - name: Cache dependency binaries id: cache-bin diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c7e115e..9ba6479 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Cache dependency binaries id: cache-bin From 5863c612e4051094f3839e40289ccc9dd135e8b5 Mon Sep 17 00:00:00 2001 From: Reza Date: Fri, 8 Sep 2023 15:45:41 -0700 Subject: [PATCH 8/9] added more asserts to the test --- tests/unit/test_tasks.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/unit/test_tasks.py b/tests/unit/test_tasks.py index a3bbe90..9ae91a4 100644 --- a/tests/unit/test_tasks.py +++ b/tests/unit/test_tasks.py @@ -610,3 +610,16 @@ def test_get_brain_volume_stats(self): self.assertEqual(2.0, volume_stats['volume_of_deep_gray_matter']) self.assertEqual(2.0, volume_stats['volume_of_brain_stem']) self.assertEqual(2.0, volume_stats['volume_of_cerebellum']) + self.assertEqual(2.0, volume_stats['volume_of_Frontal']) + self.assertEqual(4.0, volume_stats['volume_of_Parietal']) + self.assertEqual(4.0, volume_stats['volume_of_Occipital']) + self.assertEqual(2.0, volume_stats['volume_of_AnteriorTemporal']) + self.assertEqual(2.0, volume_stats['volume_of_MiddleTemporal']) + self.assertEqual(4.0, volume_stats['volume_of_PosteriorTemporal']) + self.assertEqual(8.0, volume_stats['volume_of_Parietal_Occipital']) + self.assertEqual(14.0, volume_stats['volume_of_CorpusCallosum']) + self.assertEqual(2.0, volume_stats['volume_of_CorpusCallosum_Rostrum']) + self.assertEqual(2.0, volume_stats['volume_of_CorpusCallosum_Genu']) + self.assertEqual(4.0, volume_stats['volume_of_CorpusCallosum_Body']) + self.assertEqual(4.0, volume_stats['volume_of_CorpusCallosum_Isthmus']) + self.assertEqual(2.0, volume_stats['volume_of_CorpusCallosum_Splenium']) From 4548a07ce809f5d960123ad38a761a485cf4956b Mon Sep 17 00:00:00 2001 From: Reza Date: Fri, 8 Sep 2023 16:25:40 -0700 Subject: [PATCH 9/9] increased the error margin a registration test --- tests/unit/test_image_registration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_image_registration.py b/tests/unit/test_image_registration.py index 3f710e5..e47b773 100644 --- a/tests/unit/test_image_registration.py +++ b/tests/unit/test_image_registration.py @@ -93,7 +93,7 @@ def test_register_affine(self): np.testing.assert_array_less( np.linalg.norm(get_nifti_data(output) - fixed_data) / np.linalg.norm(get_nifti_data(output) - moving_data), - 0.4, + 0.45, ) moving2_path = self.get_image_path('moving2.nii.gz')