Param#
- class pyopenms.Param#
Bases:
objectManagement and storage of parameters / INI files. This class provides a means to associate string names to int/double/string/StringList values. It allows for parameter hierarchies and to save/load the data as XML. Hierarchy levels are separated from each other by colons (e.g., ‘algorithm:common:threshold’). Each parameter and section has a description. Newline characters in the description are possible. Each parameter can be annotated with an arbitrary number of tags (e.g., ‘advanced’).
- __init__() None#
- __init__(arg: pyopenms.Param, /) None
- __init__(d: dict) None
Overloaded function.
__init__() -> None__init__(arg: pyopenms.Param, /) -> None__init__(d: dict) -> None
Create a Param from a {key: value} dict, e.g. Param({‘algorithm:threshold’: 0.5}). Equivalent to Param.from_dict(d); this is also what repr(param) evaluates to
Methods
__init__()Overloaded function.
addSection(key, description)Adds a parameter section with the given key and description
addTag(key, tag)Adds a tag to the entry specified by key (e.g., 'advanced', 'required', 'input file')
addTags(key, tags)Adds multiple tags to the entry specified by key
asDict()Return dict with str keys
checkDefaults(name, defaults[, prefix])Checks current parameter entries against given defaults.
clear()Deletes all entries
clearTags(key)Removes all tags from the entry specified by key
copy(prefix[, remove_prefix])Returns a new Param containing all entries that start with the given prefix.
empty()Returns True if there are no entries
exists(key)Returns True if the parameter exists, False otherwise
from_dict(d)Create a Param from a {key: value} dict (same as Param(d))
get(key[, default_])Get a parameter value by key, returning default if not found
getDescription(key)Returns the description of the parameter specified by key
getEntry(key)Returns a copy of the whole parameter entry (value, description, tags, restrictions).
Returns the description of the section specified by key (empty string if not found)
getTags(key)Returns the tags of the entry specified by key
getValidStrings(key)Returns the list of valid string values for the parameter.
getValue(key)Returns the value of the parameter specified by key.
getValueType(key)Returns the type of the parameter specified by key.
hasTag(key, tag)Returns True if the parameter has the specified tag
insert(prefix, param)Inserts all values of another Param object with the given prefix
isBool(key)True if the parameter is a boolean parameter: a scalar string restricted to exactly 'true' and 'false' (either order), independent of the current value.
items()Return list of (key, value) tuples
keys()Return list of parameter keys as str
merge(toMerge)Adds missing parameters from another Param object without modifying existing ones
remove(key)Removes an entry or section (when key ends with ':') by exact name match
removeAll(prefix)Removes all entries and sections that start with the given prefix
setDefaults(defaults[, prefix, showMessage])Inserts all values from defaults that are not already set.
setMaxFloat(key, max)Sets the maximum allowed value for a float parameter
setMaxInt(key, max)Sets the maximum allowed value for an integer parameter
setMinFloat(key, min)Sets the minimum allowed value for a float parameter
setMinInt(key, min)Sets the minimum allowed value for an integer parameter
setSectionDescription(key, description)Sets a description for an existing section (not for values)
setValidStrings(key, strings)Sets the list of valid string values for the parameter (checked by checkDefaults)
setValue(key, value[, description, tags])Overloaded function.
size()Returns the number of parameter entries (leaves)
to_dict()Return dict with string keys
update(source[, flag])Update parameters from a Param or dict.
values()Return list of parameter values
- addSection(key: str, description: str) None#
Adds a parameter section with the given key and description
- addTag(key: str, tag: str) None#
Adds a tag to the entry specified by key (e.g., ‘advanced’, ‘required’, ‘input file’)
- addTags(key: str, tags: list[str]) None#
Adds multiple tags to the entry specified by key
- asDict() dict#
Return dict with str keys
- checkDefaults(name: str, defaults: pyopenms.Param, prefix: str = '') None#
Checks current parameter entries against given defaults. Validates types, string restrictions, and numeric ranges. Raises exception on invalid parameters
- clear() None#
Deletes all entries
- clearTags(key: str) None#
Removes all tags from the entry specified by key
- copy(prefix: str, remove_prefix: bool = False) pyopenms.Param#
Returns a new Param containing all entries that start with the given prefix. If remove_prefix is True, the prefix is removed from the keys in the returned Param
- empty() bool#
Returns True if there are no entries
- exists(key: str) bool#
Returns True if the parameter exists, False otherwise
- static from_dict(d: dict) pyopenms.Param#
Create a Param from a {key: value} dict (same as Param(d))
- get(key: str, default_: object | None = None) object#
Get a parameter value by key, returning default if not found
- getDescription(key: str) str#
Returns the description of the parameter specified by key
- getEntry(key: str) pyopenms.ParamEntry#
Returns a copy of the whole parameter entry (value, description, tags, restrictions). Raises exception if not found
- getSectionDescription(key: str) str#
Returns the description of the section specified by key (empty string if not found)
- getTags(key: str) list[str]#
Returns the tags of the entry specified by key
- getValidStrings(key: str) list[str]#
Returns the list of valid string values for the parameter. Raises TypeError for a boolean parameter, which has no string restrictions from Python
- getValue(key: str) bool | None | int | float | str | list[str] | list[int] | list[float]#
Returns the value of the parameter specified by key. Raises exception if not found. A boolean parameter (see isBool) is returned as a Python bool
- getValueType(key: str) pyopenms.ValueType#
Returns the type of the parameter specified by key. Raises exception if not found. Note that a boolean parameter is stored as a string and reports STRING_VALUE; use isBool() to detect one
- hasTag(key: str, tag: str) bool#
Returns True if the parameter has the specified tag
- insert(prefix: str, param: pyopenms.Param) None#
Inserts all values of another Param object with the given prefix
- isBool(key: str) bool#
True if the parameter is a boolean parameter: a scalar string restricted to exactly ‘true’ and ‘false’ (either order), independent of the current value. Such a parameter reads and writes as a Python bool
- items() list#
Return list of (key, value) tuples
- keys() list#
Return list of parameter keys as str
- merge(toMerge: pyopenms.Param) None#
Adds missing parameters from another Param object without modifying existing ones
- remove(key: str) None#
Removes an entry or section (when key ends with ‘:’) by exact name match
- removeAll(prefix: str) None#
Removes all entries and sections that start with the given prefix
- setDefaults(defaults: pyopenms.Param, prefix: str = '', showMessage: bool = False) None#
Inserts all values from defaults that are not already set. Optionally adds a prefix to all keys and prints a message for each default value set
- setMaxFloat(key: str, max: float) None#
Sets the maximum allowed value for a float parameter
- setMaxInt(key: str, max: int) None#
Sets the maximum allowed value for an integer parameter
- setMinFloat(key: str, min: float) None#
Sets the minimum allowed value for a float parameter
- setMinInt(key: str, min: int) None#
Sets the minimum allowed value for an integer parameter
- setSectionDescription(key: str, description: str) None#
Sets a description for an existing section (not for values)
- setValidStrings(key: str, strings: list[str]) None#
Sets the list of valid string values for the parameter (checked by checkDefaults)
- setValue(key: str, value: bool | None | int | float | str | bytes | list[str] | list[int] | list[float], description: str = '', tags: list[str] | None = None) None#
- setValue(key: str, value: bool | None | int | float | str | bytes | list[str] | list[int] | list[float], description: str = '') None
- setValue(key: str, value: bool | None | int | float | str | bytes | list[str] | list[int] | list[float]) None
Overloaded function.
setValue(key: str, value: bool | None | int | float | str | bytes | list[str] | list[int] | list[float], description: str = '', tags: list[str] | None = None) -> None
Sets a value with description and tags. A bool defines a boolean parameter for a new key and sets an existing boolean one. Without tags an existing key keeps its tags
setValue(key: str, value: bool | None | int | float | str | bytes | list[str] | list[int] | list[float], description: str = '') -> None
Sets a value with description
setValue(key: str, value: bool | None | int | float | str | bytes | list[str] | list[int] | list[float]) -> None
Set a value for a key
- size() int#
Returns the number of parameter entries (leaves)
- to_dict() dict#
Return dict with string keys
- update(source: object, flag: object | None = None) None#
Update parameters from a Param or dict. With a truthy flag only keys that already exist here are updated
- values() list#
Return list of parameter values