Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pandas as pd | |
import scipy | |
from utils import * | |
def demo(SPM_path_to_csv, SPM_identifier_column, SPM_sequence_column, SPM_sortby, SPM_sliding_window_min, SPM_sliding_window_max, SPM_min_gap, SPM_max_gap, SPM_S_support_thresh, SPM_I_support_thresh, SPM_dataset_format, DSM_path_to_csv_left, DSM_path_to_csv_right, DSM_identifier_column, DSM_sequence_column, DSM_sortby, DSM_sliding_window_min, DSM_sliding_window_max, DSM_min_gap, DSM_max_gap, DSM_S_support_thresh, DSM_I_support_thresh, DSM_threshold_pvalue, DSM_dataset_format, DSM_test_type,result_view): | |
# Your data processing logic here | |
result = { | |
"SPM": {"path_to_csv": SPM_path_to_csv.name, "identifier_column": SPM_identifier_column, "sequence_column": SPM_sequence_column, "sortby": SPM_sortby, "sliding_window_min": SPM_sliding_window_min, "sliding_window_max": SPM_sliding_window_max, "min_gap": SPM_min_gap, "max_gap": SPM_max_gap, "S_support_thresh": SPM_S_support_thresh, "I_support_thresh": SPM_I_support_thresh, "dataset_format": SPM_dataset_format}, | |
"DSM": {"path_to_csv_left": DSM_path_to_csv_left.name, "path_to_csv_right": DSM_path_to_csv_right.name, "identifier_column": DSM_identifier_column, "sequence_column": DSM_sequence_column, "sortby": DSM_sortby, "sliding_window_min": DSM_sliding_window_min, "sliding_window_max": DSM_sliding_window_max, "min_gap": DSM_min_gap, "max_gap": DSM_max_gap, "S_support_thresh": DSM_S_support_thresh, "I_support_thresh": DSM_I_support_thresh, "threshold_pvalue": DSM_threshold_pvalue, "dataset_format": DSM_dataset_format, "test_type": DSM_test_type} | |
} | |
spm_result, occurrence_matrix = SPM(result["SPM"]) | |
ptrn_left, ptrn_right, ptrn_both_left, ptrn_both_right, dsm_result = DSM(result["DSM"]) | |
spm_result.to_csv("spm_result.csv") | |
dsm_result.to_csv("dsm_result.csv") | |
if result_view=="SPM": | |
re=spm_result | |
if result_view=="DSM": | |
re=dsm_result | |
return "spm_result.csv","dsm_result.csv",re | |
default_values = { | |
"SPM Upload CSV file": None, | |
"SPM_identifier_column": "Identifier", | |
"SPM_sequence_column": "Sequence", | |
"SPM_sortby": "S-Support", | |
"SPM_sliding_window_min": 1, | |
"SPM_sliding_window_max": 4, | |
"SPM_min_gap": 1, | |
"SPM_max_gap": 12, | |
"SPM_S_support_thresh": 0.4, | |
"SPM_I_support_thresh": 0, | |
"SPM_dataset_format": 0, | |
"DSM_path_to_csv_left": None, | |
"DSM_path_to_csv_right": None, | |
"DSM_identifier_column": "Identifier", | |
"DSM_sequence_column": "Sequence", | |
"DSM_sortby": "S-Support", | |
"DSM_sliding_window_min": 1, | |
"DSM_sliding_window_max": 1, | |
"DSM_min_gap": 1, | |
"DSM_max_gap": 12, | |
"DSM_S_support_thresh": 0.4, | |
"DSM_I_support_thresh": 0, | |
"DSM_threshold_pvalue": 0.1, | |
"DSM_dataset_format": 0, | |
"DSM_test_type": "ttest_ind", | |
"Select method for which you want to view result": "DSM" | |
} | |
interface = gr.Interface( | |
fn=process_data, | |
inputs=[ | |
gr.File(label="SPM Upload CSV file"), | |
gr.Textbox(label="SPM identifier_column"), | |
gr.Textbox(label="SPM sequence_column"), | |
gr.Dropdown(label="SPM sortby", choices=["S-Support", "I-Support"]), | |
gr.Number(label="SPM sliding_window_min"), | |
gr.Number(label="SPM sliding_window_max"), | |
gr.Number(label="SPM min_gap"), | |
gr.Number(label="SPM max_gap"), | |
gr.Number(label="SPM S_support_thresh"), | |
gr.Number(label="SPM I_support_thresh"), | |
gr.Number(label="SPM dataset_format"), | |
gr.File(label="DSM Upload CSV file for left Dataset"), | |
gr.File(label="DSM Upload CSV file for right Dataset"), | |
gr.Textbox(label="DSM identifier_column"), | |
gr.Textbox(label="DSM sequence_column"), | |
gr.Dropdown(label="DSM sortby", choices=["S-Support", "I-Support"]), | |
gr.Number(label="DSM sliding_window_min"), | |
gr.Number(label="DSM sliding_window_max"), | |
gr.Number(label="DSM min_gap"), | |
gr.Number(label="DSM max_gap"), | |
gr.Number(label="DSM S_support_thresh"), | |
gr.Number(label="DSM I_support_thresh"), | |
gr.Number(label="DSM threshold_pvalue"), | |
gr.Number(label="DSM dataset_format"), | |
gr.Dropdown(label="DSM test_type", choices=["poisson_means_test", "ttest_ind", "mannwhitneyu", "bws_test", "ranksums", "brunnermunzel", "mood", "ansari", "cramervonmises_2samp", "epps_singleton_2samp", "ks_2samp", "kstest"]), | |
gr.Dropdown(label="Select method for which you want to view result", choices=["SPM", "DSM"]) | |
], | |
outputs=[gr.File(label="SPM result"),gr.File(label="DSM result"),"dataframe"], | |
title="SPM And DSM Implementation in Python", | |
defaults=default_values | |
) | |
interface.launch(debug=True) | |