예제 #1
0
    def to_dict(self, block):
        result = {}
        for f_name, f in self.fields.iteritems():
            if f.field_type == FieldType.HIDDEN:
                continue

            with stopwatch(name="Serializing block field %s" % f_name,
                           threshold=0.01):
                raw_val = getattr(block, f_name)
                result[f_name] = f.value_to_dict(raw_val, block)

        params_protype = {
            str(param_name): param_field.to_dict()
            for param_name, param_field in self.params.iteritems()
        }
        result["_params_prototype"] = params_protype
        result["_params_prototype_list"] = params_protype.values()

        for f_name, f in self.params.iteritems():
            with stopwatch(name="Serializing block param %s" % f_name,
                           threshold=0.01):
                raw_val = getattr(block, f.name)
                result[f_name] = f.value_to_dict(raw_val, block)

        result["actions"] = [{
            "code": ar.name,
            "title": ar.user_title,
        } for ar in block.get_user_actions()]

        result["out"] = block.out_manager.to_dict(block)
        result["inputs"] = block.input_manager.to_dict()

        return result
예제 #2
0
    def to_dict(self, block):
        result = {}
        for f_name, f in self.fields.iteritems():
            if f.field_type == FieldType.HIDDEN:
                continue

            with stopwatch(name="Serializing block field %s" % f_name, threshold=0.01):
                raw_val = getattr(block, f_name)
                result[f_name] = f.value_to_dict(raw_val, block)

        params_protype = {
            str(param_name): param_field.to_dict()
            for param_name, param_field in self.params.iteritems()
        }
        result["_params_prototype"] = params_protype
        result["_params_prototype_list"] = params_protype.values()

        for f_name, f in self.params.iteritems():
            with stopwatch(name="Serializing block param %s" % f_name, threshold=0.01):
                raw_val = getattr(block, f.name)
                result[f_name] = f.value_to_dict(raw_val, block)

        result["actions"] = [{
            "code": ar.name,
            "title": ar.user_title,
        } for ar in block.get_user_actions()]

        result["out"] = block.out_manager.to_dict(block)
        result["inputs"] = block.input_manager.to_dict()

        return result
예제 #3
0
def apply_ranking(
        exp, block,
        es, ranking_name,
        result_table,
        pheno_class_column=None, options=None
):
    if not options:
        options = {}
    if not pheno_class_column:
        pheno_class_column = es.pheno_metadata["user_class_title"]

    R.r['source'](R_LIB_CUSTOM_PATH + '/ranking.Methods.r')
    func = R.r[ranking_name]

    assay_df = es.get_assay_data_frame()
    x = com.convert_to_r_matrix(assay_df)
    y = es.get_pheno_column_as_r_obj(pheno_class_column)

    log.debug("Computing ranking: `%s` options: `%s`", ranking_name, options)
    with stopwatch(name="Computing ranking: `%s` options: `%s`" % (ranking_name, options),
                   threshold=0.01):
        ranking_list = list(func(R.r['t'](x), y, **options))

    ranking_fixed = map(lambda a: int(a - 1), ranking_list)
    df = pd.DataFrame(
        index=assay_df.index,
        data=[len(assay_df)] * len(assay_df), columns=["rank"]
    )
    for rank, row_num in enumerate(ranking_fixed):
        df.ix[row_num, "rank"] = rank

    result_table.store_table(df)
    return [result_table], {}
예제 #4
0
def apply_ranking(exp,
                  block,
                  es,
                  ranking_name,
                  result_table,
                  pheno_class_column=None,
                  options=None):
    if not options:
        options = {}
    if not pheno_class_column:
        pheno_class_column = es.pheno_metadata["user_class_title"]

    R.r['source'](R_LIB_CUSTOM_PATH + '/ranking.Methods.r')
    func = R.r[ranking_name]

    assay_df = es.get_assay_data_frame()
    x = com.convert_to_r_matrix(assay_df)
    y = es.get_pheno_column_as_r_obj(pheno_class_column)

    log.debug("Computing ranking: `%s` options: `%s`", ranking_name, options)
    with stopwatch(name="Computing ranking: `%s` options: `%s`" %
                   (ranking_name, options),
                   threshold=0.01):
        ranking_list = list(func(R.r['t'](x), y, **options))

    ranking_fixed = map(lambda a: int(a - 1), ranking_list)
    df = pd.DataFrame(index=assay_df.index,
                      data=[len(assay_df)] * len(assay_df),
                      columns=["rank"])
    for rank, row_num in enumerate(ranking_fixed):
        df.ix[row_num, "rank"] = rank

    result_table.store_table(df)
    return [result_table], {}
예제 #5
0
def apply_ranking(
        exp, block,
        es, ranking_name,
        result_table,
        pheno_class_column=None, options=None
):
    if not options:
        options = {}
    if not pheno_class_column:
        pheno_class_column = es.pheno_metadata["user_class_title"]

    R.r['source'](R_LIB_CUSTOM_PATH + '/ranking.Methods.r')
    func = R.r[ranking_name]
    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)

    assay_df = es.get_assay_data_frame()
    cols = assay_df.columns

    # We must rename cols to be unique for R
    out_genes = {}
    out_cols = []
    for i, g in enumerate(cols):
        g = g.split('.')[0]
        if g in out_genes:
            new_g = g + '__' + str(i)
            out_genes[g].append(new_g)
            out_cols.append(new_g)
        else:
            out_genes[g] = [g]
            out_cols.append(g)
    assay_df.columns = out_cols
    assay_df = assay_df.T

    x = com.convert_to_r_matrix(assay_df)
    y = es.get_pheno_column_as_r_obj(pheno_class_column)
    exp.log(block.uuid, "Computing ranking: `%s` options: `%s`" % (ranking_name, options))
    log.debug("Computing ranking: `%s` options: `%s`", ranking_name, options)
    with stopwatch(name="Computing ranking: `%s` options: `%s`" % (ranking_name, options),
                   threshold=0.01):
        ranking_list = list(func(R.r['t'](x), y, **options))

    ranking_fixed = map(lambda a: int(a - 1), ranking_list)
    df = pd.DataFrame(
        index=assay_df.index,
        data=[len(assay_df)] * len(assay_df), columns=["rank"]
    )
    for rank, row_num in enumerate(ranking_fixed):
        df.ix[row_num, "rank"] = rank

    result_table.store_table(df)
    return [result_table], {}