KashyapiNagaHarshitha commited on
Commit
324258f
·
verified ·
1 Parent(s): 2fbc541

Upload Setup.py

Browse files
Files changed (1) hide show
  1. Setup.py +208 -0
Setup.py ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+ import panel as pn
4
+ import os
5
+ import pandas as pd
6
+ import json
7
+ pn.extension()
8
+
9
+ # Global variables to store the input values
10
+ input_path = ""
11
+ set_path = ""
12
+ ls_samples = []
13
+ metadata_files = []
14
+ selected_metadata_files = []
15
+
16
+ # Define a callback to store values when the button is clicked
17
+ def store_values(event):
18
+ global input_path, set_path, ls_samples, metadata_files
19
+ input_path = file_input.value
20
+ set_path = set_name.value
21
+
22
+ # Update the global variables
23
+ global base_dir, input_data_dir, output_data_dir, output_images_dir, metadata_dir, metadata_images_dir
24
+ present_dir = os.path.dirname(os.path.realpath(__file__))
25
+ input_path = os.path.join(present_dir, input_path)
26
+ base_dir = input_path
27
+ project_name = set_path
28
+ step_suffix = 'qc_eda'
29
+ previous_step_suffix_long = ""
30
+
31
+ input_data_dir = os.path.join(base_dir, project_name + "_data")
32
+ output_data_dir = os.path.join(base_dir, project_name + "_" + step_suffix)
33
+ output_images_dir = os.path.join(output_data_dir, "images")
34
+ metadata_dir = os.path.join(base_dir, project_name + "_metadata")
35
+ metadata_images_dir = os.path.join(metadata_dir, "images")
36
+
37
+ # Create directories if they don't already exist
38
+ for d in [base_dir, input_data_dir, output_data_dir, output_images_dir, metadata_dir, metadata_images_dir]:
39
+ if not os.path.exists(d):
40
+ print(f"Creation of the {d} directory...")
41
+ os.makedirs(d)
42
+ else:
43
+ print(f"The {d} directory already exists!")
44
+
45
+ # os.chdir(input_data_dir) # Avoid changing the working directory
46
+
47
+ # Update JSON with directory settings
48
+ with open('stored_variables.json', 'r') as file:
49
+ data = json.load(file)
50
+ data.update({'base_dir': base_dir, 'set_path': set_path})
51
+ with open('stored_variables.json', 'w') as file:
52
+ json.dump(data, file, indent=4)
53
+
54
+ # Create a DataFrame with the directory paths
55
+ data = {
56
+ 'Directory': ['Base Directory', 'Input Data Directory', 'Output Data Directory', 'Output Images Directory', 'Metadata Directory', 'Metadata Images Directory'],
57
+ 'Path': [base_dir, input_data_dir, output_data_dir, output_images_dir, metadata_dir, metadata_images_dir]
58
+ }
59
+ df = pd.DataFrame(data)
60
+
61
+ # List CSV files in the input_data_dir
62
+ ls_samples = [sample for sample in os.listdir(input_data_dir) if sample.endswith(".csv")]
63
+ print(f"The following CSV files were detected:\n\n{ls_samples}\n\nin {input_data_dir} directory.")
64
+
65
+ # List CSV files in the metadata_dir
66
+ metadata_files = [file for file in os.listdir(metadata_dir) if file.endswith(".tif.csv")]
67
+ print(f"The following metadata CSV files were detected:\n\n{metadata_files}\n\nin {metadata_dir} directory.")
68
+
69
+ # Update the CheckBoxGroup options
70
+ checkbox_group.options = ls_samples
71
+ metadata_checkbox_group.options = metadata_files
72
+ # Assuming csv_files should be a DataFrame constructed from ls_samples
73
+ csv_files = pd.DataFrame({'CSV Files': ls_samples})
74
+ md_files = [file for file in os.listdir(metadata_dir) if file.endswith(".tif.csv")]
75
+ print(md_files)
76
+ metadata_files_df = pd.DataFrame({'Selected_Metadata_files' : [file for file in os.listdir(metadata_dir) if file.endswith(".tif.csv")]})
77
+ print(metadata_files_df)
78
+ # Update the output panes
79
+ output_pane_1.object = f"**File Path:** {input_path}\n\n**Set Name:** {set_path}"
80
+ output_pane_2.object = df.to_html(index=False)
81
+ output_pane_3.object = csv_files.to_html(index=False)
82
+ output_pane_4.object = metadata_files_df.to_html(index=False)
83
+
84
+ # Define a callback to save the selected CSV files when the button is clicked
85
+ def save_selected_files(event):
86
+ with open('stored_variables.json', 'r') as file:
87
+ data = json.load(file)
88
+ data['ls_samples'] = ls_samples
89
+ with open('stored_variables.json', 'w') as file:
90
+ json.dump(data, file, indent=4)
91
+ print("ls_samples updated in JSON file.")
92
+
93
+ # Define a callback to update the ls_samples list based on the selected options
94
+ def update_ls_samples(event):
95
+ global ls_samples
96
+ ls_samples = event.new
97
+
98
+ # Define a callback to update the metadata_files list based on the selected options
99
+ def update_metadata_files(event):
100
+ global metadata_files, selected_metadata_files
101
+ metadata_files = event.new
102
+ selected_metadata_files = event.new
103
+
104
+ # Define a callback to save the selected metadata files when the button is clicked
105
+ def save_selected_metadata_files(event):
106
+ with open('stored_variables.json', 'r') as file:
107
+ data = json.load(file)
108
+ data['selected_metadata_files'] = selected_metadata_files
109
+ with open('stored_variables.json', 'w') as file:
110
+ json.dump(data, file, indent=4)
111
+ print("selected_metadata_files updated in JSON file.")
112
+
113
+ # Define the widgets
114
+ file_input = pn.widgets.TextInput(
115
+ name="File Path",
116
+ placeholder="Enter the path to your directory"
117
+ )
118
+
119
+ set_name = pn.widgets.TextInput(
120
+ name="Set Name",
121
+ placeholder="Enter the Set"
122
+ )
123
+
124
+ store_button = pn.widgets.Button(name='Store Values')
125
+ store_button.on_click(store_values)
126
+
127
+ checkbox_group = pn.widgets.CheckBoxGroup(name='Select CSV Files', options=[], value=[])
128
+ checkbox_group.param.watch(update_ls_samples, 'value')
129
+
130
+ metadata_checkbox_group = pn.widgets.CheckBoxGroup(name='Select Metadata Files', options=[], value=[])
131
+ metadata_checkbox_group.param.watch(update_metadata_files, 'value')
132
+
133
+ save_button = pn.widgets.Button(name='Save Files')
134
+ save_button.on_click(save_selected_files)
135
+
136
+ save_metadata_button = pn.widgets.Button(name='Save Metadata Files')
137
+ save_metadata_button.on_click(save_selected_metadata_files)
138
+
139
+ output_pane_1 = pn.pane.Markdown("")
140
+ output_pane_2 = pn.pane.HTML("")
141
+ output_pane_3 = pn.pane.HTML("")
142
+ output_pane_4 = pn.pane.HTML("")
143
+
144
+ # Create the cards
145
+ card_1 = pn.Card(
146
+ pn.Column(
147
+ pn.pane.Markdown("### Input Form"),
148
+ file_input,
149
+ set_name,
150
+ store_button,
151
+ output_pane_1,
152
+ sizing_mode="stretch_width"
153
+ ),
154
+ title="Input Form",
155
+ sizing_mode="stretch_width"
156
+ )
157
+
158
+ card_2 = pn.Card(
159
+ pn.Column(
160
+ pn.pane.Markdown("### Directory Paths"),
161
+ output_pane_2,
162
+ sizing_mode="stretch_width"
163
+ ),
164
+ title="Directory Paths",
165
+ sizing_mode="stretch_width"
166
+ )
167
+
168
+ card_3 = pn.Card(
169
+ pn.Column(
170
+ pn.pane.Markdown("### CSV Files"),
171
+ output_pane_3,
172
+ pn.pane.Markdown("### Selection of CSV files for the further analysis"),
173
+ checkbox_group,
174
+ save_button,
175
+ sizing_mode="stretch_width"
176
+ ),
177
+ title="CSV Files",
178
+ sizing_mode="stretch_width"
179
+ )
180
+
181
+ card_4 = pn.Card(
182
+ pn.Column(
183
+ pn.pane.Markdown("### Metadata Files"),
184
+ output_pane_4,
185
+ pn.pane.Markdown("### Selection of Metadata Files"),
186
+ metadata_checkbox_group,
187
+ save_metadata_button,
188
+ sizing_mode="stretch_width"
189
+ ),
190
+ title="Metadata Files",
191
+ sizing_mode="stretch_width"
192
+ )
193
+
194
+ # Create the main column with the cards
195
+ main_column = pn.Column(card_1, card_2, card_3, card_4)
196
+
197
+ # Create the GoldenTemplate with the main column
198
+ app = pn.template.GoldenTemplate(
199
+ site="Cyc-IF",
200
+ title="Setup",
201
+ main=[main_column],
202
+ header_color="black",
203
+ )
204
+
205
+ app.servable()
206
+
207
+ if __name__ == "__main__":
208
+ pn.serve(app, port=5009)