Beispiel #1
0
    def build_result_collection(self, exp):
        rc = ResultsContainer(
            base_dir=exp.get_data_folder(),
            base_filename="%s" % self.uuid
        )
        res_seq = self.res_seq

        axis_meta_block = self.base_name
        axis_meta_block_labels = self.get_fold_labels()


        def create_new_dim_rc(local_rc):
            local_rc.axis_list = [axis_meta_block]
            local_rc.labels_dict[axis_meta_block] = axis_meta_block_labels

            local_rc.init_ar()
            local_rc.update_label_index()

        # WARNING: We only support homogeneous results, so we only check first element
        res_seq_field_name, data_type = res_seq.fields.iteritems().next()
        if data_type == "ClassifierResult":
            single_rc_list = []
            for field_name in res_seq.fields:
                rc_single = ResultsContainer("", "")
                create_new_dim_rc(rc_single)

                for idx, res_seq_cell in enumerate(res_seq.sequence):
                    rc_single.ar[idx] = res_seq_cell[field_name]
                single_rc_list.append(rc_single)

            rc.add_dim_layer(single_rc_list, self.collector_spec.label, res_seq.fields.keys())

        elif data_type == "ResultsContainer":
            if len(res_seq.fields) > 1:
                raise Exception("Meta block only support single output of type ResultsContainer")

            else:
                rc_list = []
                for cell in res_seq.sequence:
                    sub_rc = cell[res_seq_field_name]
                    sub_rc.load()
                    rc_list.append(sub_rc)

                rc.add_dim_layer(rc_list, self.base_name, self.get_fold_labels())

        elif data_type == "SequenceContainer":
            # TODO remove this check
            pass
        else:
            raise Exception("Meta blocks only support ClassifierResult "
                            "or ResultsContainer in the output collection. "
                            " Instead got: %s" % data_type)

        rc.store()
        rc.ar = None
        self.set_out_var("results_container", rc)
Beispiel #2
0
    def build_result_collection(self, exp):
        if settings.CELERY_DEBUG:
            import sys
            sys.path.append('/Migration/skola/phd/projects/miXGENE/mixgene_project/wrappers/pycharm-debug.egg')
            import pydevd
            pydevd.settrace('localhost', port=6901, stdoutToServer=True, stderrToServer=True)

        rc = ResultsContainer(
            base_dir=exp.get_data_folder(),
            base_filename="%s" % self.uuid
        )
        res_seq = self.res_seq

        axis_meta_block = self.base_name
        axis_meta_block_labels = self.get_fold_labels()
        def create_new_dim_rc(local_rc):
            local_rc.axis_list = [axis_meta_block]
            local_rc.labels_dict[axis_meta_block] = axis_meta_block_labels
            local_rc.init_ar()
            local_rc.update_label_index()

        # WARNING: We only support homogeneous results, so we only check first element
        res_seq_field_name, data_type = res_seq.fields.iteritems().next()
        if data_type == "ClassifierResult":
            single_rc_list = []
            for field_name in res_seq.fields:
                rc_single = ResultsContainer("", "")
                create_new_dim_rc(rc_single)
                for idx, res_seq_cell in enumerate(res_seq.sequence):
                    rc_single.ar[idx] = res_seq_cell[field_name]
                single_rc_list.append(rc_single)

            rc.add_dim_layer(single_rc_list, self.collector_spec.label, res_seq.fields.keys())

        elif data_type == "ResultsContainer":
            if len(res_seq.fields) > 1:
                raise Exception("Meta block only support single output of type ResultsContainer")

            else:
                rc_list = []
                for cell in res_seq.sequence:
                    sub_rc = cell[res_seq_field_name]
                    sub_rc.load()
                    rc_list.append(sub_rc)

                rc.add_dim_layer(rc_list, self.base_name, self.get_fold_labels())

        elif data_type == "SequenceContainer":
            # TODO remove this check
            pass
        else:
            raise Exception("Meta blocks only support ClassifierResult "
                            "or ResultsContainer in the output collection. "
                            " Instead got: %s" % data_type)

        rc.store()
        rc.ar = None
        self.set_out_var("results_container", rc)
Beispiel #3
0
def main(base_dir, base_filename):
    rc1 = ResultsContainer("", "")
    rc1.ar = np.empty(shape=(2, ), dtype=object)
    rc1.axis_list = ["classifiers"]
    rc1.labels_dict["classifiers"] = ["svm", "dt"]

    from environment.structures import ClassifierResult
    c1 = ClassifierResult("", "")
    c1.scores["accuracy"] = 0.8
    c2 = ClassifierResult("", "")
    c2.scores["accuracy"] = 0.95

    rc1.ar[0] = c1
    rc1.ar[1] = c2

    rc2 = copy.deepcopy(rc1)
    rc3 = copy.deepcopy(rc1)
    rc4 = copy.deepcopy(rc1)

    d2_rc = ResultsContainer("", "")
    d2_rc.add_dim_layer([rc1, rc2, rc3, rc4], "cv_folds",
                        ["f1", "f2", "f3", "f4"])

    d2rc1 = copy.deepcopy(d2_rc)
    d2rc2 = copy.deepcopy(d2_rc)
    d2rc3 = copy.deepcopy(d2_rc)

    d3_rc = ResultsContainer(base_dir, base_filename)

    d3_rc.add_dim_layer([d2rc1, d2rc2, d2rc3], "fenotype_features",
                        ["age", "sex", "tissue"])

    return d3_rc
Beispiel #4
0
    rc2 = copy.deepcopy(rc1)
    rc3 = copy.deepcopy(rc1)
    rc4 = copy.deepcopy(rc1)

    d2_rc = ResultsContainer("", "")
    d2_rc.add_dim_layer([rc1, rc2, rc3, rc4], "cv_folds",
                        ["f1", "f2", "f3", "f4"])

    d2rc1 = copy.deepcopy(d2_rc)
    d2rc2 = copy.deepcopy(d2_rc)
    d2rc3 = copy.deepcopy(d2_rc)

    d3_rc = ResultsContainer(base_dir, base_filename)

    d3_rc.add_dim_layer([d2rc1, d2rc2, d2rc3], "fenotype_features",
                        ["age", "sex", "tissue"])

    return d3_rc


if __name__ == "__main__":
    r = main(".", "tmp.gz")
    r.store()

    r2 = ResultsContainer(".", "tmp.gz")
    r2.load()
    print r2.to_dict()
    print r2.ar

    #print r2.({"cv_folds": ("f2",)})
Beispiel #5
0
    def build_result_collection(self, exp):
        rc = ResultsContainer(base_dir=exp.get_data_folder(),
                              base_filename="%s" % self.uuid)
        res_seq = self.res_seq

        axis_meta_block = self.base_name
        axis_meta_block_labels = self.get_fold_labels()

        def create_new_dim_rc(local_rc):
            local_rc.axis_list = [axis_meta_block]
            local_rc.labels_dict[axis_meta_block] = axis_meta_block_labels

            local_rc.init_ar()
            local_rc.update_label_index()

        # WARNING: We only support homogeneous results, so we only check first element
        res_seq_field_name, data_type = res_seq.fields.iteritems().next()
        if data_type == "ClassifierResult":
            single_rc_list = []
            for field_name in res_seq.fields:
                rc_single = ResultsContainer("", "")
                create_new_dim_rc(rc_single)

                for idx, res_seq_cell in enumerate(res_seq.sequence):
                    rc_single.ar[idx] = res_seq_cell[field_name]
                single_rc_list.append(rc_single)

            rc.add_dim_layer(single_rc_list, self.collector_spec.label,
                             res_seq.fields.keys())

        elif data_type == "ResultsContainer":
            if len(res_seq.fields) > 1:
                raise Exception(
                    "Meta block only support single output of type ResultsContainer"
                )

            else:
                rc_list = []
                for cell in res_seq.sequence:
                    sub_rc = cell[res_seq_field_name]
                    sub_rc.load()
                    rc_list.append(sub_rc)

                rc.add_dim_layer(rc_list, self.base_name,
                                 self.get_fold_labels())

        elif data_type == "SequenceContainer":
            # TODO remove this check
            pass
        else:
            raise Exception("Meta blocks only support ClassifierResult "
                            "or ResultsContainer in the output collection. "
                            " Instead got: %s" % data_type)

        rc.store()
        rc.ar = None
        self.set_out_var("results_container", rc)
Beispiel #6
0
def main(base_dir, base_filename):
    rc1 = ResultsContainer("", "")
    rc1.ar = np.empty(shape=(2,), dtype=object)
    rc1.axis_list = ["classifiers"]
    rc1.labels_dict["classifiers"] = ["svm", "dt"]

    from environment.structures import ClassifierResult
    c1 = ClassifierResult("", "")
    c1.scores["accuracy"] = 0.8
    c2 = ClassifierResult("", "")
    c2.scores["accuracy"] = 0.95

    rc1.ar[0] = c1
    rc1.ar[1] = c2

    rc2 = copy.deepcopy(rc1)
    rc3 = copy.deepcopy(rc1)
    rc4 = copy.deepcopy(rc1)

    d2_rc = ResultsContainer("", "")
    d2_rc.add_dim_layer([rc1, rc2, rc3, rc4], "cv_folds", ["f1", "f2", "f3", "f4"])

    d2rc1 = copy.deepcopy(d2_rc)
    d2rc2 = copy.deepcopy(d2_rc)
    d2rc3 = copy.deepcopy(d2_rc)


    d3_rc = ResultsContainer(base_dir, base_filename)

    d3_rc.add_dim_layer([d2rc1, d2rc2, d2rc3], "fenotype_features",
                                                ["age", "sex", "tissue"])


    return d3_rc
Beispiel #7
0
    rc2 = copy.deepcopy(rc1)
    rc3 = copy.deepcopy(rc1)
    rc4 = copy.deepcopy(rc1)

    d2_rc = ResultsContainer("", "")
    d2_rc.add_dim_layer([rc1, rc2, rc3, rc4], "cv_folds", ["f1", "f2", "f3", "f4"])

    d2rc1 = copy.deepcopy(d2_rc)
    d2rc2 = copy.deepcopy(d2_rc)
    d2rc3 = copy.deepcopy(d2_rc)


    d3_rc = ResultsContainer(base_dir, base_filename)

    d3_rc.add_dim_layer([d2rc1, d2rc2, d2rc3], "fenotype_features",
                                                ["age", "sex", "tissue"])


    return d3_rc

if __name__ == "__main__":
    r = main(".", "tmp.gz")
    r.store()

    r2 = ResultsContainer(".", "tmp.gz")
    r2.load()
    print r2.to_dict()
    print r2.ar

    #print r2.({"cv_folds": ("f2",)})