Skip to content

Commit

Permalink
Merge pull request #55 from MetaSys-LISBP/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
llegregam committed Mar 18, 2024
2 parents d0d85f2 + eda57c7 commit 41349d6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 35 deletions.
5 changes: 4 additions & 1 deletion physiofit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import importlib.metadata
import logging

__version__ = importlib.metadata.version("physiofit")
__version__ = importlib.metadata.version("physiofit")
logger = logging.getLogger("physiofit")
logger.setLevel(logging.DEBUG)
6 changes: 2 additions & 4 deletions physiofit/base/fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -320,15 +320,13 @@ def _run_optimization(
"""

if method == "differential_evolution":
logger.debug(f"Optimization method = {method}")
optimize_results = differential_evolution(
PhysioFitter._calculate_cost, bounds=bounds,
args=(
func, exp_data_matrix, time_vector, non_opt_params, sd_matrix),
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=(
Expand Down
3 changes: 1 addition & 2 deletions physiofit/base/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
56 changes: 29 additions & 27 deletions physiofit/ui/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "GNU General Public License (GPL)"
Expand Down

0 comments on commit 41349d6

Please sign in to comment.