Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,21 +3,46 @@ import pandas as pd
|
|
3 |
import scipy
|
4 |
from utils import *
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
|
9 |
-
"
|
10 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
}
|
12 |
-
|
13 |
-
|
14 |
spm_result.to_csv("spm_result.csv")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
dsm_result.to_csv("dsm_result.csv")
|
16 |
-
|
17 |
-
re=spm_result
|
18 |
-
if result_view=="DSM":
|
19 |
-
re=dsm_result
|
20 |
-
return "spm_result.csv","dsm_result.csv",re
|
21 |
|
22 |
default_values = {
|
23 |
"SPM Upload CSV file": None,
|
@@ -50,48 +75,83 @@ default_values = {
|
|
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 |
-
|
|
|
|
3 |
import scipy
|
4 |
from utils import *
|
5 |
|
6 |
+
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):
|
7 |
+
spm_params = {
|
8 |
+
"path_to_csv": SPM_path_to_csv.name,
|
9 |
+
"identifier_column": SPM_identifier_column,
|
10 |
+
"sequence_column": SPM_sequence_column,
|
11 |
+
"sortby": SPM_sortby,
|
12 |
+
"sliding_window_min": SPM_sliding_window_min,
|
13 |
+
"sliding_window_max": SPM_sliding_window_max,
|
14 |
+
"min_gap": SPM_min_gap,
|
15 |
+
"max_gap": SPM_max_gap,
|
16 |
+
"S_support_thresh": SPM_S_support_thresh,
|
17 |
+
"I_support_thresh": SPM_I_support_thresh,
|
18 |
+
"dataset_format": SPM_dataset_format
|
19 |
}
|
20 |
+
|
21 |
+
spm_result, occurrence_matrix = SPM(spm_params)
|
22 |
spm_result.to_csv("spm_result.csv")
|
23 |
+
return "spm_result.csv",spm_result
|
24 |
+
|
25 |
+
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):
|
26 |
+
dsm_params = {
|
27 |
+
"path_to_csv_left": DSM_path_to_csv_left.name,
|
28 |
+
"path_to_csv_right": DSM_path_to_csv_right.name,
|
29 |
+
"identifier_column": DSM_identifier_column,
|
30 |
+
"sequence_column": DSM_sequence_column,
|
31 |
+
"sortby": DSM_sortby,
|
32 |
+
"sliding_window_min": DSM_sliding_window_min,
|
33 |
+
"sliding_window_max": DSM_sliding_window_max,
|
34 |
+
"min_gap": DSM_min_gap,
|
35 |
+
"max_gap": DSM_max_gap,
|
36 |
+
"S_support_thresh": DSM_S_support_thresh,
|
37 |
+
"I_support_thresh": DSM_I_support_thresh,
|
38 |
+
"threshold_pvalue": DSM_threshold_pvalue,
|
39 |
+
"dataset_format": DSM_dataset_format,
|
40 |
+
"test_type": DSM_test_type
|
41 |
+
}
|
42 |
+
|
43 |
+
ptrn_left, ptrn_right, ptrn_both_left, ptrn_both_right, dsm_result = DSM(dsm_params)
|
44 |
dsm_result.to_csv("dsm_result.csv")
|
45 |
+
return "dsm_result.csv",dsm_result
|
|
|
|
|
|
|
|
|
46 |
|
47 |
default_values = {
|
48 |
"SPM Upload CSV file": None,
|
|
|
75 |
|
76 |
|
77 |
|
78 |
+
def demo():
|
79 |
+
with gr.Blocks(theme="base") as demo:
|
80 |
+
|
81 |
+
gr.Markdown(
|
82 |
+
"""<center><h2>SPM and DSM Implementation in Python</center></h2>
|
83 |
+
<h3>Sequential Pattern Mining (SPM) and Differential Sequential Mining (DSM)</h3>
|
84 |
+
"""
|
85 |
+
)
|
86 |
+
|
87 |
+
with gr.Tab("SPM"):
|
88 |
+
with gr.Row():
|
89 |
+
spm_file = gr.File(label="Upload CSV file")
|
90 |
+
with gr.Row():
|
91 |
+
identifier_column = gr.Textbox(label="Identifier Column", value="Identifier")
|
92 |
+
with gr.Row():
|
93 |
+
sequence_column = gr.Textbox(label="Sequence Column", value="Sequence")
|
94 |
+
with gr.Row():
|
95 |
+
sortby = gr.Dropdown(label="Sort By", choices=["S-Support", "I-Support"], value="S-Support")
|
96 |
+
with gr.Row():
|
97 |
+
sliding_window_min = gr.Number(label="Sliding Window Min", value=1)
|
98 |
+
with gr.Row():
|
99 |
+
sliding_window_max = gr.Number(label="Sliding Window Max", value=4)
|
100 |
+
with gr.Row():
|
101 |
+
min_gap = gr.Number(label="Min Gap", value=1)
|
102 |
+
with gr.Row():
|
103 |
+
max_gap = gr.Number(label="Max Gap", value=12)
|
104 |
+
with gr.Row():
|
105 |
+
S_support_thresh = gr.Number(label="S Support Threshold", value=0.4)
|
106 |
+
with gr.Row():
|
107 |
+
I_support_thresh = gr.Number(label="I Support Threshold", value=0)
|
108 |
+
with gr.Row():
|
109 |
+
dataset_format = gr.Number(label="Dataset Format", value=0)
|
110 |
+
with gr.Row():
|
111 |
+
spm_submit = gr.Button("Generate SPM Result...")
|
112 |
+
|
113 |
+
|
114 |
+
with gr.Tab("DSM"):
|
115 |
+
with gr.Row():
|
116 |
+
dsm_left_file = gr.File(label="Upload Left Dataset CSV file")
|
117 |
+
with gr.Row():
|
118 |
+
dsm_right_file = gr.File(label="Upload Right Dataset CSV file")
|
119 |
+
with gr.Row():
|
120 |
+
identifier_column_dsm = gr.Textbox(label="Identifier Column", value="Identifier")
|
121 |
+
with gr.Row():
|
122 |
+
sequence_column_dsm = gr.Textbox(label="Sequence Column", value="Sequence")
|
123 |
+
with gr.Row():
|
124 |
+
sortby_dsm = gr.Dropdown(label="Sort By", choices=["S-Support", "I-Support"], value="S-Support")
|
125 |
+
with gr.Row():
|
126 |
+
sliding_window_min_dsm = gr.Number(label="Sliding Window Min", value=1)
|
127 |
+
with gr.Row():
|
128 |
+
sliding_window_max_dsm = gr.Number(label="Sliding Window Max", value=1)
|
129 |
+
with gr.Row():
|
130 |
+
min_gap_dsm = gr.Number(label="Min Gap", value=1)
|
131 |
+
with gr.Row():
|
132 |
+
max_gap_dsm = gr.Number(label="Max Gap", value=12)
|
133 |
+
with gr.Row():
|
134 |
+
S_support_thresh_dsm = gr.Number(label="S Support Threshold", value=0.4)
|
135 |
+
with gr.Row():
|
136 |
+
I_support_thresh_dsm = gr.Number(label="I Support Threshold", value=0)
|
137 |
+
with gr.Row():
|
138 |
+
threshold_pvalue = gr.Number(label="Threshold P-value", value=0.1)
|
139 |
+
with gr.Row():
|
140 |
+
dataset_format_dsm = gr.Number(label="Dataset Format", value=0)
|
141 |
+
with gr.Row():
|
142 |
+
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")
|
143 |
+
with gr.Row():
|
144 |
+
dsm_submit = gr.Button("Generate DSM Result...")
|
145 |
+
dsm_result_display = gr.Textbox(label="DSM Result")
|
146 |
+
dsm_left_data_display = gr.Table(label="Left DSM Dataframe")
|
147 |
+
spm_submit.click(spm_fn,inputs=)
|
148 |
+
spm_submit.click(spm_fn, \
|
149 |
+
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], \
|
150 |
+
outputs=[gr.File(label="SPM result"), "dataframe"])
|
151 |
+
dsm_submit.click(dsm_fn, \
|
152 |
+
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], \
|
153 |
+
outputs=[gr.File(label="DSM result"), "dataframe"])
|
154 |
+
demo.queue().launch(debug=True)
|
155 |
|
156 |
+
if __name__ == "__main__":
|
157 |
+
demo()
|