From 2f812443f1b74d90fb9412507597b9dc350382ec Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Mon, 13 Jan 2025 21:24:41 +0100 Subject: [PATCH] Add module-level docstring stubs, cleanup (#40) Add module-level docstring stubs, cleanup --- src/ccompass/CCMPS.py | 20 ++------------------ src/ccompass/CCMPS_actions.py | 14 ++------------ src/ccompass/CM.py | 2 +- src/ccompass/FDP.py | 10 +--------- src/ccompass/FSD.py | 6 +----- src/ccompass/MOA.py | 3 +-- src/ccompass/MOP.py | 21 +++++++-------------- src/ccompass/MOP_stats.py | 2 +- src/ccompass/NPC.py | 6 ++---- src/ccompass/NPC_func.py | 5 ----- src/ccompass/PPMS.py | 2 +- src/ccompass/PPMS_actions.py | 11 +---------- src/ccompass/RP.py | 3 ++- src/ccompass/SM.py | 3 +-- src/ccompass/SOP.py | 5 ++--- src/ccompass/TM.py | 2 +- src/ccompass/TPP.py | 12 +----------- 17 files changed, 27 insertions(+), 100 deletions(-) diff --git a/src/ccompass/CCMPS.py b/src/ccompass/CCMPS.py index 6f4ec6d..7e7d0cd 100644 --- a/src/ccompass/CCMPS.py +++ b/src/ccompass/CCMPS.py @@ -1,4 +1,4 @@ -##### CELLCOMPASS +"""C-COMPASS main window.""" from . import CCMPS_actions as action from . import PPMS @@ -10,34 +10,18 @@ from . import MOA from . import SM from . import RP - - import copy import pickle - -# from NPC import NPC -# from MLO_01_function import MLO, first_prediction -# from CM_01_function import CM -# from MM_01_function import MM - from tkinter import messagebox - - -# import runpy - import FreeSimpleGUI as sg import pandas as pd - import os os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" -# ----------------------------------------------------------------------------------------------------------------------------- - -import os - 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() diff --git a/src/ccompass/CCMPS_actions.py b/src/ccompass/CCMPS_actions.py index 3768424..9c6d531 100644 --- a/src/ccompass/CCMPS_actions.py +++ b/src/ccompass/CCMPS_actions.py @@ -1,3 +1,5 @@ +"""Actions related to the main window.""" + import FreeSimpleGUI as sg import numpy as np import pandas as pd @@ -7,14 +9,6 @@ import copy -## parameters: -# ------------------------------------------------------------------------------ - - -## internal functions: -# ------------------------------------------------------------------------------ - - def fract_refreshtable(window, table): window["-fractionation_table-"].Update(values=table) return @@ -140,10 +134,6 @@ def tp_clearinput(window): return -## external functions: -# ------------------------------------------------------------------------------ - - def reset_infract(): fract_indata = {} fract_identifiers = {} diff --git a/src/ccompass/CM.py b/src/ccompass/CM.py index 1c0ef26..1b031fc 100644 --- a/src/ccompass/CM.py +++ b/src/ccompass/CM.py @@ -1,4 +1,4 @@ -##### CLASS MANAGER +"""Class manager.""" import FreeSimpleGUI as sg import numpy as np diff --git a/src/ccompass/FDP.py b/src/ccompass/FDP.py index b271616..d4f3588 100644 --- a/src/ccompass/FDP.py +++ b/src/ccompass/FDP.py @@ -1,4 +1,4 @@ -##### FRACTIONATION DATA PROCESSING +"""Fractionation data processing.""" import copy import numpy as np @@ -10,10 +10,6 @@ from collections import Counter -## internal functions: -# ------------------------------------------------------------------------------ - - def create_dataset( input_data, input_tables, identifiers, conditions, window_FDP, progress ): @@ -471,10 +467,6 @@ def modify_structure(data_in): return data_out -## run script:: -# ------------------------------------------------------------------------------ - - def FDP_exec( window, input_tables, diff --git a/src/ccompass/FSD.py b/src/ccompass/FSD.py index d8801ee..de935ba 100644 --- a/src/ccompass/FSD.py +++ b/src/ccompass/FSD.py @@ -1,12 +1,8 @@ -##### FRACTIONATION SUMMARY DISPLAY +"""Fractionation summary display.""" import FreeSimpleGUI as sg -## internal functions: -# ------------------------------------------------------------------------------ - - def FSD_exec(preparams, data_ways): class_string = "" for condition in data_ways["class"]: diff --git a/src/ccompass/MOA.py b/src/ccompass/MOA.py index 05ca792..a0abc6c 100644 --- a/src/ccompass/MOA.py +++ b/src/ccompass/MOA.py @@ -1,5 +1,4 @@ -### MULTIPLE ORGANELLE ANALYSIS - +"""Multiple organelle analysis.""" import pandas as pd import numpy as np diff --git a/src/ccompass/MOP.py b/src/ccompass/MOP.py index e1fa983..34964fc 100644 --- a/src/ccompass/MOP.py +++ b/src/ccompass/MOP.py @@ -1,11 +1,11 @@ -##### MULTIPLE ORGANELLE PREDICTION +"""Multiple organelle prediction.""" + import numpy as np import pandas as pd import random import copy from datetime import datetime from scipy import stats - from sklearn import svm from sklearn.metrics import ( accuracy_score, @@ -14,7 +14,6 @@ f1_score, confusion_matrix, ) - import tensorflow as tf from tensorflow import keras import keras_tuner as kt @@ -23,16 +22,6 @@ # from tensorflow.keras.models import Model -import os - -# Define the path to the 'Classifier_Models' folder within the user's data directory -classifier_directory = get_data_directory() / "CCOMPASS_Models" - -# Create the folder if it does not exist -if not os.path.exists(classifier_directory): - os.makedirs(classifier_directory) - - optimizer_classes = { "adam": tf.keras.optimizers.Adam, "rmsprop": tf.keras.optimizers.RMSprop, @@ -822,6 +811,10 @@ def multi_predictions( ] set_shapes = [np.shape(y_train_mixed_up)[1], np.shape(Z_train_mixed_up)[1]] + # Define the path to the 'Classifier_Models' folder within the user's data directory + classifier_directory = get_data_directory() / "CCOMPASS_Models" + classifier_directory.mkdir(exist_ok=True, parents=True) + now = datetime.now() time = now.strftime("%Y%m%d%H%M%S") FNN_tuner = kt.Hyperband( @@ -830,7 +823,7 @@ def multi_predictions( objective="val_mean_squared_error", max_epochs=NN_params["NN_epochs"], factor=3, - directory=classifier_directory, + directory=str(classifier_directory), project_name=time + "_Classifier_" + condition + "_" + str(roundn), ) diff --git a/src/ccompass/MOP_stats.py b/src/ccompass/MOP_stats.py index 2036f65..a6ba67d 100644 --- a/src/ccompass/MOP_stats.py +++ b/src/ccompass/MOP_stats.py @@ -1,4 +1,4 @@ -## MULTI ORGANELLE PREDICTION STATISTICS +"""Multi-organelle prediction statistics.""" import numpy as np import pandas as pd diff --git a/src/ccompass/NPC.py b/src/ccompass/NPC.py index 80a8eab..ec1c7e7 100644 --- a/src/ccompass/NPC.py +++ b/src/ccompass/NPC.py @@ -1,9 +1,10 @@ +"""Normalized profile creation""" + import copy import numpy as np import pandas as pd import FreeSimpleGUI as sg from tkinter import messagebox, simpledialog - from .NPC_func import ( create_dataset, pre_scaling, @@ -23,9 +24,6 @@ ) from datetime import datetime -# ----------------------------------------------------------------------------- -## Local functions: -# ----------------------------------------------------------------------------- def create_data(path): # creates initial dataset with corresponding data table diff --git a/src/ccompass/NPC_func.py b/src/ccompass/NPC_func.py index 8f482a4..c0a21a7 100644 --- a/src/ccompass/NPC_func.py +++ b/src/ccompass/NPC_func.py @@ -10,11 +10,6 @@ def pre_process(): return -# ----------------------------------------------------------------------------- -## Local functions: -# ----------------------------------------------------------------------------- - - def create_condition_dataset( data_init, tables_init, conditions, idents ): # creates dictionary containing data sorted by condition diff --git a/src/ccompass/PPMS.py b/src/ccompass/PPMS.py index 86d8cd3..d46648b 100644 --- a/src/ccompass/PPMS.py +++ b/src/ccompass/PPMS.py @@ -1,4 +1,4 @@ -##### PREPARAMETERS +"""Preparameters""" import FreeSimpleGUI as sg from . import PPMS_actions as action diff --git a/src/ccompass/PPMS_actions.py b/src/ccompass/PPMS_actions.py index ea60fae..07b4ced 100644 --- a/src/ccompass/PPMS_actions.py +++ b/src/ccompass/PPMS_actions.py @@ -1,13 +1,4 @@ -## parameters: -# ------------------------------------------------------------------------------ - - -## internal functions: -# ------------------------------------------------------------------------------ - - -## external functions: -# ------------------------------------------------------------------------------ +"""Preparameter GUI actions.""" def set_combinations(params): diff --git a/src/ccompass/RP.py b/src/ccompass/RP.py index c2bffcc..1148c34 100644 --- a/src/ccompass/RP.py +++ b/src/ccompass/RP.py @@ -1,4 +1,5 @@ -### RESULT PLOTS +"""Result plots""" + import FreeSimpleGUI as sg import pandas as pd import seaborn as sns diff --git a/src/ccompass/SM.py b/src/ccompass/SM.py index 5e3b1b4..705684c 100644 --- a/src/ccompass/SM.py +++ b/src/ccompass/SM.py @@ -1,5 +1,4 @@ -## SHOW MARKERS - +"""Show markers.""" import FreeSimpleGUI as sg import pandas as pd diff --git a/src/ccompass/SOP.py b/src/ccompass/SOP.py index 41a707c..5a5e843 100644 --- a/src/ccompass/SOP.py +++ b/src/ccompass/SOP.py @@ -1,4 +1,5 @@ -##### SINGLE ORGANELLE PREDICTION +"""Single organelle prediction.""" + import pandas as pd from sklearn import svm from sklearn.metrics import ( @@ -8,11 +9,9 @@ f1_score, confusion_matrix, ) - import matplotlib.pyplot as plt import copy - clf = svm.SVC(kernel="rbf", probability=True) diff --git a/src/ccompass/TM.py b/src/ccompass/TM.py index 86935ad..9f1615e 100644 --- a/src/ccompass/TM.py +++ b/src/ccompass/TM.py @@ -1,4 +1,4 @@ -##### TEST MARKER +"""Test marker""" import FreeSimpleGUI as sg import pandas as pd diff --git a/src/ccompass/TPP.py b/src/ccompass/TPP.py index bfc3d0d..fea29f5 100644 --- a/src/ccompass/TPP.py +++ b/src/ccompass/TPP.py @@ -1,4 +1,4 @@ -##### TOTAL PROTEOME PROCESSING +"""Total proteome profiling.""" import copy import math @@ -9,10 +9,6 @@ from scipy.stats import pearsonr -## internal functions: -# ------------------------------------------------------------------------------ - - def create_dataset( tp_indata, tp_tables, tp_identifiers, tp_conditions, window ): @@ -169,12 +165,6 @@ def normalize_data(data, window): return data -## run script:: -# ------------------------------------------------------------------------------ - -# minrep = 2 - - def TPP_exec( window, tp_data,