Esempio n. 1
0
def preprocessing_pdf():
    file_name = request.args.get("filename")

    #preprocess = UserData.get_preprocess_from_id(id)
    preprocess = UserData.get_user_preprocess(g.user["id"], file_name)

    col_sel_method_set = ['Average', 'Max', 'Min', 'Interquartile range']

    if (preprocess['col_sel_method'] == ''):
        preprocess_data = {
            "file_name": preprocess['file_name'],
            "annotation_table": '-',
            "prob_mthd": '-',
            "normalize": preprocess['scaling'],
            "imputation": preprocess['imputation'],
            "volcano_hash": preprocess['volcano_hash'],
            "fold": preprocess['fold'],
            "pvalue": preprocess['pvalue'],
            "univariate_length": preprocess['length'],
            "fr_univariate_hash": preprocess['fr_univariate_hash']
        }
    else:
        preprocess_data = {
            "file_name":
            preprocess['file_name'],
            "annotation_table":
            (preprocess['annotation_table']).replace('/AnnotationTbls/', ''),
            "prob_mthd":
            col_sel_method_set[int(preprocess['col_sel_method']) - 1],
            "normalize":
            preprocess['scaling'],
            "imputation":
            preprocess['imputation'],
            "volcano_hash":
            preprocess['volcano_hash'],
            "fold":
            preprocess['fold'],
            "pvalue":
            preprocess['pvalue'],
            "univariate_length":
            preprocess['length'],
            "fr_univariate_hash":
            preprocess['fr_univariate_hash']
        }

    preprocess_data_plot = {
        "volcano_hash": preprocess['volcano_hash'],
        "fold": preprocess['fold'],
        "pvalue": preprocess['pvalue'],
        "univariate_length": preprocess['length'],
        "fr_univariate_hash": preprocess['fr_univariate_hash']
    }

    return render_template("pdf/preprocess_pdf.html",
                           data=preprocess_data,
                           data_after_norm=preprocess['after_norm_set'],
                           data_plot=preprocess_data_plot,
                           clf_results=preprocess['classification_result_set'])
Esempio n. 2
0
def skip_df_mapping():
    user_id = g.user['id']
    file_name = request.args.get("selected_file")

    if not file_name:
        return redirect('./pre')

    file_path = USER_PATH / str(user_id) / file_name

    UserData.delete_preprocess_file(user_id, file_name)

    UserData.add_preprocess(user_id, file_name, file_path.as_posix(), '', '',
                            '')
    pre_process_id = UserData.get_user_preprocess(user_id, file_name)['id']

    df = PreProcess.getDF(file_path)
    data = PreProcess.get_df_details(df, None)

    session[file_name] = data

    return redirect(
        url_for('preprocess.scaling_imputation') + "?id=" +
        str(pre_process_id))
Esempio n. 3
0
def view_merge_df():
    user_id = g.user["id"]
    annotation_table = request.form.get("anno_tbl")
    col_sel_method = request.form.get("column_selection")
    file_name = request.form.get("available_files")

    if annotation_table and col_sel_method and file_name:

        file_path = USER_PATH / str(user_id) / file_name

        # Delete query if file already pre-processed
        UserData.delete_preprocess_file(user_id, file_name)

        if annotation_table == 'other':
            file = request.files['chooseFile']

            if file and allowed_file(file.filename):

                annotation_table = secure_filename(file.filename)
                path_csv = ANNOTATION_TBL / "other" / (str(user_id) + "_" +
                                                       annotation_table)

                # Delete same file uploaded
                result = UserData.get_user_file_by_file_name(
                    user_id, annotation_table)

                annotation_df = pd.read_csv(file, usecols=[0, 1], header=0)
                col = annotation_df.columns

                if "ID" in col and "Gene Symbol" in col and len(col) == 2:
                    annotation_df.to_csv(path_csv, index=False)

                else:
                    flash(
                        "Wrong Format: Gene Symbol and/or ID column not found in annotation table."
                    )
                    return redirect('/pre')

            else:
                return abort(403)

            df = PreProcess.mergeDF(file_path, path_csv)

            if result is None:
                view_path = "/AnnotationTbls/other/" + str(
                    user_id) + "_" + annotation_table
                UserData.add_file(annotation_table,
                                  annotation_table.split('.')[1], view_path,
                                  user_id, 1, 0)

        else:
            # load df
            annotation_table_path = UPLOAD_FOLDER.as_posix() + annotation_table
            df = PreProcess.mergeDF(file_path, Path(annotation_table_path))

        if df is None:
            flash("Couldn't merge dataset with annotation table")
            return redirect('/pre')

        y = PreProcess.getDF(file_path)
        if 'class' not in y.columns:
            flash("Wrong Format: class column not found.")
            return redirect('/pre')

        y = y['class']
        data = PreProcess.get_df_details(df, y)

        session[file_name] = data

        df = df.dropna(axis=0, subset=['Gene Symbol'])
        df = PreProcess.probe2Symbol(df, int(col_sel_method))

        merge_name = "merge_" + file_name
        merge_path = USER_PATH / str(user_id) / "tmp" / merge_name
        merge_path_str = merge_path.as_posix()
        PreProcess.saveDF(df, merge_path_str)

        # save data to the Database
        UserData.add_preprocess(user_id, file_name, file_path.as_posix(),
                                annotation_table, col_sel_method,
                                merge_path_str)
        pre_process_id = UserData.get_user_preprocess(user_id, file_name)['id']

        if len(df.columns) > 100:
            df_view = df.iloc[:, 0:100].head(15)
        else:
            df_view = df.head(15)

        return render_template("preprocess/step-2.html",
                               tables=[df_view.to_html(classes='data')],
                               details=data,
                               pre_process_id=pre_process_id,
                               file_name=merge_name)

    return redirect('/pre')