Example #1
0
class TestLoadCpG(unittest.TestCase):
    def setUp(self):

        data = Data(path=ROOT_DIR, base='fixtures')

        experiment = Experiment(
            data=None,
            task=None,
            method=None,
        )

        annotations = Annotations(name='annotations',
                                  exclude='none',
                                  cross_reactive='ex',
                                  snp='ex',
                                  chr='NS',
                                  gene_region='yes',
                                  geo='any',
                                  probe_class='any')

        observables = Observables(name='observables', types={})

        cells = Cells(name='cells', types='any')

        attributes = Attributes(target='age',
                                observables=observables,
                                cells=cells)

        self.config = Config(data=data,
                             experiment=experiment,
                             annotations=annotations,
                             attributes=attributes,
                             is_run=True,
                             is_root=True)
        self.config.initialize()

    def tearDown(self):
        clear_cache(self.config)

    def test_load_excluded_check_none_excluded(self):
        self.assertEqual([], load_excluded(self.config))

    def test_load_excluded_check_pkl_creation(self):
        self.config.annotations.exclude = 'excluded'
        fn = get_data_base_path(
            self.config) + '/' + self.config.annotations.exclude + '.pkl'

        self.config.excluded = load_excluded(self.config)

        self.assertEqual(True, os.path.isfile(fn))

    def test_load_excluded_check_len_excluded(self):
        self.config.annotations.exclude = 'excluded'

        self.config.excluded = load_excluded(self.config)

        self.assertEqual(3, len(self.config.excluded))
Example #2
0
class TestLoadCpG(unittest.TestCase):
    def setUp(self):

        data = Data(path=ROOT_DIR, base='fixtures')

        experiment = Experiment(
            data=None,
            task=None,
            method=None,
        )

        annotations = Annotations(name='annotations',
                                  exclude='none',
                                  cross_reactive='ex',
                                  snp='ex',
                                  chr='NS',
                                  gene_region='yes',
                                  geo='any',
                                  probe_class='any')

        observables = Observables(name='observables', types={})

        cells = Cells(name='cells', types='any')

        attributes = Attributes(target='age',
                                observables=observables,
                                cells=cells)

        self.config = Config(data=data,
                             experiment=experiment,
                             annotations=annotations,
                             attributes=attributes,
                             is_run=True,
                             is_root=True)
        self.config.initialize()

    def tearDown(self):
        clear_cache(self.config)

    def test_load_cpg_check_files_creation(self):
        fn_dict = get_data_base_path(self.config) + '/' + 'betas_dict.pkl'
        fn_data = get_data_base_path(self.config) + '/' + 'betas'
        fn_npz = fn_data + '.npz'

        load_betas(self.config)

        self.assertEqual(True,
                         os.path.isfile(fn_dict) and os.path.isfile(fn_npz))

    def test_load_cpg_check_len_cpg_dict(self):
        load_betas(self.config)
        self.assertEqual(300, len(list(self.config.betas_dict)))

    def test_load_cpg_check_shape_cpg_data(self):
        load_betas(self.config)
        self.assertEqual((300, 729), self.config.betas_data.shape)
Example #3
0
class TestLoadCpG(unittest.TestCase):
    def setUp(self):

        data = Data(path=ROOT_DIR, base='fixtures')

        experiment = Experiment(
            data=None,
            task=None,
            method=None,
        )

        annotations = Annotations(name='annotations',
                                  type='450k',
                                  exclude='excluded',
                                  select_dict={
                                      'CROSS_R': ['0'],
                                      'Probe_SNPs': ['empty'],
                                      'Probe_SNPs_10': ['empty'],
                                      'CHR': ['-X', '-Y'],
                                      'UCSC_REFGENE_NAME': ['non-empty'],
                                  })

        observables = Observables(name='observables', types={})

        cells = Cells(name='cells', types='any')

        attributes = Attributes(target='age',
                                observables=observables,
                                cells=cells)

        self.config = Config(data=data,
                             experiment=experiment,
                             annotations=annotations,
                             attributes=attributes,
                             is_run=True,
                             is_root=True)
        self.config.initialize()

    def tearDown(self):
        clear_cache(self.config)

    def test_load_excluded_check_pkl_creation(self):
        self.config.annotations.exclude = 'excluded'
        fn = get_data_base_path(
            self.config) + '/' + self.config.annotations.exclude + '.pkl'
        self.config.excluded = load_excluded(self.config)
        self.assertEqual(True, os.path.isfile(fn))

    def test_load_excluded_check_len_excluded(self):
        self.config.annotations.exclude = 'excluded'
        self.config.excluded = load_excluded(self.config)
        self.assertEqual(3, len(self.config.excluded))
Example #4
0
class TestLoadAnnotations(unittest.TestCase):
    def setUp(self):
        data = Data(path=ROOT_DIR, base='fixtures')

        experiment = Experiment(data=None, task=None, method=None)

        annotations = Annotations(name='annotations',
                                  type='450k',
                                  exclude='excluded',
                                  select_dict={
                                      'CROSS_R': ['0'],
                                      'Probe_SNPs': ['empty'],
                                      'Probe_SNPs_10': ['empty'],
                                      'CHR': ['-X', '-Y'],
                                      'UCSC_REFGENE_NAME': ['non-empty'],
                                  })

        observables = Observables(name='observables', types={})

        cells = Cells(name='cells', types='any')

        attributes = Attributes(target='age',
                                observables=observables,
                                cells=cells)

        self.config = Config(data=data,
                             experiment=experiment,
                             annotations=annotations,
                             attributes=attributes,
                             is_run=True,
                             is_root=True)
        self.config.initialize()

    def tearDown(self):
        clear_cache(self.config)

    def test_load_observables_dict_num_elems(self):
        observables_dict = load_observables_dict(self.config)
        self.assertEqual(len(observables_dict['age']), 729)

    def test_load_observables_dict_age_range(self):
        observables_dict = load_observables_dict(self.config)
        self.assertEqual(
            max(observables_dict['age']) - min(observables_dict['age']), 80)

    def test_load_observables_dict_check_pkl_file_creation(self):
        load_observables_dict(self.config)

        create = os.path.isfile(
            get_data_base_path(self.config) + '/' +
            self.config.attributes.observables.name + '.pkl')

        self.assertEqual(True, create)

    def test_load_observables_dict_check_sum_smoke(self):
        observables_dict = load_observables_dict(self.config)

        sum_smoke = sum(list(map(int, observables_dict['smoke'])))

        self.assertEqual(188, sum_smoke)

    def test_load_observables_dict_num_Male(self):
        observables_dict = load_observables_dict(self.config)

        indexes = [
            ind for ind, val in enumerate(observables_dict['gender'])
            if val == 'M'
        ]

        self.assertEqual(341, len(indexes))

    def test_load_observables_dict_num_Female(self):
        observables_dict = load_observables_dict(self.config)

        indexes = [
            ind for ind, val in enumerate(observables_dict['gender'])
            if val == 'F'
        ]

        self.assertEqual(388, len(indexes))
class TestLoadResidualsCommon(unittest.TestCase):
    def setUp(self):

        data = Data(path=ROOT_DIR, base='fixtures')

        data_params = {'cells': ['B', 'CD4T', 'NK', 'CD8T', 'Gran']}

        experiment = Experiment(data=None,
                                task=None,
                                method=None,
                                data_params=data_params)

        annotations = Annotations(name='annotations',
                                  type='450k',
                                  exclude='excluded',
                                  select_dict={
                                      'CROSS_R': ['0'],
                                      'Probe_SNPs': ['empty'],
                                      'Probe_SNPs_10': ['empty'],
                                      'CHR': ['-X', '-Y'],
                                      'UCSC_REFGENE_NAME': ['non-empty'],
                                  })

        observables = Observables(name='observables', types={})

        cells = Cells(name='cells', types='any')

        attributes = Attributes(target='age',
                                observables=observables,
                                cells=cells)

        self.config = Config(data=data,
                             experiment=experiment,
                             annotations=annotations,
                             attributes=attributes,
                             is_run=True,
                             is_root=True)
        self.config.initialize()

    def test_load_residuals_check_files_creation(self):
        suffix = '_' + self.config.experiment.get_data_params_str()
        fn_dict = get_data_base_path(
            self.config) + '/' + 'residuals_dict' + suffix + '.pkl'
        fn_data = get_data_base_path(
            self.config) + '/' + 'residuals' + suffix + '.npz'

        load_residuals(self.config)

        self.assertEqual(True,
                         os.path.isfile(fn_dict) and os.path.isfile(fn_data))

    def tearDown(self):
        clear_cache(self.config)

    def test_load_residuals_check_len_cpg_dict(self):
        load_residuals(self.config)
        self.assertEqual(300, len(list(self.config.residuals_dict)))

    def test_load_residuals_check_shape_cpg_data(self):
        load_residuals(self.config)
        self.assertEqual((300, 729), self.config.residuals_data.shape)
Example #6
0
class TestLoadResidualsCommon(unittest.TestCase):

    def setUp(self):

        data = Data(
            path=ROOT_DIR,
            base='fixtures'
        )

        data_params = {'cells': ['B', 'CD4T', 'NK', 'CD8T', 'Gran']}

        experiment = Experiment(
            data=None,
            task=None,
            method=None,
            data_params=data_params
        )

        annotations = Annotations(
            name='annotations',
            exclude='none',
            cross_reactive='ex',
            snp='ex',
            chr='NS',
            gene_region='yes',
            geo='any',
            probe_class='any'
        )

        observables = Observables(
            name='observables',
            types={}
        )

        cells = Cells(
            name='cells',
            types='any'
        )

        attributes = Attributes(
            target='age',
            observables=observables,
            cells=cells
        )

        self.config = Config(
            data=data,
            experiment=experiment,
            annotations=annotations,
            attributes=attributes,
            is_run=True,
            is_root=True
        )
        self.config.initialize()

    def test_load_residuals_check_files_creation(self):
        suffix = '_' + self.config.experiment.get_data_params_str()
        fn_dict = get_data_base_path(self.config) + '/' + 'residuals_common_dict.pkl'
        fn_data = get_data_base_path(self.config) + '/' + 'residuals_common' + suffix + '.npz'

        load_residuals_common(self.config)

        self.assertEqual(True, os.path.isfile(fn_dict) and os.path.isfile(fn_data))

    def tearDown(self):
        clear_cache(self.config)

    def test_load_residuals_check_len_cpg_dict(self):
        load_residuals_common(self.config)
        self.assertEqual(300, len(list(self.config.residuals_dict)))

    def test_load_residuals_check_shape_cpg_data(self):
        load_residuals_common(self.config)
        self.assertEqual((300, 729), self.config.residuals_data.shape)
Example #7
0
class TestLoadAnnotations(unittest.TestCase):
    def setUp(self):
        data = Data(path=ROOT_DIR, base='fixtures')

        experiment = Experiment(data=None, task=None, method=None)

        annotations = Annotations(name='annotations',
                                  exclude='none',
                                  cross_reactive='ex',
                                  snp='ex',
                                  chr='NS',
                                  gene_region='yes',
                                  geo='any',
                                  probe_class='any')

        observables = Observables(name='observables', types={})

        cells = Cells(name='cells', types='any')

        attributes = Attributes(target='age',
                                observables=observables,
                                cells=cells)

        self.config = Config(data=data,
                             experiment=experiment,
                             annotations=annotations,
                             attributes=attributes,
                             is_run=True,
                             is_root=True)
        self.config.initialize()

    def tearDown(self):
        clear_cache(self.config)

    def test_load_attributes_dict_num_elems(self):
        attributes_dict = load_observables_dict(self.config)
        self.assertEqual(len(attributes_dict['age']), 729)

    def test_load_attributes_dict_age_range(self):
        attributes_dict = load_observables_dict(self.config)
        self.assertEqual(
            max(attributes_dict['age']) - min(attributes_dict['age']), 80)

    def test_load_attributes_dict_check_pkl_file_creation(self):
        load_observables_dict(self.config)

        create = os.path.isfile(
            get_data_base_path(self.config) + '/' +
            self.config.attributes.observables.name + '.pkl')

        self.assertEqual(True, create)

    def test_load_attributes_dict_check_sum_smoke(self):
        attributes_dict = load_observables_dict(self.config)

        sum_smoke = sum(list(map(int, attributes_dict['smoke'])))

        self.assertEqual(188, sum_smoke)

    def test_load_attributes_dict_num_Male(self):
        attributes_dict = load_observables_dict(self.config)

        indexes = [
            ind for ind, val in enumerate(attributes_dict['gender'])
            if val == 'M'
        ]

        self.assertEqual(341, len(indexes))

    def test_load_attributes_dict_num_Female(self):
        attributes_dict = load_observables_dict(self.config)

        indexes = [
            ind for ind, val in enumerate(attributes_dict['gender'])
            if val == 'F'
        ]

        self.assertEqual(388, len(indexes))
Example #8
0
class TestLoadAnnotations(unittest.TestCase):
    def setUp(self):
        data = Data(path=ROOT_DIR, base='fixtures')

        experiment = Experiment(
            data=None,
            task=None,
            method=None,
        )

        annotations = Annotations(name='annotations',
                                  exclude='none',
                                  cross_reactive='ex',
                                  snp='ex',
                                  chr='NS',
                                  gene_region='yes',
                                  geo='any',
                                  probe_class='any')

        observables = Observables(name='observables', types={})

        cells = Cells(name='cells', types='any')

        attributes = Attributes(target='age',
                                observables=observables,
                                cells=cells)

        self.config = Config(data=data,
                             experiment=experiment,
                             annotations=annotations,
                             attributes=attributes,
                             is_run=True,
                             is_root=True)
        self.config.initialize()

    def tearDown(self):
        clear_cache(self.config)

    def compare_cross_r_cpg(self, cpg_list, ann_dict):
        compare = True
        for cpg in cpg_list:
            index = ann_dict[AnnotationKey.cpg.value].index(cpg)
            if not ann_dict[AnnotationKey.cross_reactive.value][index]:
                compare = False
                break
        return compare

    def test_load_annotations_dict_num_elems(self):
        annotations_dict = load_annotations_dict(self.config)
        self.assertEqual(len(annotations_dict['ID_REF']), 300)

    def test_load_annotations_dict_num_keys(self):
        annotations_dict = load_annotations_dict(self.config)
        self.assertEqual(len(list(annotations_dict.keys())), 10)

    def test_load_annotations_dict_num_chrs(self):
        annotations_dict = load_annotations_dict(self.config)
        self.assertEqual(len(set(annotations_dict['CHR'])), 11)

    def test_load_annotations_dict_num_bops(self):
        annotations_dict = load_annotations_dict(self.config)
        self.assertEqual(len(set(annotations_dict['BOP'])), 82)

    def test_load_annotations_check_pkl_file_creation(self):
        load_annotations_dict(self.config)

        create = os.path.isfile(
            get_data_base_path(self.config) + '/' +
            self.config.annotations.name + '.pkl')

        self.assertEqual(True, create)

    def test_load_annotations_num_cross_r_cpgs(self):
        annotations_dict = load_annotations_dict(self.config)

        num_of_cross_r_cpg = sum(
            list(map(int,
                     annotations_dict[AnnotationKey.cross_reactive.value])))

        self.assertEqual(num_of_cross_r_cpg, 22)

    def test_load_annotations_dict_compare_cross_r_cpg(self):
        cross_r_cpg = [
            'cg03242964', 'cg06142509', 'cg06352932', 'cg07110474',
            'cg07208077', 'cg07818063', 'cg08555389', 'cg08683088',
            'cg09720033', 'cg11032157', 'cg14502651', 'cg14829303',
            'cg14894369', 'cg18241189', 'cg20188490', 'cg20418818',
            'cg21752292', 'cg22505295', 'cg22805813', 'cg23146713',
            'cg24653967', 'cg25677688'
        ]
        annotations_dict = load_annotations_dict(self.config)

        compare = self.compare_cross_r_cpg(cross_r_cpg, annotations_dict)

        self.assertEqual(True, compare)

    def test_load_annotations_dict_num_geo(self):
        annotations_dict = load_annotations_dict(self.config)
        num_geo = len(set(annotations_dict[AnnotationKey.geo.value]))

        self.assertEqual(6, num_geo)

    def test_load_annotations_dict_num_class(self):
        annotations_dict = load_annotations_dict(self.config)
        self.assertEqual(
            len(set(annotations_dict[AnnotationKey.probe_class.value])), 4)