phylojunction.interface.cmdbox package
Submodules
phylojunction.interface.cmdbox.cmd_parse module
- phylojunction.interface.cmdbox.cmd_parse.cmdline2dag(dag_obj: DirectedAcyclicGraph, cmd_line: str) str
Update PGM object with user-entered .pj command.
- Parameters:
dag_obj (DirectedAcyclicGraph) – DAG object that will hold all stochastic nodes (random variables) created by user via commands.
cmd_line (str) – Command line string provided by user through static script or via GUI.
- Returns:
Command string if there was nothing wrong with it.
- Return type:
(str)
- phylojunction.interface.cmdbox.cmd_parse.parse_deterministic_function_assignment(dag_obj: DirectedAcyclicGraph, det_nd_name: str, det_node_fn_spec: str, cmd_line: str) None
Create DeterministicNodeDAG instance from command string with ‘:=’ operator, then add it to ProbabilisticGraphiclModel instance. This node is not sampled (not a random variable) and is deterministically initialized via a deterministic function call.
- Parameters:
dag_obj (DirectedAcyclicGraph) – DAG object that will hold all nodes created by user via commands.
det_nd_name (str) – Name of deterministic node being created
det_node_fn_spec (str) – Specification string for deterministic function that will specify the deterministic node (whatever is right of ‘:=’ operator in PJ command).
cmd_line (str) – Command line string provided by user through static script or via GUI.
- phylojunction.interface.cmdbox.cmd_parse.parse_samp_dn_assignment(dag_obj: DirectedAcyclicGraph, stoch_node_name: str, stoch_node_dn_spec: str, cmd_line: str) None
Create and add stochastic node to graphical model.
Called when ‘~’ operator is used. This node will be sampled from distribution and is a random variable.
- Parameters:
dag_obj (DirectedAcyclicGraph) – Object that will hold all nodes created by user via commands.
stoch_node_name (str) – Name of stochastic node being created
stoch_node_dn_spec (str) – Specification string for distribution from which stochastic node will be sampled (whatever is right of ‘~’ operator in PJ command)
cmd_line (str) – Command line string provided by user through static script or via GUI
- phylojunction.interface.cmdbox.cmd_parse.parse_variable_assignment(dag_obj: DirectedAcyclicGraph, stoch_node_name: str, stoch_node_spec: str, cmd_line: str) None
Create and add constant node to DAG.
Called when ‘<-’ operator is used. This node will not be sampled and is in practice a constant node.
- Parameters:
dag_obj (DirectedAcyclicGraph) – Object that will hold all nodes created by user via commands.
stoch_node_name (str) – Name of stochastic node being created.
stoch_node_spec (str) – Stochastic node specification string (whatever is right of ‘<-’ operator in PJ command).
cmd_line (str) – Command line string provided by user through static script or via GUI.
- phylojunction.interface.cmdbox.cmd_parse.script2dag(script_file_path_or_model_spec: str, in_pj_file: bool = True, random_seed: int | None = None) DirectedAcyclicGraph
Go through .pj lines and populate and return DAG.
- Parameters:
script_file_path_or_model_spec (str) – Path to script .pj file or full string specifying model directly.
random_seed (int) – Random seed (integer) for simulation. Defaults to None.
- Returns:
- DAG object (model) built from .pj
script commands.
- Return type:
phylojunction.interface.cmdbox.cmd_parse_utils module
- phylojunction.interface.cmdbox.cmd_parse_utils.parse_spec(dag_obj: DirectedAcyclicGraph, fn_spec_str: str, cmd_line: str) Tuple[Dict[str, List[NodeDAG | str]], List[NodeDAG]]
- phylojunction.interface.cmdbox.cmd_parse_utils.parse_val_vector(vec_str: str) List[str]
Parse string specifying vector when a variable is assigned
- Parameters:
vec_str (str) – A string specifying a vector, e.g., “[1, 2, 3]”
- Raises:
ec.ScriptSyntaxError – If there are more than two squared brackets, this is thrown
- Returns:
- Vector of strings, each being one of the values inside
the vector being specified by ‘vec_str’.
- Return type:
(str)
- phylojunction.interface.cmdbox.cmd_parse_utils.tokenize_fn_spec(fn_spec_str: str, cmd_line: str) Dict[str, str]
Tokenize string containing function specification into dictionary
- Parameters:
fn_spec (str) – String containing the specification of function (i.e., what appears between ‘(’ and ‘)’.
- Returns:
- Dictionary containing function parameter strings as
keys, argument strings as values (e.g., {“mean”: “0.0”}).
- Return type:
(dict)
- phylojunction.interface.cmdbox.cmd_parse_utils.val_or_obj(dag_obj: DirectedAcyclicGraph, val: List[str]) List[NodeDAG | str]
Return list of strings with values or node names.
Checks if provided values are directly accessible as values (e.g., 1.0, “a_string_in_quotes”)) or if they are names of nodes potentially in the graphical model. If the latter, check if they are indeed nodes in the graphical model, and if so, append to return
- Parameters:
dag_obj (DirectedAcyclicGraph) – DAG object being interrogated.
val (str) – List of strings, one for each argument coming from a parsed command.
- Raises:
ec.InexistentVariableError – _description_
- Returns:
- List of strings (representing values or quoted-enclosed
strings) and/or stochastic node objects.
- Return type:
(str)