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))
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')