From ea6e28e86b57ce8741de1ab63dbb5bf074f9f3d1 Mon Sep 17 00:00:00 2001 From: legregam Date: Mon, 18 Mar 2024 14:01:04 +0100 Subject: [PATCH 1/4] changed logging system to have multiple levels and cleaner logs --- physiofit/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/physiofit/__init__.py b/physiofit/__init__.py index 7077eb4..e56be43 100644 --- a/physiofit/__init__.py +++ b/physiofit/__init__.py @@ -1,3 +1,6 @@ import importlib.metadata +import logging -__version__ = importlib.metadata.version("physiofit") \ No newline at end of file +__version__ = importlib.metadata.version("physiofit") +logger = logging.getLogger("physiofit") +logger.setLevel(logging.DEBUG) \ No newline at end of file From e03d04e404e76adb9ca82ccf02fd13a78d58665a Mon Sep 17 00:00:00 2001 From: legregam Date: Mon, 18 Mar 2024 14:01:18 +0100 Subject: [PATCH 2/4] fixed bug where final summary didnt have all experiments --- physiofit/ui/cli.py | 56 +++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/physiofit/ui/cli.py b/physiofit/ui/cli.py index 723e124..64720ae 100644 --- a/physiofit/ui/cli.py +++ b/physiofit/ui/cli.py @@ -19,6 +19,8 @@ from physiofit.base.io import IoHandler, StandardDevs, ConfigParser +logger = logging.getLogger(f"physiofit") + def args_parse(): """ Parse arguments from user input. @@ -59,18 +61,18 @@ def args_parse(): ) # Parse selective output path arguments (for galaxy implementation mostly) - parser.add_argument( - "-op", "--output_pdf", type=str, - help="Path to output the pdf file containing plots" - ) - parser.add_argument( - "-of", "--output_fluxes", type=str, - help="Path to output the flux results" - ) - parser.add_argument( - "-os", "--output_stats", type=str, - help="Path to output the khi² test" - ) + # parser.add_argument( + # "-op", "--output_pdf", type=str, + # help="Path to output the pdf file containing plots" + # ) + # parser.add_argument( + # "-of", "--output_fluxes", type=str, + # help="Path to output the flux results" + # ) + # parser.add_argument( + # "-os", "--output_stats", type=str, + # help="Path to output the khi² test" + # ) parser.add_argument( "-oc", "--output_config", type=str, help="Path to output the yaml config file" @@ -88,11 +90,11 @@ def args_parse(): def run(data, args, logger, experiments): + io = IoHandler() for exp in experiments: - io = IoHandler() exp_data = data.loc[exp, :].sort_values("time").copy() logger.info(f"Input Data: \n{exp_data}") - if hasattr(args, 'galaxy'): + if args.galaxy: io.wkdir = Path('.') else: io.wkdir = Path(args.data).parent @@ -129,10 +131,7 @@ def run(data, args, logger, experiments): if not io.multiple_experiments: io.multiple_experiments = [] io.multiple_experiments.append(df) - if exp is not None: - res_path = io.wkdir / (io.wkdir.name + "_res") / exp - else: - res_path = io.wkdir / (io.wkdir.name + "_res") + res_path = io.wkdir / (io.wkdir.name + "_res") / exp logger.info(res_path) if not res_path.is_dir(): res_path.mkdir(parents=True) @@ -149,13 +148,17 @@ def run(data, args, logger, experiments): # for line in dir.rglob("*"): # print(line) generate_zips(str(dir), args.output_zip, logger) + logger.debug(f"Dataframes to concatenate:\n{io.multiple_experiments}") # shutil.make_archive( # args.output_zip, # format='zip', # root_dir=str(io.home_path / (io.home_path.name + "_res")) # ) - io.output_recap(export_path=args.output_recap, galaxy=True) + if args.galaxy: + io.output_recap(export_path=args.output_recap, galaxy=args.galaxy) + else: + io.output_recap(export_path=str(res_path.parent), galaxy=False) def generate_zips(path_to_data_folder, output_path, logger): """Generate output zip file containing results @@ -221,16 +224,15 @@ def generate_config(args, data, logger): def process(args): - logger = logging.getLogger() - logger.setLevel(logging.DEBUG) - out_stream = logging.StreamHandler() - formatter = logging.Formatter() - out_stream.setFormatter(formatter) + cli_handle = logging.StreamHandler() + formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') + cli_handle.setFormatter(formatter) if args.debug_mode: - out_stream.setLevel(logging.DEBUG) + cli_handle.setLevel(logging.DEBUG) else: - out_stream.setLevel(logging.INFO) - logger.addHandler(out_stream) + cli_handle.setLevel(logging.INFO) + logger.addHandler(cli_handle) + if args.list: IoHandler.get_model_list() From 00f280e3c4592a2ab3bfa22e7bdfa6f5951843cb Mon Sep 17 00:00:00 2001 From: legregam Date: Mon, 18 Mar 2024 14:01:29 +0100 Subject: [PATCH 3/4] logging system tweak --- physiofit/base/fitter.py | 6 ++---- physiofit/base/io.py | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/physiofit/base/fitter.py b/physiofit/base/fitter.py index 60d7088..70f0d7c 100644 --- a/physiofit/base/fitter.py +++ b/physiofit/base/fitter.py @@ -11,8 +11,8 @@ from physiofit.models.base_model import Model -logger = logging.getLogger(__name__) -logger.setLevel(logging.INFO) +logger = logging.getLogger(f"physiofit.{__name__}") + # TODO: add estimate deg function (eq 6) with plot of best fit and measured values @@ -320,7 +320,6 @@ def _run_optimization( """ if method == "differential_evolution": - logger.debug(f"Optimization method = {method}") optimize_results = differential_evolution( PhysioFitter._calculate_cost, bounds=bounds, args=( @@ -328,7 +327,6 @@ def _run_optimization( polish=True, x0=np.array(params) ) elif method == "L-BFGS-B": - logger.debug(f"Optimization method = {method}") optimize_results = minimize( PhysioFitter._calculate_cost, x0=np.array(params), args=( diff --git a/physiofit/base/io.py b/physiofit/base/io.py index 95d9f00..5a8ce38 100644 --- a/physiofit/base/io.py +++ b/physiofit/base/io.py @@ -22,8 +22,7 @@ # Switch matplotlib logger to higher level to not get debug logs in root logger logging.getLogger("matplotlib").setLevel(logging.WARNING) -logger = logging.getLogger(__name__) -logger.setLevel(logging.DEBUG) +logger = logging.getLogger(f"physiofit.{__name__}") class IoHandler: From eda57c7a27671c45f7f503892beab47914160fc8 Mon Sep 17 00:00:00 2001 From: legregam Date: Mon, 18 Mar 2024 14:01:39 +0100 Subject: [PATCH 4/4] bump to 3.3.5 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 069235a..aa4f6e3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "physiofit" -version = "3.3.4" +version = "3.3.5" description = "Calculate extracellular fluxes from metabolite concentrations and biomass data" authors = ["llegregam "] license = "GNU General Public License (GPL)"