Skip to content

Commit

Permalink
feat(rpfbagr): allow medium file fmt csv and tsv
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-gricourt committed Aug 9, 2022
1 parent 0c13f5e commit a0f58d8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/rpfbagr/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def main():
parser_medium.add_argument(
"--input-medium-file",
type=str,
help="Provide a csv file with an header as <coumpond_id>,"
help="Provide a csv or tsv file with an header as <coumpond_id>,"
"<lower_bound>, <upper_bound>. This file "
"provides information about metabolites (Metanetx Id) "
"to add or remove.",
Expand Down
11 changes: 10 additions & 1 deletion src/rpfbagr/medium.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import csv
import logging
from collections import OrderedDict

Expand All @@ -6,8 +7,16 @@


def load_medium(path: str) -> dict:
# Find delimiter.
with open(path) as fid:
dialect = csv.Sniffer().sniff(fid.readline())
# Load.
df = pd.read_csv(
path, header=None, index_col=0, names=["reaction", "lower", "upper"]
path,
header=None,
index_col=0,
names=["reaction", "lower", "upper"],
sep=dialect.delimiter,
)
medium = df.to_dict("index")
envcond = OrderedDict()
Expand Down
2 changes: 2 additions & 0 deletions tests/dataset/medium/butanol.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EX_glc__D_e -10.0 10.0
EX_o2_e -5.0 5.0
3 changes: 2 additions & 1 deletion tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class Main_test(unittest.TestCase):
dataset_path = os.path.join(os.path.dirname(__file__), "dataset")
# Medium.
medium_path = os.path.join(dataset_path, "medium")
medium_butanol = os.path.join(medium_path, "butanol.csv")
medium_butanol_csv = os.path.join(medium_path, "butanol.csv")
medium_butanol_tsv = os.path.join(medium_path, "butanol.tsv")
# Model.
model_path = os.path.join(dataset_path, "model")
model_ecoli = os.path.join(model_path, "iAF1260.xml")
Expand Down
9 changes: 7 additions & 2 deletions tests/test_medium.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

class Test_functional(Main_test):
def test_load_medium(self):
medium = load_medium(self.medium_butanol)
medium = load_medium(self.medium_butanol_csv)
theorical_medium = OrderedDict(
{"EX_glc__D_e": (-10.0, 10.0), "EX_o2_e": (-5.0, 5.0)}
)
self.assertEqual(medium, theorical_medium)

def test_associate_flux_env(self):
medium = load_medium(self.medium_butanol)
medium = load_medium(self.medium_butanol_csv)
model = load_model(self.model_ecoli)
self.assertEqual(
model.reactions.get_by_id("EX_glc__D_e").bounds, (-8.0, 999999.0)
Expand All @@ -27,3 +27,8 @@ def test_associate_flux_env(self):
)
self.assertEqual(model.reactions.get_by_id("EX_glc__D_e").bounds, (-10.0, 10.0))
self.assertEqual(model.reactions.get_by_id("EX_o2_e").bounds, (-5.0, 5.0))

def test_format(self):
medium_csv = load_medium(self.medium_butanol_csv)
medium_tsv = load_medium(self.medium_butanol_tsv)
self.assertEqual(medium_csv, medium_tsv)
6 changes: 3 additions & 3 deletions tests/test_software.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_software_butanol(self):
args += ["--output-file-csv", fd.name]
args += ["--strategy", "ko"]
args += ["--max-knockouts", "3"]
args += ["--input-medium-file", self.medium_butanol]
args += ["--input-medium-file", self.medium_butanol_csv]
args += ["--thread", "1"]

ret = Test_software.launch(args)
Expand All @@ -56,7 +56,7 @@ def test_software_butanol_light(self):
args += ["--output-file-csv", fd.name]
args += ["--strategy", "ko"]
args += ["--max-knockouts", "3"]
args += ["--input-medium-file", self.medium_butanol]
args += ["--input-medium-file", self.medium_butanol_tsv]
args += ["--thread", "1"]

ret = Test_software.launch(args)
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_software_butanol_iml1515(self):
args += ["--output-file-tsv", fd.name]
args += ["--strategy", "ko"]
args += ["--max-knockouts", "3"]
args += ["--input-medium-file", self.medium_butanol]
args += ["--input-medium-file", self.medium_butanol_csv]
args += ["--thread", "1"]

ret = Test_software.launch(args)
Expand Down

0 comments on commit a0f58d8

Please sign in to comment.