Skip to content

Commit

Permalink
Merge pull request #38 from MolecularBioinformatics/feature/mat-cli
Browse files Browse the repository at this point in the history
adding .mat file support to CLI
  • Loading branch information
sauter-roland authored Apr 1, 2024
2 parents 0655c7d + b8d5382 commit d00536d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 45 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "gemcat"
version = "1.1.0"
version = "1.2.0"

description = "A toolbox for gene expression-based prediction of metabolic alterations"
keywords = ["python", "bioinformatics", "modeling", "metabolites", "omics"]
Expand Down
4 changes: 2 additions & 2 deletions src/gemcat/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import cobra
from pandas import DataFrame, Series, read_csv

from .io import load_json_cobra, load_sbml_cobra
from .io import load_json_cobra, load_mat_cobra, load_sbml_cobra
from .workflows import workflow_standard


Expand All @@ -33,7 +33,7 @@ def not_implemented(whatever: Any):
"xml": load_sbml_cobra,
"json": load_json_cobra,
"csv": not_implemented,
"mat": not_implemented,
"mat": load_mat_cobra,
}


Expand Down
20 changes: 13 additions & 7 deletions src/gemcat/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ def load_json_cobra(json_file: Union[str, Path]) -> cobra.Model:
:return: Model object created from the COBRA model
:rtype: Model
"""
if isinstance(json_file, Path):
json_file = json_file.as_posix()
cobra_model = cobra.io.load_json_model(json_file)

cobra_model = cobra.io.load_json_model(str(json_file))
return cobra_model


Expand All @@ -56,10 +53,19 @@ def load_sbml_cobra(sbml_file: Union[str, Path]) -> cobra.Model:
:return: Model object created from the COBRA model
:rtype: Model
"""
if isinstance(sbml_file, Path):
sbml_file = sbml_file.as_posix()
cobra_model = cobra.io.read_sbml_model(sbml_file)
cobra_model = cobra.io.read_sbml_model(str(sbml_file))
return cobra_model


def load_mat_cobra(mat_file: Union[str, Path]) -> cobra.Model:
"""
Loads a Pagerank-based Model from a COBRA SBML file.
:param mat_file: Path to json SBML file
:type mat_file: Union[str, Path]
:return: COBRA model object
:rtype: Model
"""
cobra_model = cobra.io.load_matlab_model(str(mat_file))
return cobra_model


Expand Down
56 changes: 21 additions & 35 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,45 +81,31 @@ def test_cli_293_xml():


@pytest.mark.slow
def test_cli_paper_uc_ns():
args = MockNamespace(
expressionfile=str(expression_path / "prot_uc_vs_healthy.csv"),
expressioncolumn="foldchange",
baseline=str(expression_path / "prot_uc_vs_healthy.csv"),
baselinecolumn="base",
genefill=None,
modelfile=str(model_path / "Recon3D.json"),
outfile="./temp_outfile.csv",
)
result, outfile = cli.cli_standard(args)
assert isinstance(result, Series)
assert len(result) > 1000
assert outfile.stem == "temp_outfile"
assert outfile.suffix == ".csv"
expected = read_csv(results_path / "uc.csv", sep=",", index_col=0).iloc[:, 0]
assert allclose(expected.values, result.values, atol=0.3)


@pytest.mark.slow
def test_cli_paper_uc_wf():
args = MockNamespace(
expressionfile=str(expression_path / "prot_uc_vs_healthy.csv"),
expressioncolumn="foldchange",
baseline=str(expression_path / "prot_uc_vs_healthy.csv"),
baselinecolumn="base",
genefill=None,
modelfile=str(model_path / "Recon3D.json"),
outfile="./temp_outfile.csv",
def test_cli_293_mat():
out_file = Path("./temp_outfile.csv")
run(
[
"gemcat",
str(model_path / "Recon3D_301.mat"),
str(expression_path / "prot_uc_vs_healthy.csv"),
"-e",
"foldchange",
"-o",
str(out_file),
"-g",
"1.0",
],
shell=False,
)
result, _ = cli.cli_standard(args)
assert isinstance(result, Series)
assert len(result) > 1000
expected = read_csv(results_path / "uc.csv", sep=",", index_col=0).iloc[:, 0]
assert allclose(expected.values, result.values, atol=0.3)
assert out_file.is_file()
received = read_csv(out_file, sep=",", index_col=0).iloc[:, 0]
out_file.unlink()
assert len(received > 1000)
assert received.isna().sum() == 0


@pytest.mark.slow
def test_cli_paper_uc_term():
def test_cli_uc_json():
out_file = Path("./temp_outfile.csv")
run(
[
Expand Down

0 comments on commit d00536d

Please sign in to comment.