Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 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)
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 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)
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
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)
Esempio n. 14
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.')
Esempio n. 15
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)
Esempio n. 16
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)
Esempio n. 17
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)
Esempio n. 18
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)
Esempio n. 19
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)
Esempio n. 20
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)
Esempio n. 21
0
def cpg_proc_table_aggregator_dev(data,
                                  annotations,
                                  attributes,
                                  observables_list,
                                  params=None):
    child_methods_lvl_1 = [Method.polygon, Method.z_test_linreg]
    child_methods_lvl_2 = [Method.linreg]

    config_root = Config(data=copy.deepcopy(data),
                         experiment=Experiment(type=DataType.cpg,
                                               task=Task.table,
                                               method=Method.aggregator,
                                               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 child_method_lvl_1 in child_methods_lvl_1:
        config_lvl_1 = Config(data=copy.deepcopy(data),
                              experiment=Experiment(type=DataType.cpg,
                                                    task=Task.table,
                                                    method=child_method_lvl_1,
                                                    params={}),
                              annotations=copy.deepcopy(annotations),
                              attributes=copy.deepcopy(attributes),
                              is_run=True,
                              is_root=False)
        node_lvl_1 = Node(name=str(config_lvl_1),
                          config=config_lvl_1,
                          parent=root)

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

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

                attributes_lvl_2 = Attributes(
                    target=copy.deepcopy(attributes.target),
                    observables=observables_lvl_2,
                    cells=cells_lvl_2,
                )

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

    build_tree(root)
    calc_tree(root)
Esempio n. 22
0
def observables_plot_histogram(
    data,
    annotations,
    attributes,
    observables_list,
    method_params=None
):
    """
        Plotting histogram for target observable distribution for provided subjects subsets and provided CpG list.

        Possible parameters of experiment:

        * ``'bin_size'``: bin size for numeric target. \n
          For categorical target is not considered.
        * ``'opacity'``: opacity level.
          From ``0.0`` to ``1.0``.
        * ``'barmode'``: type of barmode. \n
          Possible options: \n
          ``'overlay'`` for overlaid histograms. \n
          ``'stack'`` for stacked histograms. \n
        * ``'x_range'``: can be ``'auto'`` or list with two elements, which are borders of target axis.

        :param data: pdm.Data instance, which specifies information about dataset.
        :param annotations: pdm.Annotations instance, which specifies subset of CpGs.
        :param attributes: pdm.Attributes instance, which specifies information about subjects.
        :param cpg_list: List of CpGs for plotting
        :param observables_list: list of subjects subsets. Each element in list is dict,
         where ``key`` is observable name and ``value`` is possible values for this observable.
        :param method_params: parameters of experiment.
    """

    config_root = Config(
        data=copy.deepcopy(data),
        experiment=Experiment(
            data=DataType.observables,
            task=Task.observables,
            method=Method.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
    )
    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,
            is_load_child=False
        )
        Node(name=str(config_child), config=config_child, parent=root)

    build_tree(root)
    calc_tree(root)
Esempio n. 23
0
def table_aggregator_linreg(
    data_type,
    data,
    annotations,
    attributes,
    observables_list,
    data_params=None,
    task_params=None,
    method_params=None
):
    child_methods_lvl_1 = [Method.polygon, Method.z_test_linreg]
    child_methods_lvl_2 = [Method.linreg]

    config_root = Config(
        data=copy.deepcopy(data),
        experiment=Experiment(
            data=data_type,
            task=Task.table,
            method=Method.aggregator,
            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)

    for child_method_lvl_1 in child_methods_lvl_1:

        if child_method_lvl_1 == Method.polygon:
            method_params = {'method': Method.linreg}
            is_load_child = True
        elif child_method_lvl_1 == Method.z_test_linreg:
            method_params = {}
            is_load_child = True
        elif child_method_lvl_1 == Method.ancova:
            method_params = {}
            is_load_child = True
        else:
            method_params = {}
            is_load_child = False

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

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

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

                attributes_lvl_2 = Attributes(
                    target=copy.deepcopy(attributes.target),
                    observables=observables_lvl_2,
                    cells=cells_lvl_2,
                )

                config_lvl_2 = Config(
                    data=copy.deepcopy(data),
                    experiment=Experiment(
                        data=data_type,
                        task=Task.table,
                        method=copy.deepcopy(child_method_lvl_2),
                        data_params=copy.deepcopy(data_params),
                    ),
                    annotations=copy.deepcopy(annotations),
                    attributes=attributes_lvl_2,
                    is_run=True,
                    is_root=False,
                    is_load_child=is_load_child
                )
                Node(name=str(config_lvl_2), config=config_lvl_2, parent=node_lvl_1)

    build_tree(root)
    calc_tree(root)
Esempio n. 24
0
def betas_clock_special(
    data,
    annotations,
    attributes,
    file,
    method_params=None,
):
    """
        Producing epigentic clock, using best CpGs which are provided in input file.

        Epigentic clock represents as table:
        Each row corresponds to clocks, which are built on all CpGs from the previous rows including the current row.
        Columns:

        * item: CpG id.
        * aux: gene, on which CpG is mapped.
        * R2: determination coefficient of linear regression between real and predicted target observable.
          A statistical measure of how well the regression line approximates the data points.
        * r: correlation coefficient of linear regression between real and predicted target observable.
        * evs: explained variance regression score.
        * mae: mean absolute error regression loss.
        * rmse: root mean square error

        Possible parameters of experiment:

        * ``'type'``: type of clocks. \n
          Possible options: \n
          ``'all'``: iterative building of clocks starting from one element in the model,
          ending with ``'size'`` elements in the model. \n
          ``'single '``: building of clocks only with ``'size'`` elements in the model. \n
          ``'deep'``: iterative building of clocks starting from one element in the model,
          ending with ``'size'`` elements in the model, but choosing all possible combinations from ``'size'`` elements.
        * ``'part'``: the proportion of considered number of subject in the test set. From ``0.0`` to ``1.0``.
        * ``'size'``: maximum number of exogenous variables in a model.
        * ``'runs'`` number of bootstrap runs in model

        :param data: pdm.Data instance, which specifies information about dataset.
        :param annotations: pdm.Annotations instance, which specifies subset of CpGs.
        :param attributes: pdm.Attributes instance, which specifies information about subjects.
        :param method_params: parameters of experiment.
     """

    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(
                                 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.special,
                                  method_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.')
Esempio n. 25
0
def table_ancova(
    data_type,
    data,
    annotations,
    attributes,
    observables_list,
    data_params=None,
    task_params=None,
    method_params=None
):

    config_ancova = Config(
        data=copy.deepcopy(data),
        experiment=Experiment(
            data=data_type,
            task=Task.table,
            method=Method.ancova,
            data_params=copy.deepcopy(data_params),
            method_params=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_ancova), config=config_ancova)

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

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

        attributes_linreg = Attributes(
            target=copy.deepcopy(attributes.target),
            observables=observables_linreg,
            cells=cells_linreg,
        )

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

    build_tree(root)
    calc_tree(root)
Esempio n. 26
0
def betas_plot_curve_clock(data,
                           annotations,
                           attributes,
                           observables_list,
                           child_method=Method.linreg,
                           data_params=None,
                           method_params=None):
    data_type = DataType.betas

    clock_method_params = {
        'type': 'all',
        'part': 0.25,
        'size': 100,
        'runs': 100,
    }

    config_root = Config(data=copy.deepcopy(data),
                         experiment=Experiment(
                             data=data_type,
                             task=Task.plot,
                             method=Method.curve,
                             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,
                         is_load_child=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_lvl_1 = Config(data=copy.deepcopy(data),
                                    experiment=Experiment(
                                        data=data_type,
                                        task=Task.clock,
                                        method=copy.deepcopy(child_method),
                                        data_params=copy.deepcopy(data_params),
                                        method_params=clock_method_params),
                                    annotations=copy.deepcopy(annotations),
                                    attributes=attributes_child,
                                    is_run=False,
                                    is_root=False,
                                    is_load_child=False)
        node_lvl_1 = Node(name=str(config_child_lvl_1),
                          config=config_child_lvl_1,
                          parent=root)

        config_child_lvl_2 = Config(data=copy.deepcopy(data),
                                    experiment=Experiment(
                                        data=data_type,
                                        task=Task.table,
                                        method=Method.linreg),
                                    annotations=copy.deepcopy(annotations),
                                    attributes=attributes_child,
                                    is_run=False,
                                    is_root=False)
        Node(name=str(config_child_lvl_2),
             config=config_child_lvl_2,
             parent=node_lvl_1)

    build_tree(root)
    calc_tree(root)
Esempio n. 27
0
def table_aggregator_variance(
    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)

    config_lvl_1 = Config(
        data=copy.deepcopy(data),
        experiment=Experiment(
            data=data_type,
            task=Task.table,
            method=Method.polygon,
            data_params=copy.deepcopy(data_params),
            method_params={'method': Method.variance}
        ),
        annotations=copy.deepcopy(annotations),
        attributes=copy.deepcopy(attributes),
        is_run=True,
        is_root=False
    )
    node_lvl_1 = Node(name=str(config_lvl_1), config=config_lvl_1, parent=root)

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

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

        attributes_lvl_2 = Attributes(
            target=copy.deepcopy(attributes.target),
            observables=observables_lvl_2,
            cells=cells_lvl_2,
        )

        config_lvl_2 = Config(
            data=copy.deepcopy(data),
            experiment=Experiment(
                data=data_type,
                task=Task.table,
                method=Method.variance,
                data_params=copy.deepcopy(data_params),
                method_params={
                    'semi_window': 8,
                    'box_b': 'Q5',
                    'box_t': 'Q95',
                }
            ),
            annotations=copy.deepcopy(annotations),
            attributes=attributes_lvl_2,
            is_run=True,
            is_root=False
        )
        Node(name=str(config_lvl_2), config=config_lvl_2, parent=node_lvl_1)

    cluster_types = copy.deepcopy(observables_list[0])
    cluster_types.pop('gender', None)
    cluster_types.pop('sex', None)
    observables_cluster = Observables(
        name=copy.deepcopy(attributes.observables.name),
        types=cluster_types
    )

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

    attributes_cluster = Attributes(
        target=copy.deepcopy(attributes.target),
        observables=observables_cluster,
        cells=cells_cluster,
    )

    config_cluster = Config(
        data=copy.deepcopy(data),
        experiment=Experiment(
            data=data_type,
            task=Task.table,
            method=Method.cluster,
            data_params=copy.deepcopy(data_params),
            method_params={
                'eps': 0.2,
                'min_samples_percentage': 1
            }
        ),
        annotations=copy.deepcopy(annotations),
        attributes=attributes_cluster,
        is_run=True,
        is_root=False
    )
    Node(name=str(config_cluster), config=config_cluster, parent=root)

    build_tree(root)
    calc_tree(root)
Esempio n. 28
0
def plot_scatter_comparison(
    data_type,
    data_list,
    annotations_list,
    attributes_list,
    observables_list,
    data_params_list,
    rows_dict,
    cols_dict,
    child_method=Method.linreg,
    method_params=None,
):

    data = copy.deepcopy(data_list[0])
    data.base = 'comparison'
    annotations = annotations_list[0]
    attributes = attributes_list[0]

    items = rows_dict['items']
    reverses = rows_dict['reverses']
    data_bases = cols_dict['data_bases']

    task_params = {'type': 'run'}

    method_params['items'] = items
    method_params['reverses'] = reverses
    method_params['data_bases'] = data_bases
    if 'aux' in rows_dict:
        method_params['aux'] = rows_dict['aux']
    method_params['x_ranges'] = []
    for data_base_id, data_base in enumerate(data_bases):
        method_params['x_ranges'].append([
            cols_dict['begins'][data_base_id], cols_dict['ends'][data_base_id]
        ])

    method_params['y_ranges'] = []
    for item_id in range(0, len(items)):
        method_params['y_ranges'].append(
            [rows_dict['begins'][item_id], rows_dict['ends'][item_id]])

    config_root = Config(data=copy.deepcopy(data),
                         experiment=Experiment(
                             data=data_type,
                             task=Task.plot,
                             method=Method.scatter_comparison,
                             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,
                         is_init=False,
                         is_init_child=False)
    root = Node(name=str(config_root), config=config_root)

    for data_base_id, data_base in enumerate(data_bases):
        method_params_lvl_1 = copy.deepcopy(method_params)
        method_params_lvl_1['items'] = items
        method_params_lvl_1['reverses'] = reverses
        method_params_lvl_1['x_ranges'] = [
            cols_dict['begins'][data_base_id], cols_dict['ends'][data_base_id]
        ]
        method_params_lvl_1['y_ranges'] = []

        for item_id in range(0, len(items)):
            method_params_lvl_1['y_ranges'].append(
                [rows_dict['begins'][item_id], rows_dict['ends'][item_id]])

        task_params_lvl_1 = {'type': 'prepare'}

        config_lvl_1 = Config(
            data=copy.deepcopy(data_list[data_base_id]),
            experiment=Experiment(data=data_type,
                                  task=Task.plot,
                                  method=Method.scatter,
                                  data_params=copy.deepcopy(
                                      data_params_list[data_base_id]),
                                  task_params=task_params_lvl_1,
                                  method_params=method_params_lvl_1),
            annotations=copy.deepcopy(annotations_list[data_base_id]),
            attributes=copy.deepcopy(attributes_list[data_base_id]),
            is_run=True,
            is_root=False,
            is_load_child=False)

        node_lvl_1 = Node(name=str(config_lvl_1),
                          config=config_lvl_1,
                          parent=root)

        for d in observables_list[data_base_id]:
            observables_child = Observables(name=copy.deepcopy(
                attributes_list[data_base_id].observables.name),
                                            types=d)

            cells_child = Cells(
                name=copy.deepcopy(attributes_list[data_base_id].cells.name),
                types=copy.deepcopy(attributes_list[data_base_id].cells.types))

            attributes_child = Attributes(
                target=copy.deepcopy(attributes_list[data_base_id].target),
                observables=observables_child,
                cells=cells_child,
            )

            config_child = Config(
                data=copy.deepcopy(data_list[data_base_id]),
                experiment=Experiment(
                    data=data_type,
                    task=Task.table,
                    method=copy.deepcopy(child_method),
                    data_params=copy.deepcopy(data_params_list[data_base_id]),
                ),
                annotations=copy.deepcopy(annotations_list[data_base_id]),
                attributes=attributes_child,
                is_run=False,
                is_root=False,
                is_load_child=False)
            Node(name=str(config_child),
                 config=config_child,
                 parent=node_lvl_1)

    build_tree(root)
    calc_tree(root)