Spaces:
Sleeping
Sleeping
File size: 7,439 Bytes
57b138a be109f4 6db04bb c386cc2 5875840 6db04bb 5875840 6db04bb 5875840 6db04bb 5875840 c386cc2 6db04bb 6afa339 5875840 979a092 5875840 979a092 5875840 979a092 5875840 979a092 5875840 06bef74 5875840 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
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()
|