diff --git a/src/ccompass/CCMPS.py b/src/ccompass/CCMPS.py index 7e7d0cd..9974061 100644 --- a/src/ccompass/CCMPS.py +++ b/src/ccompass/CCMPS.py @@ -20,70 +20,10 @@ os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" -def main(): - """The entry point for the C-COMPASS application.""" - fract_paths, fract_tables, fract_data, fract_pos = action.resetinput() - fract_data, fract_std, fract_intermediate, fract_info, fract_conditions = ( - action.reset_fract() - ) - - tp_paths, tp_tables, tp_data, tp_pos = action.resetinput() - - fract_indata, fract_identifiers = action.reset_infract() - tp_indata, tp_identifiers = action.reset_intp() - tp_data, tp_intermediate, tp_info, tp_conditions, tp_icorr = ( - action.reset_tp() - ) - - fract_preparams = PPMS.fract_default() - tp_preparams = PPMS.tp_default() - - marker_sets = marker_conv = fract_full = fract_full_up = fract_marker = ( - fract_marker_vis - ) = fract_marker_up = fract_mixed_up = fract_test = svm_marker = ( - svm_test - ) = svm_metrics = learning_xyz = results = comparison = {} - marker_params = {"how": "exclude", "what": "unite"} - marker_list = pd.DataFrame - NN_params = PPMS.NN_default() - - status = action.default_status() - - # status = {'fractionation_data' : False, - # 'tp_data' : False, - # 'lipidome_data' : False, - # 'lipidome_total' : False, - # 'marker_file' : False, - # 'marker_matched' : False, - # 'training' : False, - # 'proteome_prediction' : False, - # 'lipidome_prediction' : False, - # 'comparison_global' : False, - # 'comparison_class' : False} - - # tp_preparams = {} - # marker_sets = {} - # marker_conv = {} - # fract_full = {} - # fract_full_up = {} - # fract_marker = {} - # fract_marker_vis = {} - # fract_marker_up = {} - # fract_mixed_up = {} - # fract_test = {} - # svm_marker = {} - # svm_test = {} - # svm_metrics = {} - # learning_xyz = {} - # results = {} - # comparison = {} - - sg.theme("Dark Blue 3") - menu_def = [ - ["Session", ["Save...", "Open...", "New", "Exit"]], - ["Help", ["About...", "Open Website", "Manual"]], - ] +def get_data_import_frame(fract_paths, tp_paths) -> sg.Frame: + """Create the "Data Import" frame.""" + # The fractionation tab layout_fractionation = [ [ sg.Button( @@ -423,606 +363,690 @@ def main(): # ], size = (140,70))], # ] - layout_CCMPS = [ - [sg.Menu(menu_def, tearoff=False)], - [ - sg.Frame( - layout=[ + return sg.Frame( + layout=[ + [ + sg.TabGroup( [ - sg.TabGroup( - [ - [ - sg.Tab( - " - Fractionation - ", - layout_fractionation, - ), - sg.Tab( - " - TotalProteomes - ", - layout_TP, - key="-total_tab-", - ), - ] - ], - tab_location="topleft", - tab_background_color="grey", - size=(600, 450), - ) - ] - ], - title="Data Import", - size=(620, 480), - ), - sg.Frame( - layout=[ - [ - sg.Button( - "Parameters...", - size=(15, 1), - key="-classification_parameters-", - disabled=False, - enable_events=True, - button_color="black", - ), - sg.Button( - "Train C-COMPASS!", - size=(25, 1), - key="-classification_MOP-", - disabled=True, - enable_events=True, - button_color="dark blue", - ), - sg.Button( - "ML Validation", - size=(15, 1), - key="-classification_validation-", - disabled=True, - enable_events=True, - visible=False, - ), - sg.Button( - "Reset", - size=(10, 1), - key="-classification_reset-", - disabled=True, - enable_events=True, - button_color="dark red", - ), + [ + sg.Tab( + " - Fractionation - ", + layout_fractionation, + ), + sg.Tab( + " - TotalProteomes - ", + layout_TP, + key="-total_tab-", + ), + ] ], - [sg.HSep()], + tab_location="topleft", + tab_background_color="grey", + size=(600, 450), + ) + ] + ], + title="Data Import", + size=(620, 480), + ) + + +def get_spatial_prediction_frame() -> sg.Frame: + """Create the "Spatial Prediction" frame.""" + return sg.Frame( + layout=[ + [ + sg.Button( + "Parameters...", + size=(15, 1), + key="-classification_parameters-", + disabled=False, + enable_events=True, + button_color="black", + ), + sg.Button( + "Train C-COMPASS!", + size=(25, 1), + key="-classification_MOP-", + disabled=True, + enable_events=True, + button_color="dark blue", + ), + sg.Button( + "ML Validation", + size=(15, 1), + key="-classification_validation-", + disabled=True, + enable_events=True, + visible=False, + ), + sg.Button( + "Reset", + size=(10, 1), + key="-classification_reset-", + disabled=True, + enable_events=True, + button_color="dark red", + ), + ], + [sg.HSep()], + [ + sg.Column( [ - sg.Column( - [ - [ - sg.Text("Prot. Fractionation:"), - sg.Push(), - sg.Text( - "none", - key="-status_fract-", - text_color="black", - ), - ], # or: 'ready' - [ - sg.Text("Total Proteome:"), - sg.Push(), - sg.Text( - "none", - key="-status_tp-", - text_color="black", - ), - ], # or: 'ready' - [ - sg.Text("Marker Proteins:"), - sg.Push(), - sg.Text( - "none", - key="-status_marker-", - text_color="black", - ), - ], # or: 'ready' + [ + sg.Text("Prot. Fractionation:"), + sg.Push(), + sg.Text( + "none", + key="-status_fract-", + text_color="black", + ), + ], # or: 'ready' + [ + sg.Text("Total Proteome:"), + sg.Push(), + sg.Text( + "none", + key="-status_tp-", + text_color="black", + ), + ], # or: 'ready' + [ + sg.Text("Marker Proteins:"), + sg.Push(), + sg.Text( + "none", + key="-status_marker-", + text_color="black", + ), + ], # or: 'ready' + [ + sg.Text("Lipidome Fractionation:"), + sg.Push(), + sg.Text( + "none", + key="-status_fract_lipid-", + text_color="black", + ), + ], + [ + sg.Text("Total Lipidome:"), + sg.Push(), + sg.Text( + "none", + key="-status_total_lipid-", + text_color="black", + ), + ], + ], + size=(240, 180), + ), + sg.Frame( + layout=[ + [ + sg.Text("Data Type:"), + sg.Push(), + sg.Combo( [ - sg.Text("Lipidome Fractionation:"), - sg.Push(), - sg.Text( - "none", - key="-status_fract_lipid-", - text_color="black", - ), + "Lipidomics", ], - [ - sg.Text("Total Lipidome:"), - sg.Push(), - sg.Text( - "none", - key="-status_total_lipid-", - text_color="black", - ), + default_value="Lipidomics", + size=(15, 1), + readonly=True, + ), + ], + [sg.HSep()], + [sg.VPush()], + [ + sg.Button( + "Import/Edit Fractionation...", + size=(39, 1), + ) + ], + [ + sg.Button( + "Import/Edit Total Lysate...", + size=(39, 1), + ) + ], + ], + title="Additional Import", + size=(340, 130), + vertical_alignment="top", + visible=False, + ), + ], + # [sg.Frame(layout = [ + # [sg.Button('calculate full static Statistics', size = (25,1), key = '-classification_statistics-', disabled = True, enable_events = True, button_color = 'dark blue'), + # sg.Text('(TP required!)', font = ('Helvetica', 8)), + # sg.Button('rouch statistics', size =(14,1), key = '-classification_statistics_rough-', disabled = False, enable_events = True, button_color = 'grey'), + # sg.Text('(w/o TP but biased!)', font = ('Helvetica', 8))], + # [sg.Text('missing', key = '-status_statistics-')], + # [sg.HSep()], + # [sg.Button('calculate conditional Changes', size = (25,1), key = '-classification_comparison-', disabled = False, enable_events = True, button_color = 'dark blue'), + # sg.Text('(TP required!)', font = ('Helvetica', 8)), + # sg.Button('rough Comparison', size = (14,1), key = '-classification_comparison_rough-', disabled = False, enable_events = True, button_color = 'grey'), + # sg.Text('(w/o TP but biased!)', font = ('Helvetica', 8))], + # [sg.Text('missing', key = '-status_comparison-')], + # ], title = 'Statistics', size = (590,150))], + [sg.VPush()], + [ + sg.Frame( + layout=[ + [ + sg.Frame( + layout=[ + [ + sg.Button( + "Predict Proteome!", + size=(32, 1), + key="-statistic_predict-", + disabled=True, + enable_events=True, + button_color="dark blue", + ) + ], + [sg.HSep()], + [ + sg.Button( + "Export Prediction", + size=(15, 1), + key="-statistic_export-", + disabled=True, + enable_events=True, + button_color="black", + ), + sg.Button( + "Import Prediction", + size=(15, 1), + key="-statistic_import-", + disabled=False, + enable_events=True, + button_color="black", + ), + ], + [sg.HSep()], + [sg.VPush()], + [ + sg.Button( + "Report...", + size=(15, 1), + key="-statistic_report-", + disabled=True, + enable_events=True, + button_color="grey", + ), + sg.Button( + "Reset", + size=(15, 1), + key="-statistic_reset-", + disabled=True, + enable_events=True, + button_color="dark red", + ), + ], + [ + sg.Button( + "Static Heatmap", + size=(15, 1), + key="-statistic_heatmap-", + disabled=True, + enable_events=True, + ), + sg.Button( + "Distribution Plots", + size=(15, 1), + key="-statistic_distribution-", + disabled=True, + enable_events=True, + ), + ], ], - ], - size=(240, 180), - ), - sg.Frame( - layout=[ - [ - sg.Text("Data Type:"), - sg.Push(), - sg.Combo( - [ - "Lipidomics", - ], - default_value="Lipidomics", - size=(15, 1), - readonly=True, - ), + title="Proteome", + size=(280, 195), + ), + sg.Frame( + layout=[ + [ + sg.Button( + "Predict Lipidome!", + size=(32, 1), + key="-lipidome_predict-", + disabled=True, + enable_events=True, + button_color="dark blue", + ) + ], + [sg.VPush()], + [sg.HSep()], + [ + sg.Button( + "Report...", + size=(15, 1), + key="-lipidome_report-", + disabled=True, + enable_events=True, + button_color="grey", + ), + sg.Button( + "Reset", + size=(15, 1), + key="-lipidome_reset-", + disabled=True, + enable_events=True, + button_color="dark red", + ), + ], + [ + sg.Button( + "Heatmap", + size=(15, 1), + key="-lipidome_heatmap-", + disabled=True, + enable_events=True, + ), + sg.Button( + "Reorganization Plot", + size=(15, 1), + key="-lipidome_reorganization-", + disabled=True, + enable_events=True, + ), + ], + [ + sg.Button( + "Density Plot", + size=(15, 1), + key="-lipidome_density-", + disabled=True, + enable_events=True, + ), + sg.Button( + "Class Compositions", + size=(15, 1), + key="-lipidome_composition-", + disabled=True, + enable_events=True, + ), + ], ], - [sg.HSep()], - [sg.VPush()], - [ - sg.Button( - "Import/Edit Fractionation...", - size=(39, 1), - ) + title="Lipidome", + size=(290, 195), + visible=False, + ), + ], + ], + title="Static Statistics", + size=(580, 230), + ) + ], + ], + title="Spatial Prediction", + size=(600, 480), + ) + + +def get_marker_selection_frame() -> sg.Frame: + """Create the "Marker Selection" frame.""" + return sg.Frame( + layout=[ + [ + sg.Frame( + layout=[ + [ + sg.Listbox( + values=[], + size=(40, 4), + key="-marker_list-", + disabled=False, + enable_events=True, + horizontal_scroll=True, + ) + ], + [ + sg.Column( + layout=[ + [ + sg.Button( + "Add...", + size=(7, 1), + key="-marker_add-", + disabled=False, + enable_events=True, + ) + ], + [ + sg.Button( + "Remove", + size=(7, 1), + key="-marker_remove-", + disabled=True, + enable_events=True, + button_color="dark red", + ) + ], ], - [ - sg.Button( - "Import/Edit Total Lysate...", - size=(39, 1), - ) + size=(72, 70), + ), + sg.Column( + layout=[ + [ + sg.Text("key column:\t"), + sg.Combo( + [], + size=(10, 1), + key="-marker_key-", + enable_events=True, + readonly=True, + ), + ], + [ + sg.Text("class column:\t"), + sg.Combo( + [], + size=(10, 1), + key="-marker_class-", + enable_events=True, + readonly=True, + ), + ], ], - ], - title="Additional Import", - size=(340, 130), - vertical_alignment="top", - visible=False, - ), + size=(220, 70), + ), + ], ], - # [sg.Frame(layout = [ - # [sg.Button('calculate full static Statistics', size = (25,1), key = '-classification_statistics-', disabled = True, enable_events = True, button_color = 'dark blue'), - # sg.Text('(TP required!)', font = ('Helvetica', 8)), - # sg.Button('rouch statistics', size =(14,1), key = '-classification_statistics_rough-', disabled = False, enable_events = True, button_color = 'grey'), - # sg.Text('(w/o TP but biased!)', font = ('Helvetica', 8))], - # [sg.Text('missing', key = '-status_statistics-')], - # [sg.HSep()], - # [sg.Button('calculate conditional Changes', size = (25,1), key = '-classification_comparison-', disabled = False, enable_events = True, button_color = 'dark blue'), - # sg.Text('(TP required!)', font = ('Helvetica', 8)), - # sg.Button('rough Comparison', size = (14,1), key = '-classification_comparison_rough-', disabled = False, enable_events = True, button_color = 'grey'), - # sg.Text('(w/o TP but biased!)', font = ('Helvetica', 8))], - # [sg.Text('missing', key = '-status_comparison-')], - # ], title = 'Statistics', size = (590,150))], - [sg.VPush()], - [ - sg.Frame( - layout=[ - [ - sg.Frame( - layout=[ - [ - sg.Button( - "Predict Proteome!", - size=(32, 1), - key="-statistic_predict-", - disabled=True, - enable_events=True, - button_color="dark blue", - ) - ], - [sg.HSep()], - [ - sg.Button( - "Export Prediction", - size=(15, 1), - key="-statistic_export-", - disabled=True, - enable_events=True, - button_color="black", - ), - sg.Button( - "Import Prediction", - size=(15, 1), - key="-statistic_import-", - disabled=False, - enable_events=True, - button_color="black", - ), - ], - [sg.HSep()], - [sg.VPush()], - [ - sg.Button( - "Report...", - size=(15, 1), - key="-statistic_report-", - disabled=True, - enable_events=True, - button_color="grey", - ), - sg.Button( - "Reset", - size=(15, 1), - key="-statistic_reset-", - disabled=True, - enable_events=True, - button_color="dark red", - ), - ], - [ - sg.Button( - "Static Heatmap", - size=(15, 1), - key="-statistic_heatmap-", - disabled=True, - enable_events=True, - ), - sg.Button( - "Distribution Plots", - size=(15, 1), - key="-statistic_distribution-", - disabled=True, - enable_events=True, - ), - ], - ], - title="Proteome", - size=(280, 195), - ), - sg.Frame( - layout=[ - [ - sg.Button( - "Predict Lipidome!", - size=(32, 1), - key="-lipidome_predict-", - disabled=True, - enable_events=True, - button_color="dark blue", - ) - ], - [sg.VPush()], - [sg.HSep()], - [ - sg.Button( - "Report...", - size=(15, 1), - key="-lipidome_report-", - disabled=True, - enable_events=True, - button_color="grey", - ), - sg.Button( - "Reset", - size=(15, 1), - key="-lipidome_reset-", - disabled=True, - enable_events=True, - button_color="dark red", - ), - ], - [ - sg.Button( - "Heatmap", - size=(15, 1), - key="-lipidome_heatmap-", - disabled=True, - enable_events=True, - ), - sg.Button( - "Reorganization Plot", - size=(15, 1), - key="-lipidome_reorganization-", - disabled=True, - enable_events=True, - ), - ], - [ - sg.Button( - "Density Plot", - size=(15, 1), - key="-lipidome_density-", - disabled=True, - enable_events=True, - ), - sg.Button( - "Class Compositions", - size=(15, 1), - key="-lipidome_composition-", - disabled=True, - enable_events=True, - ), - ], - ], - title="Lipidome", - size=(290, 195), - visible=False, - ), - ], - ], - title="Static Statistics", - size=(580, 230), - ) + title="Import", + size=(320, 190), + ), + sg.Column( + layout=[ + [ + sg.Button( + "Load preset-list", + size=(32, 1), + key="-marker_preset-", + disabled=False, + enable_events=True, + button_color="dark blue", + visible=False, + ) + ], + [sg.HSep()], + [ + sg.Text("Fract. Key:\t"), + sg.Combo( + ["[IDENTIFIER]"], + key="-marker_fractkey-", + size=(18, 1), + readonly=True, + ), + ], + [sg.HSep()], + [ + sg.Button( + "Parameters...", + size=(15, 1), + key="-marker_parameters-", + disabled=False, + enable_events=True, + button_color="black", + ), + sg.Button( + "Manage...", + size=(15, 1), + key="-marker_manage-", + disabled=True, + enable_events=True, + button_color="black", + ), + ], + [ + sg.Button( + "Correlations...", + size=(15, 1), + key="-marker_test-", + disabled=True, + enable_events=True, + button_color="grey", + ), + sg.Button( + "Profiles...", + size=(15, 1), + key="-marker_profiles-", + disabled=True, + enable_events=True, + button_color="grey", + ), + ], + [sg.HSep()], + [ + sg.Button( + "Reset", + size=(15, 1), + key="-marker_reset-", + disabled=True, + enable_events=True, + button_color="dark red", + ), + sg.Button( + "Match!", + size=(15, 1), + key="-marker_accept-", + disabled=True, + enable_events=True, + button_color="dark green", + ), + ], ], - ], - title="Spatial Prediction", - size=(600, 480), - ), + size=(280, 180), + ), + ], ], - [ - sg.Frame( - layout=[ - [ - sg.Frame( - layout=[ - [ - sg.Listbox( - values=[], - size=(40, 4), - key="-marker_list-", - disabled=False, - enable_events=True, - horizontal_scroll=True, - ) - ], - [ - sg.Column( - layout=[ - [ - sg.Button( - "Add...", - size=(7, 1), - key="-marker_add-", - disabled=False, - enable_events=True, - ) - ], - [ - sg.Button( - "Remove", - size=(7, 1), - key="-marker_remove-", - disabled=True, - enable_events=True, - button_color="dark red", - ) - ], - ], - size=(72, 70), - ), - sg.Column( - layout=[ - [ - sg.Text("key column:\t"), - sg.Combo( - [], - size=(10, 1), - key="-marker_key-", - enable_events=True, - readonly=True, - ), - ], - [ - sg.Text("class column:\t"), - sg.Combo( - [], - size=(10, 1), - key="-marker_class-", - enable_events=True, - readonly=True, - ), - ], - ], - size=(220, 70), - ), - ], - ], - title="Import", - size=(320, 190), - ), - sg.Column( - layout=[ - [ - sg.Button( - "Load preset-list", - size=(32, 1), - key="-marker_preset-", - disabled=False, - enable_events=True, - button_color="dark blue", - visible=False, - ) - ], - [sg.HSep()], - [ - sg.Text("Fract. Key:\t"), - sg.Combo( - ["[IDENTIFIER]"], - key="-marker_fractkey-", - size=(18, 1), - readonly=True, - ), - ], - [sg.HSep()], - [ - sg.Button( - "Parameters...", - size=(15, 1), - key="-marker_parameters-", - disabled=False, - enable_events=True, - button_color="black", - ), - sg.Button( - "Manage...", - size=(15, 1), - key="-marker_manage-", - disabled=True, - enable_events=True, - button_color="black", - ), - ], - [ - sg.Button( - "Correlations...", - size=(15, 1), - key="-marker_test-", - disabled=True, - enable_events=True, - button_color="grey", - ), - sg.Button( - "Profiles...", - size=(15, 1), - key="-marker_profiles-", - disabled=True, - enable_events=True, - button_color="grey", - ), - ], - [sg.HSep()], - [ - sg.Button( - "Reset", - size=(15, 1), - key="-marker_reset-", - disabled=True, - enable_events=True, - button_color="dark red", - ), - sg.Button( - "Match!", - size=(15, 1), - key="-marker_accept-", - disabled=True, - enable_events=True, - button_color="dark green", - ), - ], - ], - size=(280, 180), - ), + title="Marker Selection", + size=(620, 220), + ) + + +def get_conditional_comparison_frame() -> sg.Frame: + """Create the "Conditional Comparison" frame.""" + return sg.Frame( + layout=[ + [ + sg.Frame( + layout=[ + # [sg.Text('Statistics required!')], + [ + sg.Button( + "Calculate global Changes!", + size=(32, 1), + key="-global_run-", + disabled=True, + enable_events=True, + button_color="dark blue", + ) + ], + [sg.HSep()], + [ + sg.Button( + "Change Heatmap", + size=(15, 1), + key="-global_heatmap-", + disabled=True, + enable_events=True, + ), + sg.Button( + "Distance Plot", + size=(15, 1), + key="-global_distance-", + disabled=True, + enable_events=True, + ), + ], + [ + sg.Button( + "Report...", + size=(15, 1), + key="-global_report-", + disabled=True, + enable_events=True, + button_color="grey", + ), + sg.Button( + "Reset", + size=(15, 1), + key="-global_reset-", + disabled=True, + enable_events=True, + button_color="dark red", + ), + ], ], - ], - title="Marker Selection", - size=(620, 220), - ), - sg.Frame( - layout=[ - [ - sg.Frame( - layout=[ - # [sg.Text('Statistics required!')], - [ - sg.Button( - "Calculate global Changes!", - size=(32, 1), - key="-global_run-", - disabled=True, - enable_events=True, - button_color="dark blue", - ) - ], - [sg.HSep()], - [ - sg.Button( - "Change Heatmap", - size=(15, 1), - key="-global_heatmap-", - disabled=True, - enable_events=True, - ), - sg.Button( - "Distance Plot", - size=(15, 1), - key="-global_distance-", - disabled=True, - enable_events=True, - ), - ], - [ - sg.Button( - "Report...", - size=(15, 1), - key="-global_report-", - disabled=True, - enable_events=True, - button_color="grey", - ), - sg.Button( - "Reset", - size=(15, 1), - key="-global_reset-", - disabled=True, - enable_events=True, - button_color="dark red", - ), - ], - ], - title="Global Changes", - size=(290, 190), - ), - sg.Frame( - layout=[ - [ - sg.Button( - "Calculate class-centric Changes!", - size=(32, 1), - key="-class_run-", - disabled=True, - enable_events=True, - button_color="dark blue", - ) - ], - [sg.HSep()], - [ - sg.Button( - "Class Heatmaps", - size=(15, 1), - key="-class_heatmap-", - disabled=True, - enable_events=True, - visible=False, - ), - sg.Button( - "Class Reorg. Plots", - size=(15, 1), - key="-class_reorganization-", - disabled=True, - enable_events=True, - visible=False, - ), - ], - [ - sg.Button( - "Report...", - size=(15, 1), - key="-class_report-", - disabled=True, - enable_events=True, - button_color="grey", - ), - sg.Button( - "Reset", - size=(15, 1), - key="-class_reset-", - disabled=True, - enable_events=True, - button_color="dark red", - ), - ], - ], - title="Class-centric Changes", - size=(290, 190), - ), - ] - ], - title="Conditional Comparison", - size=(600, 220), - ), + title="Global Changes", + size=(290, 190), + ), + sg.Frame( + layout=[ + [ + sg.Button( + "Calculate class-centric Changes!", + size=(32, 1), + key="-class_run-", + disabled=True, + enable_events=True, + button_color="dark blue", + ) + ], + [sg.HSep()], + [ + sg.Button( + "Class Heatmaps", + size=(15, 1), + key="-class_heatmap-", + disabled=True, + enable_events=True, + visible=False, + ), + sg.Button( + "Class Reorg. Plots", + size=(15, 1), + key="-class_reorganization-", + disabled=True, + enable_events=True, + visible=False, + ), + ], + [ + sg.Button( + "Report...", + size=(15, 1), + key="-class_report-", + disabled=True, + enable_events=True, + button_color="grey", + ), + sg.Button( + "Reset", + size=(15, 1), + key="-class_reset-", + disabled=True, + enable_events=True, + button_color="dark red", + ), + ], + ], + title="Class-centric Changes", + size=(290, 190), + ), + ] + ], + title="Conditional Comparison", + size=(600, 220), + ) + + +def main(): + """The entry point for the C-COMPASS application.""" + fract_paths, fract_tables, fract_data, fract_pos = action.resetinput() + fract_data, fract_std, fract_intermediate, fract_info, fract_conditions = ( + action.reset_fract() + ) + + tp_paths, tp_tables, tp_data, tp_pos = action.resetinput() + + fract_indata, fract_identifiers = action.reset_infract() + tp_indata, tp_identifiers = action.reset_intp() + tp_data, tp_intermediate, tp_info, tp_conditions, tp_icorr = ( + action.reset_tp() + ) + + fract_preparams = PPMS.fract_default() + tp_preparams = PPMS.tp_default() + + marker_sets = marker_conv = fract_full = fract_full_up = fract_marker = ( + fract_marker_vis + ) = fract_marker_up = fract_mixed_up = fract_test = svm_marker = ( + svm_test + ) = svm_metrics = learning_xyz = results = comparison = {} + marker_params = {"how": "exclude", "what": "unite"} + marker_list = pd.DataFrame + NN_params = PPMS.NN_default() + + status = action.default_status() + + # status = {'fractionation_data' : False, + # 'tp_data' : False, + # 'lipidome_data' : False, + # 'lipidome_total' : False, + # 'marker_file' : False, + # 'marker_matched' : False, + # 'training' : False, + # 'proteome_prediction' : False, + # 'lipidome_prediction' : False, + # 'comparison_global' : False, + # 'comparison_class' : False} + + # tp_preparams = {} + # marker_sets = {} + # marker_conv = {} + # fract_full = {} + # fract_full_up = {} + # fract_marker = {} + # fract_marker_vis = {} + # fract_marker_up = {} + # fract_mixed_up = {} + # fract_test = {} + # svm_marker = {} + # svm_test = {} + # svm_metrics = {} + # learning_xyz = {} + # results = {} + # comparison = {} + + sg.theme("Dark Blue 3") + + # The main menu + menu_def = [ + ["Session", ["Save...", "Open...", "New", "Exit"]], + ["Help", ["About...", "Open Website", "Manual"]], + ] + + layout_CCMPS = [ + [sg.Menu(menu_def, tearoff=False)], + [ + get_data_import_frame(fract_paths=fract_paths, tp_paths=tp_paths), + get_spatial_prediction_frame(), + ], + [ + get_marker_selection_frame(), + get_conditional_comparison_frame(), ], ] - window_CCMPS = sg.Window("CellCOMPASS", layout_CCMPS, size=(1260, 720)) - # ----------------------------------------------------------------------------------------------------------------------------- + main_window = sg.Window("CellCOMPASS", layout_CCMPS, size=(1260, 720)) + # The event loop while True: - event_CCMPS, values_CCMPS = window_CCMPS.read() + event, values_CCMPS = main_window.read() # action.refresh_window(window_CCMPS, status) # if status['fractionation_data']: @@ -1030,69 +1054,69 @@ def main(): # else: # window_CCMPS['-status_fract-'].Update('missing') - if event_CCMPS == "-fractionation_add-": + if event == "-fractionation_add-": action.fract_add( values_CCMPS, - window_CCMPS, + main_window, fract_paths, fract_tables, fract_indata, fract_pos, fract_identifiers, ) - if event_CCMPS == "-fractionation_remove-": + elif event == "-fractionation_remove-": if values_CCMPS["-fractionation_path-"]: action.fract_rem( values_CCMPS, - window_CCMPS, + main_window, fract_paths, fract_tables, fract_data, ) - if event_CCMPS == "-fractionation_path-": + elif event == "-fractionation_path-": action.fract_refreshtable( - window_CCMPS, + main_window, fract_tables[values_CCMPS["-fractionation_path-"]], ) - if event_CCMPS == "-fractionation_edit_remove-": + elif event == "-fractionation_edit_remove-": if values_CCMPS["-fractionation_table-"]: - action.fract_defrem(values_CCMPS, window_CCMPS, fract_tables) + action.fract_defrem(values_CCMPS, main_window, fract_tables) else: messagebox.showerror("Error", "Select (a) row(s).") - if event_CCMPS == "-fractionation_edit_keep-": + elif event == "-fractionation_edit_keep-": if values_CCMPS["-fractionation_table-"]: - action.fract_defkeep(values_CCMPS, window_CCMPS, fract_tables) + action.fract_defkeep(values_CCMPS, main_window, fract_tables) else: messagebox.showerror("Error", "Select (a) row(s).") - if event_CCMPS == "-fractionation_edit_condition-": + elif event == "-fractionation_edit_condition-": if values_CCMPS["-fractionation_table-"]: - action.fract_defcon(values_CCMPS, window_CCMPS, fract_tables) + action.fract_defcon(values_CCMPS, main_window, fract_tables) else: messagebox.showerror("Error", "Select (a) row(s).") - if event_CCMPS == "-fractionation_edit_replicate-": + elif event == "-fractionation_edit_replicate-": if values_CCMPS["-fractionation_table-"]: - action.fract_defrep(values_CCMPS, window_CCMPS, fract_tables) + action.fract_defrep(values_CCMPS, main_window, fract_tables) else: messagebox.showerror("Error", "Select (a) row(s).") - if event_CCMPS == "-fractionation_edit_fractions-": + elif event == "-fractionation_edit_fractions-": if values_CCMPS["-fractionation_table-"]: - action.fract_deffract(values_CCMPS, window_CCMPS, fract_tables) + action.fract_deffract(values_CCMPS, main_window, fract_tables) else: messagebox.showerror("Error", "Select (a) row(s).") - if event_CCMPS == "-fractionation_edit_identifier-": + elif event == "-fractionation_edit_identifier-": if values_CCMPS["-fractionation_table-"]: fract_identifiers = action.fract_defident( values_CCMPS, - window_CCMPS, + main_window, fract_tables, fract_pos, fract_identifiers, ) else: messagebox.showerror("Error", "Select (a) row(s).") - if event_CCMPS == "-fractionation_parameters-": + elif event == "-fractionation_parameters-": fract_preparams = PPMS.PPMS_exec_fract(fract_preparams) - if event_CCMPS == "-fractionation_reset-": + elif event == "-fractionation_reset-": sure = sg.popup_yes_no( "Reset Fractionation Pre-Processing? You have to run it again to use your data." ) @@ -1104,7 +1128,7 @@ def main(): fract_info, fract_conditions, ) = action.reset_fract() - action.fract_buttons(window_CCMPS, False) + action.fract_buttons(main_window, False) # window_CCMPS['-marker_fractkey-'].Update(values = ['[IDENTIFIER]'] + list(fract_info)) marker_list = pd.DataFrame() fract_marker = {} @@ -1114,7 +1138,7 @@ def main(): # action.enable_markersettings(window_CCMPS, True) status["fractionation_data"] = False - window_CCMPS["-marker_fractkey-"].Update( + main_window["-marker_fractkey-"].Update( values=["[IDENTIFIER]"], value="" ) status["marker_matched"] = False @@ -1133,7 +1157,7 @@ def main(): else: pass - if event_CCMPS == "-fractionation_start-": + elif event == "-fractionation_start-": if fract_paths: ( fract_data, @@ -1142,7 +1166,7 @@ def main(): fract_info, fract_conditions, ) = FDP.FDP_exec( - window_CCMPS, + main_window, fract_tables, fract_preparams, fract_identifiers, @@ -1153,7 +1177,7 @@ def main(): fract_conditions, fract_indata, ) - window_CCMPS["-marker_fractkey-"].Update( + main_window["-marker_fractkey-"].Update( values=["[IDENTIFIER]"] + list(fract_info) ) if fract_data["class"]: @@ -1163,58 +1187,58 @@ def main(): messagebox.showerror( "No dataset!", "Please import a fractionation dataset." ) - if event_CCMPS == "-fractionation_summary-": + elif event == "-fractionation_summary-": RP.RP_gradient_heatmap(fract_data) # FSD.FSD_exec(fract_preparams, fract_data) # if event_CCMPS == '-fractionation_export-': # action.fract_export(values_CCMPS, fract_data, fract_info) - if event_CCMPS == "-tp_add-": + elif event == "-tp_add-": action.tp_add( values_CCMPS, - window_CCMPS, + main_window, tp_paths, tp_tables, tp_indata, tp_pos, tp_identifiers, ) - if event_CCMPS == "-tp_remove-": + elif event == "-tp_remove-": if values_CCMPS["-tp_path-"]: action.tp_rem( - values_CCMPS, window_CCMPS, tp_paths, tp_tables, tp_data + values_CCMPS, main_window, tp_paths, tp_tables, tp_data ) - if event_CCMPS == "-tp_path-": + elif event == "-tp_path-": action.tp_refreshtable( - window_CCMPS, tp_tables[values_CCMPS["-tp_path-"]] + main_window, tp_tables[values_CCMPS["-tp_path-"]] ) - if event_CCMPS == "-tp_edit_remove-": + elif event == "-tp_edit_remove-": if values_CCMPS["-tp_table-"]: - action.tp_defrem(values_CCMPS, window_CCMPS, tp_tables) + action.tp_defrem(values_CCMPS, main_window, tp_tables) else: messagebox.showerror("Error", "Select (a) row(s).") - if event_CCMPS == "-tp_edit_keep-": + elif event == "-tp_edit_keep-": if values_CCMPS["-tp_table-"]: - action.tp_defkeep(values_CCMPS, window_CCMPS, tp_tables) + action.tp_defkeep(values_CCMPS, main_window, tp_tables) else: messagebox.showerror("Error", "Select (a) row(s).") - if event_CCMPS == "-tp_edit_condition-": + elif event == "-tp_edit_condition-": if values_CCMPS["-tp_table-"]: - action.tp_defcon(values_CCMPS, window_CCMPS, tp_tables) + action.tp_defcon(values_CCMPS, main_window, tp_tables) else: messagebox.showerror("Error", "Select (a) row(s).") - if event_CCMPS == "-tp_edit_identifier-": + elif event == "-tp_edit_identifier-": if values_CCMPS["-tp_table-"]: tp_identifiers = action.tp_defident( values_CCMPS, - window_CCMPS, + main_window, tp_tables, tp_pos, tp_identifiers, ) - if event_CCMPS == "-tp_parameters-": + elif event == "-tp_parameters-": tp_preparams = PPMS.PPMS_exec_TP(tp_preparams) - if event_CCMPS == "-tp_reset-": + elif event == "-tp_reset-": sure = sg.popup_yes_no( "Reset TotalProteome Pre-Processing? You have to run it again to use your data." ) @@ -1228,11 +1252,11 @@ def main(): status["comparison_class"] = False else: pass - if event_CCMPS == "-tp_start-": + elif event == "-tp_start-": if tp_paths: tp_data, tp_intermediate, tp_info, tp_conditions, tp_icorr = ( TPP.TPP_exec( - window_CCMPS, + main_window, tp_data, tp_tables, tp_preparams, @@ -1252,36 +1276,36 @@ def main(): messagebox.showerror( "No dataset!", "Please import a TP dataset." ) - if event_CCMPS == "-tp_export-": + elif event == "-tp_export-": action.tp_export(tp_data, tp_info) - if event_CCMPS == "-marker_add-": - action.marker_add(window_CCMPS, values_CCMPS, marker_sets) - event_CCMPS, values_CCMPS = window_CCMPS.read(timeout=50) + elif event == "-marker_add-": + action.marker_add(main_window, values_CCMPS, marker_sets) + event, values_CCMPS = main_window.read(timeout=50) if marker_sets: status["marker_file"] = True else: status["marker_file"] = False - if event_CCMPS == "-marker_remove-": + elif event == "-marker_remove-": try: - action.marker_remove(window_CCMPS, values_CCMPS, marker_sets) + action.marker_remove(main_window, values_CCMPS, marker_sets) except Exception: pass if marker_sets: status["marker_file"] = True else: status["marker_file"] = False - if event_CCMPS == "-marker_list-": - action.refresh_markercols(window_CCMPS, values_CCMPS, marker_sets) - if event_CCMPS == "-marker_key-": + elif event == "-marker_list-": + action.refresh_markercols(main_window, values_CCMPS, marker_sets) + elif event == "-marker_key-": action.marker_setkey(values_CCMPS, marker_sets) - if event_CCMPS == "-marker_class-": + elif event == "-marker_class-": marker_conv = action.marker_setclass(values_CCMPS, marker_sets) - if event_CCMPS == "-marker_parameters-": + elif event == "-marker_parameters-": marker_params = PPMS.PPMS_exec_marker(marker_params) - if event_CCMPS == "-marker_manage-": + elif event == "-marker_manage-": if action.check_markers(marker_sets): marker_conv = CM.CM_exec(marker_sets, marker_conv) else: @@ -1289,7 +1313,7 @@ def main(): "Error", "Please define key and class column." ) - if event_CCMPS == "-marker_test-": + elif event == "-marker_test-": if action.check_markers(marker_sets): try: marker_list = action.create_markerlist( @@ -1309,7 +1333,7 @@ def main(): messagebox.showerror( "Error", "Please define key and class column." ) - if event_CCMPS == "-marker_profiles-": + elif event == "-marker_profiles-": if action.check_markers(marker_sets): try: marker_list = action.create_markerlist( @@ -1330,7 +1354,7 @@ def main(): "Error", "Please define key and class column." ) - if event_CCMPS == "-marker_accept-": + elif event == "-marker_accept-": if values_CCMPS["-marker_list-"] == []: messagebox.showerror( "Error", "Please import at least one Marker List!" @@ -1383,7 +1407,7 @@ def main(): "Error", "Incompatible Fractionation Key!" ) - if event_CCMPS == "-marker_reset-": + elif event == "-marker_reset-": marker_list = pd.DataFrame() fract_marker = {} fract_marker_vis = {} @@ -1403,10 +1427,10 @@ def main(): # window_CCMPS['-classification_MOP-'].Update(disabled = True) # window_CCMPS['-classification_SVM-'].Update(disabled = True) - if event_CCMPS == "-classification_parameters-": + elif event == "-classification_parameters-": NN_params = PPMS.PPMS_exec_NN(NN_params) - if event_CCMPS == "-classification_MOP-": + elif event == "-classification_MOP-": ( learning_xyz, NN_params, @@ -1431,7 +1455,7 @@ def main(): # window_CCMPS['-status_comparison-'].Update('done!') status["training"] = True - if event_CCMPS == "-classification_reset-": + elif event == "-classification_reset-": svm_marker = svm_test = svm_metrics = learning_xyz = results = ( comparison ) = {} @@ -1441,13 +1465,13 @@ def main(): False ) - if event_CCMPS == "-statistic_predict-": + elif event == "-statistic_predict-": results = MOA.stats_proteome( learning_xyz, NN_params, fract_data, fract_conditions ) status["proteome_prediction"] = True - if event_CCMPS == "-statistic_export-": + elif event == "-statistic_export-": filename = sg.popup_get_file( "Export Statistics", no_window=True, @@ -1458,7 +1482,7 @@ def main(): with open(filename, "wb") as file: pickle.dump(results, file) - if event_CCMPS == "-statistic_import-": + elif event == "-statistic_import-": filename = sg.popup_get_file( "Import Statistics", no_window=True, @@ -1484,7 +1508,7 @@ def main(): except Exception: messagebox.showerror("Error", "Incompatible file type!") - if event_CCMPS == "-statistic_report-": + elif event == "-statistic_report-": export_folder = sg.popup_get_folder("Statistics Report") if export_folder: for condition in results: @@ -1510,7 +1534,7 @@ def main(): ] df_out.to_excel(fname, index=True) - if event_CCMPS == "-global_report-": + elif event == "-global_report-": export_folder = sg.popup_get_folder("Global Changes Report") if export_folder: for comb in comparison: @@ -1542,7 +1566,7 @@ def main(): ] df_out.to_excel(fname, index=True) - if event_CCMPS == "-class_report-": + elif event == "-class_report-": export_folder = sg.popup_get_folder("Class-centric Changes Report") if export_folder: for condition in results: @@ -1595,7 +1619,7 @@ def main(): ] df_out.to_excel(fname, index=True) - if event_CCMPS == "-statistic_reset-": + elif event == "-statistic_reset-": results = comparison = {} status["proteome_prediction"] = status[ "lipidome_prediction" @@ -1603,39 +1627,39 @@ def main(): False ) - if event_CCMPS == "-statistic_heatmap-": + elif event == "-statistic_heatmap-": RP.RP_stats_heatmap(results) - if event_CCMPS == "-statistic_distribution-": + elif event == "-statistic_distribution-": RP.RP_stats_distribution(results) - if event_CCMPS == "-global_heatmap-": + elif event == "-global_heatmap-": RP.RP_global_heatmap(comparison) - if event_CCMPS == "-global_distance-": + elif event == "-global_distance-": RP.RP_global_distance(comparison) - if event_CCMPS == "-class_heatmap-": + elif event == "-class_heatmap-": RP.RP_class_heatmap(results) - if event_CCMPS == "-class_reorganization-": + elif event == "-class_reorganization-": RP.RP_class_reorganization(comparison) - if event_CCMPS == "-global_run-": + elif event == "-global_run-": comparison = MOA.global_comparison(results) status["comparison_global"] = True - if event_CCMPS == "-global_reset-": + elif event == "-global_reset-": comparison = {} status["comparison_global"] = status["comparison_class"] = False - if event_CCMPS == "-class_run-": + elif event == "-class_run-": comparison = MOA.class_comparison( tp_data, fract_conditions, results, comparison ) status["comparison_class"] = True - if event_CCMPS == "-class_reset-": + elif event == "-class_reset-": results, comparison = MOA.class_reset(results, comparison) status["comparison_class"] = False @@ -1646,7 +1670,7 @@ def main(): # if event_CCMPS == '-classification_comparison_rough-': # comparison = MOP_stats.comp_exec3('rough', results, learning_xyz) - if event_CCMPS == "-export_statistics-": + elif event == "-export_statistics-": export_folder = sg.popup_get_folder("Export Statistics") if export_folder: for condition in results: @@ -1676,7 +1700,7 @@ def main(): ) # results[condition]['metrics'].to_csv(fname, sep='\t', index=True, index_label='Identifier') - if event_CCMPS == "-export_comparison-": + elif event == "-export_comparison-": export_folder = sg.popup_get_folder("Export Statistics") if export_folder: for comb in comparison: @@ -1726,7 +1750,7 @@ def main(): # full_path = path+'/CCMPS_export_'+comp+'.tsv' # df_export_part.to_csv(full_path, sep = '\t', index = False) - if event_CCMPS == "Save...": + elif event == "Save...": action.session_save( fract_paths, fract_tables, @@ -1769,7 +1793,7 @@ def main(): values_CCMPS["-marker_fractkey-"], status, ) - if event_CCMPS == "Open...": + elif event == "Open...": filename = sg.popup_get_file( "Open Session", no_window=True, @@ -1817,13 +1841,13 @@ def main(): comparison, marker_fractkey, status, - ) = action.session_open(window_CCMPS, values_CCMPS, filename) + ) = action.session_open(main_window, values_CCMPS, filename) # window_CCMPS['-marker_tpkey-'].Update(values = ['[IDENTIFIER]'] + tp_info.columns.tolist()) - window_CCMPS["-marker_fractkey-"].Update( + main_window["-marker_fractkey-"].Update( values=["[IDENTIFIER]"] + list(fract_info), value=marker_fractkey, ) - if event_CCMPS == "New": + elif event == "New": sure = sg.popup_yes_no( "Are you sure to close the session and start a new one?" ) @@ -1831,8 +1855,8 @@ def main(): fract_paths, fract_tables, fract_data, fract_pos = ( action.resetinput() ) - action.fract_clearinput(window_CCMPS) - action.tp_clearinput(window_CCMPS) + action.fract_clearinput(main_window) + action.tp_clearinput(main_window) fract_indata, fract_identifiers = action.reset_infract() ( fract_data, @@ -1855,16 +1879,16 @@ def main(): ) = svm_marker = svm_test = svm_metrics = learning_xyz = ( results ) = comparison = {} - window_CCMPS["-marker_list-"].Update(values=[]) - window_CCMPS["-marker_key-"].Update(values=[]) - window_CCMPS["-marker_class-"].Update(values=[]) + main_window["-marker_list-"].Update(values=[]) + main_window["-marker_key-"].Update(values=[]) + main_window["-marker_class-"].Update(values=[]) marker_params = {"how": "exclude", "what": "unite"} marker_list = pd.DataFrame NN_params = PPMS.NN_default() status = action.default_status() - window_CCMPS["-marker_fractkey-"].Update( + main_window["-marker_fractkey-"].Update( values=["[IDENTIFIER]"] + list(fract_info) ) else: @@ -1872,10 +1896,12 @@ def main(): # ----------------------------------------------------------------------------------------------------------------------------- - if event_CCMPS == sg.WIN_CLOSED or event_CCMPS == "Exit": + elif event == sg.WIN_CLOSED or event == "Exit": break - action.refresh_window(window_CCMPS, status) - window_CCMPS.close() + + action.refresh_window(main_window, status) + + main_window.close() # import dill # filepath = 'session.pkl'