Beispiel #1
0
    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()
Beispiel #2
0
def betas_clock_linreg(data, annotations, attributes, method_params=None):
    config_root = Config(data=copy.deepcopy(data),
                         experiment=Experiment(
                             data=DataType.betas,
                             task=Task.clock,
                             method=Method.linreg,
                             method_params=copy.deepcopy(method_params)),
                         annotations=copy.deepcopy(annotations),
                         attributes=copy.deepcopy(attributes),
                         is_run=True,
                         is_root=True)
    root = Node(name=str(config_root), config=config_root)

    config_child = Config(data=copy.deepcopy(data),
                          experiment=Experiment(data=DataType.betas,
                                                task=Task.table,
                                                method=Method.linreg),
                          annotations=copy.deepcopy(annotations),
                          attributes=copy.deepcopy(attributes),
                          is_run=True,
                          is_root=False)

    Node(name=str(config_child), config=config_child, parent=root)

    build_tree(root)
    calc_tree(root)
Beispiel #3
0
def cpg_proc_clock_linreg_dev(data,
                              annotations,
                              attributes,
                              child_method=Method.linreg,
                              params=None):
    config_root = Config(data=copy.deepcopy(data),
                         experiment=Experiment(type=DataType.cpg,
                                               task=Task.clock,
                                               method=Method.linreg,
                                               params=copy.deepcopy(params)),
                         annotations=copy.deepcopy(annotations),
                         attributes=copy.deepcopy(attributes),
                         is_run=True,
                         is_root=True)
    root = Node(name=str(config_root), config=config_root)

    config_child = Config(data=copy.deepcopy(data),
                          experiment=Experiment(
                              type=DataType.cpg,
                              task=Task.table,
                              method=copy.deepcopy(child_method),
                              params={}),
                          annotations=copy.deepcopy(annotations),
                          attributes=copy.deepcopy(attributes),
                          is_run=True,
                          is_root=False)

    Node(name=str(config_child), config=config_child, parent=root)

    build_tree(root)
    calc_tree(root)
Beispiel #4
0
    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()
Beispiel #5
0
def betas_adj_table_approach_3(data, annotations, attributes, target_list,
                               data_params_list):
    config_root = Config(data=copy.deepcopy(data),
                         experiment=Experiment(data=DataType.betas_adj,
                                               task=Task.table,
                                               method=Method.aggregator,
                                               data_params=copy.deepcopy(
                                                   data_params_list[0])),
                         annotations=copy.deepcopy(annotations),
                         attributes=copy.deepcopy(attributes),
                         is_run=True,
                         is_root=True)
    root = Node(name=str(config_root), config=config_root)

    for id, target in enumerate(target_list):
        attributes_common = copy.deepcopy(attributes)
        attributes_common.target = target
        config_common = Config(data=copy.deepcopy(data),
                               experiment=Experiment(
                                   data=DataType.betas_adj,
                                   task=Task.table,
                                   method=Method.oma,
                                   data_params=copy.deepcopy(
                                       data_params_list[id])),
                               annotations=copy.deepcopy(annotations),
                               attributes=attributes_common,
                               is_run=True,
                               is_root=False)
        Node(name=str(config_common), config=config_common, parent=root)

    build_tree(root)
    calc_tree(root)
Beispiel #6
0
def cpg_proc_clock_linreg(
    data,
    annotations,
    attributes,
    child_method = Method.linreg
):
    config_root = Config(
        data=data,
        experiment=Experiment(
            type=DataType.cpg,
            task=Task.clock,
            method=Method.linreg,
            params={}
        ),
        annotations=annotations,
        attributes=attributes
    )
    root = Node(name=str(config_root), config=config_root)

    config_child = Config(
        data=data,
        experiment=Experiment(
            type=DataType.cpg,
            task=Task.table,
            method=child_method,
            params={}
        ),
        annotations=annotations,
        attributes=attributes
    )

    Node(name=str(config_child), config=config_child, parent=root)

    calc_tree(root)
Beispiel #7
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))
Beispiel #8
0
def table_aggregator_approach_4(
    data_type,
    data,
    annotations,
    attributes,
    observables_list,
    data_params,
):
    config_root = Config(
        data=copy.deepcopy(data),
        experiment=Experiment(
            data=data_type,
            task=Task.table,
            method=Method.aggregator,
            data_params=copy.deepcopy(data_params),
        ),
        annotations=copy.deepcopy(annotations),
        attributes=copy.deepcopy(attributes),
        is_run=True,
        is_root=True
    )
    root = Node(name=str(config_root), config=config_root)

    for d in observables_list:
        observables_lvl_1 = Observables(
            name=copy.deepcopy(attributes.observables.name),
            types=d
        )

        cells_lvl_1 = Cells(
            name=copy.deepcopy(attributes.cells.name),
            types=copy.deepcopy(attributes.cells.types)
        )

        attributes_lvl_1 = Attributes(
            target=copy.deepcopy(attributes.target),
            observables=observables_lvl_1,
            cells=cells_lvl_1,
        )

        config_lvl_1 = Config(
            data=copy.deepcopy(data),
            experiment=Experiment(
                data=data_type,
                task=Task.table,
                method=Method.heteroskedasticity,
                data_params=copy.deepcopy(data_params)
            ),
            annotations=copy.deepcopy(annotations),
            attributes=attributes_lvl_1,
            is_run=True,
            is_root=False
        )
        Node(name=str(config_lvl_1), config=config_lvl_1, parent=root)

    build_tree(root)
    calc_tree(root)
Beispiel #9
0
def cpg_plot_methylation_scatter(
    data,
    annotations,
    attributes,
    cpg_list,
    observables_list,
    child_method=Method.linreg,
):
    for cpg in cpg_list:

        config_root = Config(
            data=data,
            experiment=Experiment(
                type=DataType.cpg,
                task=Task.methylation,
                method=Method.scatter,
                params={}
            ),
            annotations=annotations,
            attributes=attributes
        )
        config_root.experiment.params['item'] = cpg

        root = Node(name=str(config_root), config=config_root)

        for d in observables_list:
            observables_child = Observables(
                name=attributes.observables.name,
                types=d
            )

            cells_child = Cells(
                name=attributes.cells.name,
                types=attributes.cells.types
            )

            attributes_child = Attributes(
                target=attributes.target,
                observables=observables_child,
                cells=cells_child,
            )

            config_child = Config(
                data=data,
                experiment=Experiment(
                    type=DataType.cpg,
                    task=Task.table,
                    method=child_method,
                    params={}
                ),
                annotations=annotations,
                attributes=attributes_child,
                is_run=False
            )
            Node(name=str(config_child), config=config_child, parent=root)

        calc_tree(root)
Beispiel #10
0
def betas_plot_variance_histogram_dev(data,
                                      annotations,
                                      attributes,
                                      cpg_list,
                                      observables_list,
                                      child_method=Method.linreg,
                                      method_params=None):
    for cpg in cpg_list:

        config_root = Config(data=copy.deepcopy(data),
                             experiment=Experiment(
                                 data=DataType.betas,
                                 task=Task.methylation,
                                 method=Method.variance_histogram,
                                 method_params=copy.deepcopy(method_params)),
                             annotations=copy.deepcopy(annotations),
                             attributes=copy.deepcopy(attributes),
                             is_run=True,
                             is_root=True,
                             is_load_child=False)

        if config_root.experiment.method_params is None:
            config_root.experiment.method_params = dict()

        config_root.experiment.method_params['item'] = cpg

        root = Node(name=str(config_root), config=config_root)

        for d in observables_list:
            observables_child = Observables(name=copy.deepcopy(
                attributes.observables.name),
                                            types=d)

            cells_child = Cells(name=copy.deepcopy(attributes.cells.name),
                                types=copy.deepcopy(attributes.cells.types))

            attributes_child = Attributes(
                target=copy.deepcopy(attributes.target),
                observables=observables_child,
                cells=cells_child,
            )

            config_child = Config(data=copy.deepcopy(data),
                                  experiment=Experiment(
                                      data=DataType.betas,
                                      task=Task.table,
                                      method=copy.deepcopy(child_method)),
                                  annotations=copy.deepcopy(annotations),
                                  attributes=attributes_child,
                                  is_run=False,
                                  is_root=False,
                                  is_load_child=False)
            Node(name=str(config_child), config=config_child, parent=root)

        build_tree(root)
        calc_tree(root)
Beispiel #11
0
def plot_scatter(data_type,
                 data,
                 annotations,
                 attributes,
                 observables_list,
                 child_method=Method.linreg,
                 data_params=None,
                 method_params=None):
    task_params = {'type': 'run'}

    config_root = Config(data=copy.deepcopy(data),
                         experiment=Experiment(
                             data=data_type,
                             task=Task.plot,
                             method=Method.scatter,
                             data_params=copy.deepcopy(data_params),
                             method_params=copy.deepcopy(method_params),
                             task_params=task_params),
                         annotations=copy.deepcopy(annotations),
                         attributes=copy.deepcopy(attributes),
                         is_run=True,
                         is_root=True,
                         is_load_child=False)

    root = Node(name=str(config_root), config=config_root)

    for d in observables_list:
        observables_child = Observables(name=copy.deepcopy(
            attributes.observables.name),
                                        types=d)

        cells_child = Cells(name=copy.deepcopy(attributes.cells.name),
                            types=copy.deepcopy(attributes.cells.types))

        attributes_child = Attributes(
            target=copy.deepcopy(attributes.target),
            observables=observables_child,
            cells=cells_child,
        )

        config_child = Config(data=copy.deepcopy(data),
                              experiment=Experiment(
                                  data=data_type,
                                  task=Task.table,
                                  method=copy.deepcopy(child_method),
                                  data_params=copy.deepcopy(data_params),
                              ),
                              annotations=copy.deepcopy(annotations),
                              attributes=attributes_child,
                              is_run=False,
                              is_root=False,
                              is_load_child=False)
        Node(name=str(config_child), config=config_child, parent=root)

    build_tree(root)
    calc_tree(root)
Beispiel #12
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)
Beispiel #13
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))
Beispiel #14
0
def cpg_proc_table_polygon(
    data,
    annotations,
    attributes,
    observables_list,
    child_method = Method.linreg
):
    config_root = Config(
        data=data,
        experiment=Experiment(
            type=DataType.cpg,
            task=Task.table,
            method=Method.polygon,
            params={}
        ),
        annotations=annotations,
        attributes=attributes
    )
    root = Node(name=str(config_root), config=config_root)

    for d in observables_list:

        observables_child = Observables(
            name=attributes.observables.name,
            types=d
        )

        cells_child = Cells(
            name=attributes.cells.name,
            types=attributes.cells.types
        )

        attributes_child = Attributes(
            target=attributes.target,
            observables=observables_child,
            cells=cells_child,
        )

        config_child = Config(
            data=data,
            experiment=Experiment(
                type=DataType.cpg,
                task=Task.table,
                method=child_method,
                params={}
            ),
            annotations=annotations,
            attributes=attributes_child
        )
        Node(name=str(config_child), config=config_child, parent=root)

    calc_tree(root)
Beispiel #15
0
def entropy_plot(data,
                 annotations,
                 attributes,
                 observables_list,
                 method,
                 data_params=None,
                 method_params=None):
    config_root = Config(data=copy.deepcopy(data),
                         experiment=Experiment(
                             data=DataType.entropy,
                             task=Task.plot,
                             method=method,
                             data_params=copy.deepcopy(data_params),
                             method_params=copy.deepcopy(method_params)),
                         annotations=copy.deepcopy(annotations),
                         attributes=copy.deepcopy(attributes),
                         is_run=True,
                         is_root=True)

    root = Node(name=str(config_root), config=config_root)

    for types in observables_list:
        observables_child = Observables(name=copy.deepcopy(
            attributes.observables.name),
                                        types=types)

        cells_child = Cells(name=copy.deepcopy(attributes.cells.name),
                            types=copy.deepcopy(attributes.cells.types))

        attributes_child = Attributes(
            target=copy.deepcopy(attributes.target),
            observables=observables_child,
            cells=cells_child,
        )

        config_child = Config(data=copy.deepcopy(data),
                              experiment=Experiment(
                                  data=DataType.entropy,
                                  task=Task.table,
                                  method=Method.mock,
                                  data_params=copy.deepcopy(data_params)),
                              annotations=copy.deepcopy(annotations),
                              attributes=attributes_child,
                              is_run=False,
                              is_root=False)
        Node(name=str(config_child), config=config_child, parent=root)

    build_tree(root)
    calc_tree(root)
Beispiel #16
0
def cpg_proc_special_clock_linreg_dev(
    data,
    annotations,
    attributes,
    file,
    params=None,
):
    if os.path.isfile(file):

        head, tail = os.path.split(file)
        fn = os.path.splitext(tail)[0]
        ext = os.path.splitext(tail)[1]

        config_root = Config(data=copy.deepcopy(data),
                             experiment=Experiment(
                                 type=DataType.cpg,
                                 task=Task.clock,
                                 method=Method.linreg,
                                 params=copy.deepcopy(params)),
                             annotations=copy.deepcopy(annotations),
                             attributes=copy.deepcopy(attributes),
                             is_run=True,
                             is_root=True)
        root = Node(name=str(config_root), config=config_root)

        config_child = Config(data=copy.deepcopy(data),
                              experiment=Experiment(type=DataType.cpg,
                                                    task=Task.table,
                                                    method=Method.special,
                                                    params={'file_name': fn}),
                              annotations=copy.deepcopy(annotations),
                              attributes=copy.deepcopy(attributes),
                              is_run=False,
                              is_root=False)

        Node(name=str(config_child), config=config_child, parent=root)

        build_tree(root)

        new_file = get_save_path(config_child) + '/' + \
             get_file_name(config_child) + ext

        copyfile(file, new_file)

        calc_tree(root)

    else:
        raise FileNotFoundError(f'File {file} not found.')
Beispiel #17
0
def residuals_table_approach_3(data, annotations, attributes,
                               target_sex_specific, target_age_related,
                               data_params_sex_specific,
                               data_params_age_related):
    config_root = Config(
        data=copy.deepcopy(data),
        experiment=Experiment(
            data=DataType.residuals,
            task=Task.table,
            method=Method.aggregator,
            data_params=copy.deepcopy(data_params_sex_specific)),
        annotations=copy.deepcopy(annotations),
        attributes=copy.deepcopy(attributes),
        is_run=True,
        is_root=True)
    root = Node(name=str(config_root), config=config_root)

    attributes_ss = copy.deepcopy(attributes)
    attributes_ss.target = target_sex_specific
    config_ss = Config(
        data=copy.deepcopy(data),
        experiment=Experiment(
            data=DataType.residuals,
            task=Task.table,
            method=Method.pbc,
            data_params=copy.deepcopy(data_params_sex_specific)),
        annotations=copy.deepcopy(annotations),
        attributes=attributes_ss,
        is_run=True,
        is_root=False)
    Node(name=str(config_ss), config=config_ss, parent=root)

    attributes_ar = copy.deepcopy(attributes)
    attributes_ar.target = target_age_related
    config_ar = Config(data=copy.deepcopy(data),
                       experiment=Experiment(
                           data=DataType.residuals,
                           task=Task.table,
                           method=Method.oma,
                           data_params=copy.deepcopy(data_params_age_related)),
                       annotations=copy.deepcopy(annotations),
                       attributes=attributes_ar,
                       is_run=True,
                       is_root=False)
    Node(name=str(config_ar), config=config_ar, parent=root)

    build_tree(root)
    calc_tree(root)
Beispiel #18
0
def table(
    data,
    annotations,
    attributes,
    data_type,
    method,
    data_params=None,
    task_params=None,
    method_params=None
):
    config_root = Config(
        data=copy.deepcopy(data),
        experiment=Experiment(
            data=data_type,
            task=Task.table,
            method=method,
            data_params=copy.deepcopy(data_params),
            task_params=copy.deepcopy(task_params),
            method_params=copy.deepcopy(method_params)
        ),
        annotations=copy.deepcopy(annotations),
        attributes=copy.deepcopy(attributes),
        is_run=True,
        is_root=True
    )

    root = Node(name=str(config_root), config=config_root)
    build_tree(root)
    calc_tree(root)
Beispiel #19
0
def epimutations_load(data):

    config = Config(
        data=copy.deepcopy(data),
        experiment=Experiment(
            data=DataType.epimutations,
            task=None,
            method=None
        ),
        annotations=Annotations(
            name='annotations',
            exclude='bad_cpgs',
            cross_reactive='any',
            snp='any',
            chr='NS',
            gene_region='any',
            geo='any',
            probe_class='any'
        ),
        attributes=Attributes(
            target=None,
            observables=None,
            cells=None
        ),
        is_run=True,
        is_root=True
    )

    load_epimutations(config)
Beispiel #20
0
def betas_horvath_calculator_create_regular(
    chip_type,
    observables_fn,
    data,
    data_params,
):
    annotations = Annotations(name='annotations',
                              type=chip_type,
                              exclude='none',
                              select_dict={})

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

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

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

    config_root = Config(data=copy.deepcopy(data),
                         experiment=Experiment(
                             data=DataType.betas_horvath_calculator,
                             task=Task.create,
                             method=Method.regular,
                             data_params=copy.deepcopy(data_params)),
                         annotations=copy.deepcopy(annotations),
                         attributes=copy.deepcopy(attributes),
                         is_run=True,
                         is_root=True)

    root = Node(name=str(config_root), config=config_root)
    build_tree(root)
    calc_tree(root)
Beispiel #21
0
    def setUp(self):
        data = Data(name='cpg_beta', path=ROOT_DIR, base='fixtures')

        experiment = Experiment(type=DataType.cpg,
                                task='',
                                method='',
                                params={})

        annotations = Annotations(name='annotations',
                                  exclude=CommonTypes.none.value,
                                  cross_reactive=CrossReactive.exclude.value,
                                  snp=SNP.exclude.value,
                                  chr=Chromosome.non_sex.value,
                                  gene_region=GeneRegion.yes.value,
                                  geo=CommonTypes.any.value,
                                  probe_class=CommonTypes.any.value)

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

        cells = Cells(name='cells', types=CommonTypes.any.value)

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

        self.config = Config(
            data=data,
            experiment=experiment,
            annotations=annotations,
            attributes=attributes,
        )
Beispiel #22
0
def attributes_plot_observables_histogram(
    data,
    annotations,
    attributes,
    observables_list,
):
    config_root = Config(
        data=data,
        experiment=Experiment(
            type=DataType.attributes,
            task=Task.observables,
            method=Method.histogram,
            params={}
        ),
        annotations=annotations,
        attributes=attributes
    )
    root = Node(name=str(config_root), config=config_root)

    for d in observables_list:
        observables_child = Observables(
            name=attributes.observables.name,
            types=d
        )

        cells_child = Cells(
            name=attributes.cells.name,
            types=attributes.cells.types
        )

        attributes_child = Attributes(
            target=attributes.target,
            observables=observables_child,
            cells=cells_child,
        )

        config_child = Config(
            data=data,
            experiment=config_root.experiment,
            annotations=annotations,
            attributes=attributes_child,
            is_run=False
        )
        Node(name=str(config_child), config=config_child, parent=root)

    calc_tree(root)
Beispiel #23
0
def cpg_proc_table_z_test_linreg_dev(data,
                                     annotations,
                                     attributes,
                                     observables_list,
                                     child_method=Method.linreg,
                                     params=None):
    config_root = Config(data=copy.deepcopy(data),
                         experiment=Experiment(type=DataType.cpg,
                                               task=Task.table,
                                               method=Method.z_test_linreg,
                                               params=copy.deepcopy(params)),
                         annotations=copy.deepcopy(annotations),
                         attributes=copy.deepcopy(attributes),
                         is_run=True,
                         is_root=True)
    root = Node(name=str(config_root), config=config_root)

    for d in observables_list:
        observables_child = Observables(name=copy.deepcopy(
            attributes.observables.name),
                                        types=d)

        cells_child = Cells(name=copy.deepcopy(attributes.cells.name),
                            types=copy.deepcopy(attributes.cells.types))

        attributes_child = Attributes(
            target=copy.deepcopy(attributes.target),
            observables=observables_child,
            cells=cells_child,
        )

        config_child = Config(data=copy.deepcopy(data),
                              experiment=Experiment(
                                  type=DataType.cpg,
                                  task=Task.table,
                                  method=copy.deepcopy(child_method),
                                  params={}),
                              annotations=copy.deepcopy(annotations),
                              attributes=attributes_child,
                              is_run=True,
                              is_root=False)
        Node(name=str(config_child), config=config_child, parent=root)

    build_tree(root)
    calc_tree(root)
Beispiel #24
0
def attributes_plot_observables_histogram_dev(data,
                                              annotations,
                                              attributes,
                                              observables_list,
                                              params=None):
    config_root = Config(data=copy.deepcopy(data),
                         experiment=Experiment(type=DataType.attributes,
                                               task=Task.observables,
                                               method=Method.histogram,
                                               params=copy.deepcopy(params)),
                         annotations=copy.deepcopy(annotations),
                         attributes=copy.deepcopy(attributes),
                         is_run=True,
                         is_root=True)
    root = Node(name=str(config_root), config=config_root)

    for d in observables_list:
        observables_child = Observables(name=copy.deepcopy(
            attributes.observables.name),
                                        types=d)

        cells_child = Cells(name=copy.deepcopy(attributes.cells.name),
                            types=copy.deepcopy(attributes.cells.types))

        attributes_child = Attributes(
            target=copy.deepcopy(attributes.target),
            observables=observables_child,
            cells=cells_child,
        )

        config_child = Config(data=copy.deepcopy(data),
                              experiment=config_root.experiment,
                              annotations=copy.deepcopy(annotations),
                              attributes=attributes_child,
                              is_run=False,
                              is_root=True)
        Node(name=str(config_child), config=config_child, parent=root)

    build_tree(root)
    calc_tree(root)
Beispiel #25
0
def load_beta_config(data, annotations, attributes, data_params=None):
    config = Config(data=copy.deepcopy(data),
                    experiment=Experiment(
                        data=DataType.betas,
                        task=Task.load,
                        method=Method.mock,
                        data_params=copy.deepcopy(data_params)),
                    annotations=copy.deepcopy(annotations),
                    attributes=copy.deepcopy(attributes),
                    is_run=True,
                    is_root=True)

    context = Context(config)
    context.load(config)

    return config
Beispiel #26
0
def epimutations_load(data):

    config = Config(data=copy.deepcopy(data),
                    experiment=Experiment(data=DataType.epimutations,
                                          task=None,
                                          method=None),
                    annotations=Annotations(name='annotations',
                                            type='450k',
                                            exclude='bad_cpgs',
                                            select_dict={'CHR': ['-X', '-Y']}),
                    attributes=Attributes(target=None,
                                          observables=None,
                                          cells=None),
                    is_run=True,
                    is_root=True)

    load_epimutations(config)
Beispiel #27
0
def cpg_proc_table_variance_linreg_dev(data,
                                       annotations,
                                       attributes,
                                       params=None):
    config_root = Config(data=copy.deepcopy(data),
                         experiment=Experiment(type=DataType.cpg,
                                               task=Task.table,
                                               method=Method.variance_linreg,
                                               params=copy.deepcopy(params)),
                         annotations=copy.deepcopy(annotations),
                         attributes=copy.deepcopy(attributes),
                         is_run=True,
                         is_root=True)

    root = Node(name=str(config_root), config=config_root)
    build_tree(root)
    calc_tree(root)
Beispiel #28
0
def cpg_proc_table_variance_linreg(
    data,
    annotations,
    attributes
):
    config_root = Config(
        data=data,
        experiment=Experiment(
            type=DataType.cpg,
            task=Task.table,
            method=Method.variance_linreg,
            params={}
        ),
        annotations=annotations,
        attributes=attributes
    )

    root = Node(name=str(config_root), config=config_root)
    calc_tree(root)
Beispiel #29
0
def betas_spec_create_regular(
    data,
    data_params,
    observables
):
    annotations = Annotations(
        name='annotations',
        type='450k',
        exclude='none',
        select_dict={
            'CHR': ['-X', '-Y']
        }
    )

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

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

    config_root = Config(
        data=copy.deepcopy(data),
        experiment=Experiment(
            data=DataType.betas_spec,
            task=Task.create,
            method=Method.regular,
            data_params=data_params
        ),
        annotations=copy.deepcopy(annotations),
        attributes=copy.deepcopy(attributes),
        is_run=True,
        is_root=True
    )

    root = Node(name=str(config_root), config=config_root)
    build_tree(root)
    calc_tree(root)
Beispiel #30
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))