Skip to content

Commit

Permalink
Merge pull request #51 from MetaSys-LISBP/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
llegregam committed Dec 19, 2023
2 parents 272a8b1 + af67996 commit 4979be3
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ physiofit.egg-info/requires.txt
physiofit.egg-info/SOURCES.txt
physiofit.egg-info/top_level.txt
/versions publi/
/physiofit/data/
18 changes: 9 additions & 9 deletions physiofit/base/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self):
self.simulated_data_sds = None
self.simulated_data = None
self.experimental_data = None
self.home_path = None
self.wkdir = None
self.data_path = None
self.res_path = None
self.has_config_been_read = False
Expand Down Expand Up @@ -145,16 +145,16 @@ def _verify_data(data: DataFrame):
"DataFrame has not been generated"
)

for x in ["time", "X"]:
for x in ["time", "X", "experiments"]:
if x not in data.columns:
raise ValueError(f"Column {x} is missing from the dataset")
if data.columns[0] != "experiments":
raise ValueError("First column should be 'experiments'")
if data.columns[1] != "time":
raise ValueError("Second column should be 'time'")

if "experiment" in data.columns:
if len(data.columns) <= 3:
raise ValueError(f"Data does not contain any metabolite columns")
else:
if len(data.columns) <= 2:
raise ValueError(f"Data does not contain any metabolite columns")
if len(data.columns) <= 3:
raise ValueError(f"Data does not contain any metabolite columns")

for x in data.columns:
if x != "experiments" and data[x].dtypes != np.int64 and data[x].dtypes != np.float64:
Expand Down Expand Up @@ -219,7 +219,7 @@ def add_model(model_file):
def read_yaml(yaml_file: str | bytes) -> ConfigParser:

"""
Import raml configuration file and parse keyword arguments
Import yaml configuration file and parse keyword arguments
:param yaml_file: path to the yaml file or json file
:return config_parser: Dictionary containing arguments parsed from yaml file
Expand Down
17 changes: 0 additions & 17 deletions physiofit/data/data_example.tsv

This file was deleted.

17 changes: 0 additions & 17 deletions physiofit/data/test-data_single_exp.tsv

This file was deleted.

12 changes: 0 additions & 12 deletions physiofit/models/template.py

This file was deleted.

12 changes: 7 additions & 5 deletions physiofit/ui/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import logging
from pathlib import Path
import sys
# import shutil

import pandas as pd

Expand Down Expand Up @@ -93,8 +92,11 @@ def run(data, args, logger, experiments):
io = IoHandler()
exp_data = data.loc[exp, :].sort_values("time").copy()
logger.info(f"Input Data: \n{exp_data}")
io.home_path = Path(args.data).parent
logger.info(f"Home path: {io.home_path}")
if hasattr(args, 'galaxy'):
io.wkdir = Path('.')
else:
io.wkdir = Path(args.data).parent
logger.info(f"Home path: {io.wkdir}")
logger.info(f"Reading configuration file at {args.config}")
io.configparser = io.read_yaml(args.config)
logger.info(f"Config File:\n{io.configparser}")
Expand Down Expand Up @@ -128,9 +130,9 @@ def run(data, args, logger, experiments):
io.multiple_experiments = []
io.multiple_experiments.append(df)
if exp is not None:
res_path = io.home_path / (io.home_path.name + "_res") / exp
res_path = io.wkdir / (io.wkdir.name + "_res") / exp
else:
res_path = io.home_path / (io.home_path.name + "_res")
res_path = io.wkdir / (io.wkdir.name + "_res")
logger.info(res_path)
if not res_path.is_dir():
res_path.mkdir(parents=True)
Expand Down
32 changes: 16 additions & 16 deletions physiofit/ui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _initialize_opt_menu(self):
except Exception:
st.error("An error has occurred when reading the yaml configuration file.")
raise
elif file_extension in ["tsv", "txt"]:
elif file_extension in ["tsv", "txt"]:
try:
self.io.data = self.io.read_data(self.data_file)
# Initialize default SDs
Expand Down Expand Up @@ -141,10 +141,10 @@ def _initialize_opt_menu(self):
except Exception:
st.error("An error has occurred when initializing the model")
raise
if not self.io.home_path:
if not self.io.wkdir:
raise ValueError("No output directory selected")
self.config_parser = ConfigParser(
path_to_data = self.io.home_path / self.data_file.name,
path_to_data =self.io.wkdir / self.data_file.name,
selected_model= self.model,
sds = self.sd,
mc = self.mc,
Expand Down Expand Up @@ -284,8 +284,8 @@ def _initialize_opt_menu_widgets(self, file_extension):
self._output_directory_selector()

else:
self.io.home_path = Path(self.config_parser.path_to_data).resolve().parent
self.io.res_path = self.io.home_path / (self.io.home_path.name + "_res")
self.io.wkdir = Path(self.config_parser.path_to_data).resolve().parent
self.io.res_path = self.io.wkdir / (self.io.wkdir.name + "_res")

# Build the form for advanced parameters
form = st.form("Parameter_form")
Expand Down Expand Up @@ -500,28 +500,28 @@ def _output_directory_selector(self):

# Initialize home path from directory selector and add
# to session state
st.session_state.home_path = Path(st.text_input(
st.session_state.wkdir = Path(st.text_input(
"Selected output data directory:",
filedialog.askdirectory(master=root)
))
if st.session_state.home_path == Path(".") \
or not st.session_state.home_path.exists():
if st.session_state.wkdir == Path(".") \
or not st.session_state.wkdir.exists():
raise RuntimeError("Please provide a valid output directory")
self.io.home_path = copy(
st.session_state.home_path)
self.io.wkdir = copy(
st.session_state.wkdir)

elif hasattr(st.session_state, "home_path"):
elif hasattr(st.session_state, "wkdir"):

self.io.home_path = Path(st.text_input(
self.io.wkdir = Path(st.text_input(
"Selected output data directory:",
st.session_state.home_path
st.session_state.wkdir
))
if self.io.home_path == Path(".") \
or not self.io.home_path.exists():
if self.io.wkdir == Path(".") \
or not self.io.wkdir.exists():
raise RuntimeError("Please provide a valid output directory")

# Initialize the result export directory
self.io.res_path = self.io.home_path / (self.io.home_path.name + "_res")
self.io.res_path = self.io.wkdir / (self.io.wkdir.name + "_res")
if not clicked:
if not self.io.res_path.is_dir():
self.io.res_path.mkdir()
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.1"
version = "3.3.2"
description = "Calculate extracellular fluxes from metabolite concentrations and biomass data"
authors = ["llegregam <[email protected]>"]
license = "GNU General Public License (GPL)"
Expand Down
Binary file added validation/Validation.pdf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ model:
S_GlcEq_s_0: 100
X_0: 1
y_BM: 1
path_to_data: ..\data.tsv
path_to_data: ".\\validation\\models\\Monod_model\\physiofit_results\\data.tsv"
sds:
P_ethanol: 3
S_GlcEq: 7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ model:
Glc_q: 1
X_0: 1
growth_rate: 1
path_to_data: C:\Users\millard\Documents\GIT\PhysioFit\data_test\Steady-state_model\data.txt
path_to_data: ".\\validation\\models\\Steady-state_model\\physiofit_results\\results\\config_file.yml"
sds:
Ace: 0.2
Glc: 0.46
Expand Down
Binary file removed validation/models/~$results.xlsx
Binary file not shown.

0 comments on commit 4979be3

Please sign in to comment.