Skip to content

Commit

Permalink
Update config template and validations
Browse files Browse the repository at this point in the history
change config bigscape.cutoff from float to string

transform config `root_dir` to full path.
  • Loading branch information
CunliangGeng authored Mar 1, 2024
1 parent 22984c3 commit 26bd85b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/nplinker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from dynaconf import Dynaconf
from dynaconf import Validator
from nplinker.utils import transform_to_full_path


# The Dynaconf library is used for loading NPLinker config file.
Expand All @@ -10,6 +11,7 @@
# directory.
# The loaded config data is available by importing this module and accessing the 'config' variable.

__all__ = ["config"]

# Locate the user's config file
user_config_file = os.environ.get("NPLINKER_CONFIG_FILE", "nplinker.toml")
Expand All @@ -29,7 +31,9 @@
validators = [
# General settings
## `root_dir` value is transformed to a `pathlib.Path` object and must be a directory.
Validator("root_dir", required=True, cast=Path, condition=lambda v: v.is_dir()),
Validator(
"root_dir", required=True, cast=transform_to_full_path, condition=lambda v: v.is_dir()
),
Validator("mode", required=True, cast=lambda v: v.lower(), is_in=["local", "podp"]),
## `podp_id` must be set if `mode` is "podp"; must not be set if `mode` is "local".
Validator("podp_id", required=True, when=Validator("mode", eq="podp")),
Expand All @@ -55,7 +59,7 @@
),
# BigScape
Validator("bigscape.parameters", required=True, is_type_of=str),
Validator("bigscape.cutoff", required=True, is_type_of=float),
Validator("bigscape.cutoff", required=True, is_type_of=str),
# Scoring
## `scoring.methods` must be a list of strings and must contain at least one of the
## supported scoring methods.
Expand Down
5 changes: 3 additions & 2 deletions src/nplinker/data/nplinker.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ version = "3.1"
parameters = "--mibig --clans-off --mix --include_singletons --cutoffs 0.30"
# Which bigscape cutoff to use for NPLinker analysis.
# There might be multiple cutoffs in bigscape output.
# The default value is 0.30.
cutoff = 0.30
# Note that this value must be a string.
# The default value is "0.30".
cutoff = "0.30"


[scoring]
Expand Down
2 changes: 1 addition & 1 deletion src/nplinker/nplinker_default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ version = "3.1"

[bigscape]
parameters = "--mibig --clans-off --mix --include_singletons --cutoffs 0.30"
cutoff = 0.30
cutoff = "0.30"

[scoring]
methods = ["metcalf"]
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ def test_config_demo1():
config.bigscape.parameters
== "--mibig --clans-off --mix --include_singletons --cutoffs 0.30"
)
assert config.bigscape.cutoff == 0.30
assert config.bigscape.cutoff == "0.30"

assert config.scoring.methods == ["metcalf"]

0 comments on commit 26bd85b

Please sign in to comment.