Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pandas as pd | |
import scipy | |
from utils import * | |
def spm_fn(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): | |
spm_params = { | |
"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 | |
} | |
spm_result, occurrence_matrix = SPM(spm_params) | |
spm_result.to_csv("spm_result.csv") | |
return "spm_result.csv",spm_result | |
def dsm_fn(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): | |
dsm_params = { | |
"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 | |
} | |
ptrn_left, ptrn_right, ptrn_both_left, ptrn_both_right, dsm_result = DSM(dsm_params) | |
dsm_result.to_csv("dsm_result.csv") | |
return "dsm_result.csv",dsm_result | |
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" | |
} | |
def demo(): | |
with gr.Blocks(theme="base") as demo: | |
gr.Markdown( | |
"""<center><h2>SPM and DSM Implementation in Python</center></h2> | |
<h3>Sequential Pattern Mining (SPM) and Differential Sequential Mining (DSM)</h3> | |
""" | |
) | |
with gr.Tab("SPM"): | |
with gr.Row(): | |
spm_file = gr.File(label="Upload CSV file") | |
with gr.Row(): | |
identifier_column = gr.Textbox(label="Identifier Column", value="Identifier") | |
with gr.Row(): | |
sequence_column = gr.Textbox(label="Sequence Column", value="Sequence") | |
with gr.Row(): | |
sortby = gr.Dropdown(label="Sort By", choices=["S-Support", "I-Support"], value="S-Support") | |
with gr.Row(): | |
sliding_window_min = gr.Number(label="Sliding Window Min", value=1) | |
with gr.Row(): | |
sliding_window_max = gr.Number(label="Sliding Window Max", value=4) | |
with gr.Row(): | |
min_gap = gr.Number(label="Min Gap", value=1) | |
with gr.Row(): | |
max_gap = gr.Number(label="Max Gap", value=12) | |
with gr.Row(): | |
S_support_thresh = gr.Number(label="S Support Threshold", value=0.4) | |
with gr.Row(): | |
I_support_thresh = gr.Number(label="I Support Threshold", value=0) | |
with gr.Row(): | |
dataset_format = gr.Number(label="Dataset Format", value=0) | |
with gr.Row(): | |
spm_result=gr.File(label="SPM result") | |
with gr.Row(): | |
spm_dataframe=gr.Dataframe() | |
spm_submit = gr.Button("Generate SPM Result...") | |
with gr.Tab("DSM"): | |
with gr.Row(): | |
dsm_left_file = gr.File(label="Upload Left Dataset CSV file") | |
with gr.Row(): | |
dsm_right_file = gr.File(label="Upload Right Dataset CSV file") | |
with gr.Row(): | |
identifier_column_dsm = gr.Textbox(label="Identifier Column", value="Identifier") | |
with gr.Row(): | |
sequence_column_dsm = gr.Textbox(label="Sequence Column", value="Sequence") | |
with gr.Row(): | |
sortby_dsm = gr.Dropdown(label="Sort By", choices=["S-Support", "I-Support"], value="S-Support") | |
with gr.Row(): | |
sliding_window_min_dsm = gr.Number(label="Sliding Window Min", value=1) | |
with gr.Row(): | |
sliding_window_max_dsm = gr.Number(label="Sliding Window Max", value=1) | |
with gr.Row(): | |
min_gap_dsm = gr.Number(label="Min Gap", value=1) | |
with gr.Row(): | |
max_gap_dsm = gr.Number(label="Max Gap", value=12) | |
with gr.Row(): | |
S_support_thresh_dsm = gr.Number(label="S Support Threshold", value=0.4) | |
with gr.Row(): | |
I_support_thresh_dsm = gr.Number(label="I Support Threshold", value=0) | |
with gr.Row(): | |
threshold_pvalue = gr.Number(label="Threshold P-value", value=0.1) | |
with gr.Row(): | |
dataset_format_dsm = gr.Number(label="Dataset Format", value=0) | |
with gr.Row(): | |
test_type = gr.Dropdown(label="Test Type", choices=["poisson_means_test", "ttest_ind", "mannwhitneyu", "bws_test", "ranksums", "brunnermunzel", "mood", "ansari", "cramervonmises_2samp", "epps_singleton_2samp", "ks_2samp", "kstest"], value="ttest_ind") | |
with gr.Row(): | |
dsm_result=gr.File(label="DSM result") | |
with gr.Row(): | |
dsm_dataframe=gr.Dataframe() | |
dsm_submit = gr.Button("Generate DSM Result...") | |
spm_submit.click(spm_fn, \ | |
inputs=[spm_file, identifier_column, sequence_column, sortby, sliding_window_min, sliding_window_max, min_gap, max_gap, S_support_thresh, I_support_thresh, dataset_format], \ | |
outputs=[spm_result,spm_dataframe]) | |
dsm_submit.click(dsm_fn, \ | |
inputs=[dsm_left_file, dsm_right_file, 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, dataset_format_dsm, test_type], \ | |
outputs=[dsm_result,dsm_dataframe]) | |
demo.queue().launch(debug=True) | |
if __name__ == "__main__": | |
demo() | |