Skip to content

Commit

Permalink
fix(rpfba): remove medium feature
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-gricourt committed May 17, 2023
1 parent 731f658 commit 0bd7bc3
Show file tree
Hide file tree
Showing 21 changed files with 397 additions and 1,786 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ node_modules
_exclude
/docsource/_build/
/docsource/_autosummary
cicd-toolkit
cicd-toolkit
*.egg-info
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ graft rptools/rpthermo/data
graft rptools/rpscore/models
graft rptools/rpviz/data
graft rptools/rpviz/templates
graft rptools/rpfba/medium
90 changes: 25 additions & 65 deletions rptools/rpfba/Args.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,95 +3,55 @@
List,
)
from rptools._version import __version__
from rptools.rpfba.medium import (
__MEDIUM_DEFAULT_ID,
__MEDIUM_PATH,
read_medium_ids
)

def add_arguments(
parser: ArgumentParser):
parser.add_argument(
'pathway_file',
type=str,
help='SBML file that contains an heterologous pathway'
)
parser.add_argument(
'model_file',
type=str,
help='GEM model file (SBML)'
)

def add_arguments(parser: ArgumentParser):
parser.add_argument(
'compartment_id',
type=str,
help='model compartment id to consider (e.g. \'c\' or \'MNXC3\')'
"pathway_file", type=str, help="SBML file that contains an heterologous pathway"
)
parser.add_argument("model_file", type=str, help="GEM model file (SBML)")
parser.add_argument(
'outfile',
"compartment_id",
type=str,
help='output file'
help="model compartment id to consider (e.g. 'c' or 'MNXC3')",
)
parser.add_argument("outfile", type=str, help="output file")
parser.add_argument(
'--objective_rxn_id',
"--objective_rxn_id",
type=str,
default='rxn_target',
help='reaction ID to optimise (default: rxn_target)'
default="rxn_target",
help="reaction ID to optimise (default: rxn_target)",
)
parser.add_argument(
'--biomass_rxn_id',
"--biomass_rxn_id",
type=str,
default='biomass',
help='biomass reaction ID (default: biomass). Note: Only for \'fraction\' simulation'
default="biomass",
help="biomass reaction ID (default: biomass). Note: Only for 'fraction' simulation",
)
parser.add_argument(
'--sim',
"--sim",
type=str,
choices=['fba', 'pfba', 'fraction'],
default='fraction',
help='type of simulation to use (default: fraction)'
choices=["fba", "pfba", "fraction"],
default="fraction",
help="type of simulation to use (default: fraction)",
)
parser.add_argument(
'--fraction_of',
"--fraction_of",
type=float,
default=0.75,
help='fraction of the optimum (default: 0.75). Note: this value is ignored is \'fba\' is used'
help="fraction of the optimum (default: 0.75). Note: this value is ignored is 'fba' is used",
)
parser.add_argument(
'--merge',
action='store_true',
"--merge",
action="store_true",
default=False,
help='output the full merged model in addition of heterologous pathway only (default: False)'
help="output the full merged model in addition of heterologous pathway only (default: False)",
)
parser.add_argument(
'--ignore_orphan_species',
action='store_true',
"--ignore_orphan_species",
action="store_true",
default=True,
help='ignore metabolites that are only consumed or produced (default: True)'
help="ignore metabolites that are only consumed or produced (default: True)",
)

parser_medium = parser.add_argument_group('Medium', 'Medium modifications')
parser_medium.add_argument('--medium_compartment_id',
type=str,
default='MNXC2',
help='Model compartiment id corresponding to the extra-cellular compartment'
)
parser_medium.add_argument(
'--medium_file',
type=str,
help='Provide a csv file with an header as <coumpond_id>,<upper_bound>. \
This file provides information about metabolites (Metanetx Id) to add or remove (giving upper bound value)'
)
parser_medium.add_argument(
'--medium_id',
type=str,
default=__MEDIUM_DEFAULT_ID,
choices=[__MEDIUM_DEFAULT_ID] + read_medium_ids(__MEDIUM_PATH),
help='Use a base medium composition. Data can be add with the option --medium_file'
)
parser_medium.add_argument(
'--minimal_medium_file',
type=str,
help='Provide a path of a CSV file to output information about minimal medium'
)

return parser
75 changes: 19 additions & 56 deletions rptools/rpfba/__main__.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,40 @@
import pandas as pd

from os import (
path as os_path,
makedirs as os_makedirs
)
from errno import (
EEXIST as errno_EEXIST
)
from logging import (
Logger,
getLogger
)
from typing import(
List,
Dict,
Tuple
)
from os import path as os_path, makedirs as os_makedirs
from errno import EEXIST as errno_EEXIST
from logging import Logger, getLogger
from typing import List, Dict, Tuple
from copy import deepcopy
from rptools import build_args_parser
from rptools.rpfba.Args import add_arguments
from rptools.rpfba.medium import (
__MEDIUM_PATH,
load_compounds,
)
from rptools.rpfba import (
runFBA
)
from rptools.rpfba import runFBA
from rptools.rplibs.rpPathway import rpPathway


def entry_point():
def _make_dir(filename):
dirname = os_path.dirname(filename)
if dirname != '' and not os_path.exists(dirname):
if dirname != "" and not os_path.exists(dirname):
try:
os_makedirs(dirname)
except OSError as exc: # Guard against race condition
except OSError as exc: # Guard against race condition
if exc.errno != errno_EEXIST:
raise

# Args.
parser = build_args_parser(
prog = 'rpfba',
description='Process to Flux Balance Analysis',
m_add_args=add_arguments
prog="rpfba",
description="Process to Flux Balance Analysis",
m_add_args=add_arguments,
)
args = parser.parse_args()

# Init.
from rptools.__main__ import init
logger = init(parser, args)

pathway = rpPathway.from_rpSBML(
infile=args.pathway_file,
logger=logger
)
logger = init(parser, args)

# Load compounds.
df_medium_base, df_medium_user = load_compounds(
medium_id=args.medium_id,
file_base=__MEDIUM_PATH,
file_user=args.medium_file,
logger=logger
)
pathway = rpPathway.from_rpSBML(infile=args.pathway_file, logger=logger)

results = runFBA(
pathway=pathway,
Expand All @@ -72,28 +46,17 @@ def _make_dir(filename):
fraction_coeff=args.fraction_of,
merge=args.merge,
ignore_orphan_species=args.ignore_orphan_species,
medium_compartment_id=args.medium_compartment_id,
df_medium_base=df_medium_base,
df_medium_user=df_medium_user,
logger=logger
logger=logger,
)

if results is None:
logger.info('No results written. Exiting...')
logger.info("No results written. Exiting...")
else:
logger.info('Writing into file...')
logger.info("Writing into file...")
_make_dir(args.outfile)
pathway.to_rpSBML().write_to_file(args.outfile)
logger.info(' |--> written in ' + args.outfile)
logger.info(" |--> written in " + args.outfile)

if args.minimal_medium_file:
minimal_medium = results.get(
'minimal_medium',
pd.DataFrame()
)
_make_dir(args.minimal_medium_file)
minimal_medium.to_csv(args.minimal_medium_file)
logger.info(' |--> written in ' + args.minimal_medium_file)

if __name__ == '__main__':
if __name__ == "__main__":
entry_point()
Loading

0 comments on commit 0bd7bc3

Please sign in to comment.