hydroflows.workflow.Workflow#

class hydroflows.workflow.Workflow(name='hydroflows', config: Dict | WorkflowConfig | None = None, wildcards: Dict | None = None, root: Path | None = None)[source]#

Bases: object

Create a workflow instance.

Parameters:
  • config (Dict, optional) – The configuration of the workflow, by default None.

  • wildcards (Dict, optional) – The wildcard keys and values of the workflow, by default None.

Methods

create_rule

Create a rule based on a method.

create_rule_from_kwargs

Add a rule for method 'name' with keyword-arguments 'kwargs'.

dryrun

Dryrun the workflow.

from_yaml

Load a workflow from a yaml file.

get_ref

Get a cross-reference to previously set rule parameters or workflow config.

plot_rulegraph

Plot the rulegraph.

run

Run the workflow.

to_cwl

Save the workflow to a CWL workflow.

to_snakemake

Save the workflow to a snakemake workflow.

to_yaml

Save the workflow to a yaml file.

Attributes

root

Get the root of the workflow.

property root: Path#

Get the root of the workflow.

create_rule(method: Method, rule_id: str | None = None) Rule[source]#

Create a rule based on a method.

Parameters:
  • method (Method) – The method to create the rule from.

  • rule_id (str, optional) – The rule id, by default None.

create_rule_from_kwargs(method: str, kwargs: Dict[str, str], rule_id: str | None = None) None[source]#

Add a rule for method ‘name’ with keyword-arguments ‘kwargs’.

Parameters:
  • method (str) – The name of the method.

  • kwargs (Dict[str, str]) – The keyword arguments for the method.

  • rule_id (str, optional) – The rule id, by default None.

get_ref(ref: str) Ref[source]#

Get a cross-reference to previously set rule parameters or workflow config.

classmethod from_yaml(file: str) Workflow[source]#

Load a workflow from a yaml file.

to_snakemake(snakefile: str = 'Snakefile', dryrun: bool = False) None[source]#

Save the workflow to a snakemake workflow.

Parameters:
  • snakefile (Path) – The snakefile filename, by default “Snakefile”.

  • dryrun (bool, optional) – Run the workflow in dryrun mode, by default False.

to_cwl(cwlfile: Path = None, dryrun: bool = False, touch_inputs: bool = False) None[source]#

Save the workflow to a CWL workflow.

Parameters:
  • cwlfile (Path) – Path to the CWL workflow file. CWL files for individual methods will be created in the subfolder <cwlfile>/cwl.

  • dryrun (bool, optional) – Run the workflow in dryrun mode, by default False

to_yaml(file: str) None[source]#

Save the workflow to a yaml file.

run(max_workers=1) None[source]#

Run the workflow.

Parameters:
  • max_workers (int, optional) – The maximum number of workers, by default 1. Only used when dryrun is False.

  • missing_file_error (bool, optional) – Raise an error when a file is missing, by default False. This only works when dryrun is True.

dryrun(missing_file_error: bool = False) None[source]#

Dryrun the workflow.

Parameters:

missing_file_error (bool, optional) – Raise an error when a file is missing, by default False.

plot_rulegraph(filename: str | Path | None = 'rulegraph.svg', plot_rule_attrs=True) Digraph[source]#

Plot the rulegraph.

The rulegraph is a directed graph where the nodes are rules and the edges are dependencies.

The nodes are colored based on the type of rule: Expand rules are colored blue, reduce rules are colored green, and rules with repeat wildcards are colored purple. Result rules are colored red.

Parameters:
  • filename (str, optional) – The filename of the rulegraph, by default “rulegraph.svg”. The file is saved in the root directory of the workflow.

  • plot_rule_attrs (bool, optional) – Plot the rule attributes (n runs and wildcards) in the node, by default True.

Returns:

The graphviz Digraph object.

Return type:

graphviz.Digraph