lcmodel-wrapper 0.5.1__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/PKG-INFO +1 -1
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper/_version.py +1 -1
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper/control.py +21 -13
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper/core.py +5 -3
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper.egg-info/PKG-INFO +1 -1
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/tests/test_control.py +18 -2
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/tests/test_lcm.py +2 -1
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/LICENSE +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/LICENSE.lcmodel +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/MANIFEST.in +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/NOTICE +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/README.md +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper/__init__.py +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper/basis.py +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper/binaries.py +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper/container.py +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper/convert.py +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper/coord.py +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper/io.py +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper.egg-info/SOURCES.txt +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper.egg-info/dependency_links.txt +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper.egg-info/requires.txt +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper.egg-info/top_level.txt +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/pyproject.toml +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/setup.cfg +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/tests/test_binaries.py +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/tests/test_convert.py +0 -0
- {lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/tests/test_io.py +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
# Single source of truth for the package version. pyproject.toml reads it at build time,
|
|
2
2
|
# and binaries.py derives the GitHub release / container image tag ("v<version>") from
|
|
3
3
|
# it, so every wheel pairs with the LCModel artifacts built alongside it.
|
|
4
|
-
__version__ = "0.
|
|
4
|
+
__version__ = "0.6.0"
|
|
@@ -13,32 +13,39 @@
|
|
|
13
13
|
####################################################################################################
|
|
14
14
|
|
|
15
15
|
import os
|
|
16
|
-
from typing import List, Tuple
|
|
16
|
+
from typing import List, Optional, Tuple
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
# the lipids, macromolecules and creatine CH2 correction LCModel simulates and adds to
|
|
20
|
+
# every basis set unless told otherwise (manual, Sec 11.7)
|
|
21
|
+
SIMULATED = ["Lip13a", "Lip13b", "Lip09", "Lip20",
|
|
22
|
+
"MM09", "MM12", "MM14", "MM17", "MM20",
|
|
23
|
+
"-CrCH2", "CrCH2"]
|
|
22
24
|
|
|
23
25
|
|
|
24
26
|
#********************#
|
|
25
27
|
# ignore presets #
|
|
26
28
|
#********************#
|
|
27
|
-
def resolve_ignore(ignore) -> List[str]:
|
|
29
|
+
def resolve_ignore(ignore) -> Optional[List[str]]:
|
|
30
|
+
"""None leaves the omitted metabolites to LCModel, or to the control file given."""
|
|
31
|
+
if ignore is None:
|
|
32
|
+
return None
|
|
28
33
|
if isinstance(ignore, str):
|
|
29
|
-
if ignore.lower() == "
|
|
30
|
-
return list(
|
|
34
|
+
if ignore.lower() == "simulated":
|
|
35
|
+
return list(SIMULATED)
|
|
31
36
|
if ignore.lower() == "none":
|
|
32
37
|
return []
|
|
33
38
|
raise ValueError(
|
|
34
|
-
"Unknown ignore preset. Use '
|
|
39
|
+
"Unknown ignore preset. Use 'simulated', 'none', or a list of metabolite names."
|
|
35
40
|
)
|
|
36
41
|
if isinstance(ignore, (list, tuple)):
|
|
37
42
|
return list(ignore)
|
|
38
43
|
raise ValueError("ignore must be a list of metabolite names or a preset string.")
|
|
39
44
|
|
|
40
45
|
|
|
41
|
-
def _omit_lines(ignore: List[str]) -> List[str]:
|
|
46
|
+
def _omit_lines(ignore: Optional[List[str]]) -> List[str]:
|
|
47
|
+
if ignore is None:
|
|
48
|
+
return []
|
|
42
49
|
return [f"nomit={len(ignore)}"] + [f"chomit({i + 1})='{m}'" for i, m in enumerate(ignore)]
|
|
43
50
|
|
|
44
51
|
|
|
@@ -46,7 +53,7 @@ def _omit_lines(ignore: List[str]) -> List[str]:
|
|
|
46
53
|
# build a control set #
|
|
47
54
|
#*************************#
|
|
48
55
|
def build_control(path2basis: str, n_points: int, bandwidth: float, central_freq: float,
|
|
49
|
-
ppmlim: Tuple[float, float] = (0.5, 4.2), ignore=
|
|
56
|
+
ppmlim: Tuple[float, float] = (0.5, 4.2), ignore=None,
|
|
50
57
|
dows: bool = False) -> List[str]:
|
|
51
58
|
"""Create a default LCModel control file as a list of lines."""
|
|
52
59
|
return [
|
|
@@ -74,12 +81,13 @@ def build_control(path2basis: str, n_points: int, bandwidth: float, central_freq
|
|
|
74
81
|
# load + override file #
|
|
75
82
|
#**************************#
|
|
76
83
|
def load_control(control_path: str, path2basis: str, ppmlim: Tuple[float, float],
|
|
77
|
-
ignore=
|
|
78
|
-
"""Read an existing control file and override basis, ppm limits and
|
|
84
|
+
ignore=None) -> List[str]:
|
|
85
|
+
"""Read an existing control file and override basis, ppm limits and, when given,
|
|
86
|
+
ignored metabolites."""
|
|
79
87
|
ignore = resolve_ignore(ignore)
|
|
80
88
|
with open(control_path, "r") as fh:
|
|
81
89
|
control = [line for line in fh.read().splitlines()
|
|
82
|
-
if not line.startswith(("chomit(", "nomit="))]
|
|
90
|
+
if ignore is None or not line.startswith(("chomit(", "nomit="))]
|
|
83
91
|
|
|
84
92
|
set_key(control, "filbas", f"'{os.path.abspath(path2basis)}'")
|
|
85
93
|
set_key(control, "ppmst", ppmlim[1])
|
|
@@ -76,8 +76,10 @@ class PyLCModel:
|
|
|
76
76
|
Analysis window (ppmend, ppmst).
|
|
77
77
|
conj : bool
|
|
78
78
|
Conjugate the FIDs before fitting (convention dependent).
|
|
79
|
-
ignore : str | list
|
|
80
|
-
|
|
79
|
+
ignore : str | list, optional
|
|
80
|
+
Metabolites to omit: a list of names, "none", or "simulated" for LCModel's
|
|
81
|
+
simulated lipids, macromolecules and creatine CH2 correction. By default
|
|
82
|
+
(None) LCModel's own choice, or the control file's.
|
|
81
83
|
save_path : str, optional
|
|
82
84
|
Directory to keep intermediate files (otherwise a temporary one is used).
|
|
83
85
|
path2exec : str, optional
|
|
@@ -112,7 +114,7 @@ class PyLCModel:
|
|
|
112
114
|
"""
|
|
113
115
|
|
|
114
116
|
def __init__(self, path2basis, control=None, multiprocessing=False, ppmlim=(0.5, 4.2),
|
|
115
|
-
conj=True, ignore=
|
|
117
|
+
conj=True, ignore=None, save_path="", path2exec=None,
|
|
116
118
|
domain="time", sample_points=None, bandwidth=None, central_freq=None,
|
|
117
119
|
allow_download=True, allow_docker=True, allow_build=True,
|
|
118
120
|
convert_basis=False, basis_format=None, timeout=900, io_timeout=10,
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
####################################################################################################
|
|
4
4
|
# #
|
|
5
5
|
# Purpose: Extra control parameters: written in LCModel's namelist syntax, and kept whichever #
|
|
6
|
-
# way the control is made, including when it is rebuilt once the data is known.
|
|
6
|
+
# way the control is made, including when it is rebuilt once the data is known. Omitted #
|
|
7
|
+
# metabolites are LCModel's or the control file's own unless given. #
|
|
7
8
|
# #
|
|
8
9
|
####################################################################################################
|
|
9
10
|
|
|
@@ -16,7 +17,7 @@ import pytest
|
|
|
16
17
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
|
|
17
18
|
|
|
18
19
|
from lcmodel_wrapper import PyLCModel, binaries
|
|
19
|
-
from lcmodel_wrapper.control import build_control, set_params
|
|
20
|
+
from lcmodel_wrapper.control import build_control, load_control, set_params
|
|
20
21
|
|
|
21
22
|
_BASIS = (Path(__file__).resolve().parent.parent / "example_data" / "2016_fitting_challenge"
|
|
22
23
|
/ "basisset_LCModel" / "press3T_30ms.BASIS")
|
|
@@ -34,6 +35,21 @@ def test_params_are_written_as_the_namelist_expects():
|
|
|
34
35
|
assert control[-1] == "$END"
|
|
35
36
|
|
|
36
37
|
|
|
38
|
+
#**************#
|
|
39
|
+
# omitting #
|
|
40
|
+
#**************#
|
|
41
|
+
def test_lcmodel_chooses_what_to_omit_unless_told(tmp_path):
|
|
42
|
+
built = build_control("x.basis", 2048, 4000.0, 123.2)
|
|
43
|
+
assert not any(line.startswith(("nomit", "chomit")) for line in built)
|
|
44
|
+
assert "chomit(1)='Lip13a'" in build_control("x.basis", 2048, 4000.0, 123.2,
|
|
45
|
+
ignore="simulated")
|
|
46
|
+
|
|
47
|
+
study = tmp_path / "study.control"
|
|
48
|
+
study.write_text("$LCMODL\nnomit=1\nchomit(1)='Lac'\n$END\n")
|
|
49
|
+
assert "chomit(1)='Lac'" in load_control(str(study), "x.basis", (0.5, 4.2))
|
|
50
|
+
assert "nomit=0" in load_control(str(study), "x.basis", (0.5, 4.2), ignore="none")
|
|
51
|
+
|
|
52
|
+
|
|
37
53
|
#*************#
|
|
38
54
|
# rebuilt #
|
|
39
55
|
#*************#
|
|
@@ -60,7 +60,8 @@ def challenge_mae(test_size: int = 5) -> float:
|
|
|
60
60
|
basis = _CHALLENGE / "basisset_LCModel" / "press3T_30ms.BASIS"
|
|
61
61
|
data_dir = _CHALLENGE / "datasets_JMRUI"
|
|
62
62
|
|
|
63
|
-
lcm = PyLCModel(path2basis=str(basis), sample_points=2048, domain="time"
|
|
63
|
+
lcm = PyLCModel(path2basis=str(basis), sample_points=2048, domain="time",
|
|
64
|
+
ignore="simulated")
|
|
64
65
|
n_metabs = lcm.basis.n_metabs
|
|
65
66
|
|
|
66
67
|
# pair ground truths with challenge datasets by dataset number
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{lcmodel_wrapper-0.5.1 → lcmodel_wrapper-0.6.0}/lcmodel_wrapper.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|