def test_local_sublist_regexp_match(self): ''' Method to test that the subject list builder includes only desired sites from S3 Parameters ---------- self : BuildSublistTestCase a unittest.TestCase-inherited class ''' # Import packages import os from CPAC.utils import test_init # Init variables data_config_dict = self.data_config_dict subs_match_regex = [ '0010042', '0010064', '0010128', '0021019', '0023008', '0023008', '0023012', '0027011', '0027018', '0027034', '0027037', '1019436', '1206380', '1418396' ] # Copy original inputs to all same folder with # {participant}_{series} in filenames base_dir = test_init.return_resource_subfolder('input_reorg_files') # Set up local templates anat_template = os.path.join( base_dir, '[si]?*{site}_mprage_sub{participant}_sess{session}_ser_{series}.nii.gz' ) func_template = os.path.join( base_dir, '?[si]*{site}_rest_sub{participant}_sess{session}_ser_{series}.nii.gz' ) # Add include sites to data config dictionary data_config_dict['anatomicalTemplate'] = anat_template data_config_dict['functionalTemplate'] = func_template # Return found filepaths from subject list filepaths = self._return_sublist_filepaths(data_config_dict) # And check them properly_filtered, filter_msg = \ self._check_filepaths(filepaths, subs_match_regex, include=True) # Assert resulting list is properly filtered self.assertTrue(properly_filtered, msg=filter_msg)
def test_local_sublist_regexp_match(self): ''' Method to test that the subject list builder includes only desired sites from S3 Parameters ---------- self : BuildSublistTestCase a unittest.TestCase-inherited class ''' # Import packages import os from CPAC.utils import test_init # Init variables data_config_dict = self.data_config_dict subs_match_regex = ['0010042', '0010064', '0010128', '0021019', '0023008', '0023008', '0023012', '0027011', '0027018', '0027034', '0027037', '1019436', '1206380', '1418396'] # Copy original inputs to all same folder with # {participant}_{series} in filenames base_dir = test_init.return_resource_subfolder('input_reorg_files') # Set up local templates anat_template = os.path.join(base_dir, '[si]?*{site}_mprage_sub{participant}_sess{session}_ser_{series}.nii.gz') func_template = os.path.join(base_dir, '?[si]*{site}_rest_sub{participant}_sess{session}_ser_{series}.nii.gz') # Add include sites to data config dictionary data_config_dict['anatomicalTemplate'] = anat_template data_config_dict['functionalTemplate'] = func_template # Return found filepaths from subject list filepaths = self._return_sublist_filepaths(data_config_dict) # And check them properly_filtered, filter_msg = \ self._check_filepaths(filepaths, subs_match_regex, include=True) # Assert resulting list is properly filtered self.assertTrue(properly_filtered, msg=filter_msg)
def test_local_sublist_exclude_subs(self): ''' Method to test that the subject list builder excludes only non-desired subjects from S3 Parameters ---------- self : BuildSublistTestCase a unittest.TestCase-inherited class ''' # Import packages import os from CPAC.utils import test_init # Init variables data_config_dict = self.data_config_dict exclude_subs = ['0010042', '0010064', '0010128'] base_dir = test_init.return_resource_subfolder('input') # Set up local templates anat_template = os.path.join(base_dir, '{site}/{participant}/{session}/{series}/'\ 'mprage.nii.gz') func_template = os.path.join(base_dir, '{site}/{participant}/{session}/{series}/'\ 'rest.nii.gz') # Add include sites to data config dictionary data_config_dict['anatomicalTemplate'] = anat_template data_config_dict['functionalTemplate'] = func_template data_config_dict['exclusionSubjectList'] = exclude_subs # Return found filepaths from subject list filepaths = self._return_sublist_filepaths(data_config_dict) # And check them properly_filtered, filter_msg = \ self._check_filepaths(filepaths, exclude_subs, include=False) # Assert resulting list is properly filtered self.assertTrue(properly_filtered, msg=filter_msg)
def test_ambiguous_template(self): ''' Function that tests the subject list cannot be built properly with an over-ambiguous path template Parameters ---------- self : BuildSublistTestCase a unittest.TestCase-inherited class ''' # Import packages import os from CPAC.utils import build_sublist, test_init # Init variables # Init variables data_config_dict = self.data_config_dict # Copy original inputs to all same folder with # {participant}_{series} in filenames base_dir = test_init.return_resource_subfolder('input_reorg_files') # Set up local templates anat_template = os.path.join(base_dir, '{site}_mprage_{participant}_{session}_{series}.nii.gz') func_template = os.path.join(base_dir, '{site}_rest_{participant}_{session}_{series}.nii.gz') # Add include sites to data config dictionary data_config_dict['anatomicalTemplate'] = anat_template data_config_dict['functionalTemplate'] = func_template # Build subject list try: self._return_sublist_filepaths(data_config_dict) except Exception as exc: self.assertIsInstance(exc, Exception)
def setUp(self): ''' Method to instantiate the TestCase Parameters ---------- self : DatSinkTestCase a unittest.TestCase-inherited class Returns ------- None this function does not return any values, but populates the instance attributes for: self.base_dir : string filepath to base directory of DataSink self.creds_path : string filepath to AWS keys credentials file self.data_sink : nipype DataSink object object from nipype.interfaces.io.DataSink() self.ds_node : nipype Node object object from nipype.pipeline.engine.Node() self.in_file : string filepath to nifti file to use as test input to datasink ''' # Import packages import os import sys import tempfile import nipype.pipeline.engine as pe import nipype.interfaces.io as nio from CPAC.utils import test_init # Init variables try: input_dir = test_init.return_resource_subfolder('input') subj_id = test_init.return_test_subj() creds_path = test_init.return_aws_creds() bucket_name = test_init.default_bucket_name() except Exception as exc: print 'Unable to locate testing resources.\nError: %s' % exc sys.exit() # Datasink parameters base_dir = tempfile.mkdtemp() # Get the input file as an anatomical scan from th e CPAC_RESOURCES in_file = os.path.join(input_dir, 'site_1', subj_id, 'session_1', 'anat_1', 'mprage.nii.gz') # Init the datasinks data_sink = nio.DataSink() ds_node = pe.Node(nio.DataSink(), name='sinker_0') # Add instance variables to TestCase self.base_dir = base_dir self.bucket_name = bucket_name self.creds_path = creds_path self.data_sink = data_sink self.ds_node = ds_node self.in_file = in_file