Lightweight python module to load, validate and visualize CWL (Common Workflow Language) files through networkx graphs.
Project description
CWL2Nx
Lightweight python module to load, validate and visualize CWL (Common Workflow Language) files through networkx graphs. It uses cwl_utils for parsing and validation.
Installation
pip install cwl2nx
Example Usage
You will find an example of workflow in the GitHub repository : workflow_example.cwl.yaml. Other examples can be found here : https://workflowhub.org
Straightforward conversion
from cwl2nx import CWLToNetworkxConnector
dir = "workflow_example.cwl.yaml"
dag = CWLToNetworkxConnector(dir).convert_to_networkx() # dag is networkx.DiGraph
print(dag.nodes, dag.edges)
Using dagviz
You'll need to install
dagvizbefore
/!\ you need to run the code below in a jupyter notebook
from cwl2nx import CWLToNetworkxConnector
import networkx as nx
import dagviz
dir = "workflow_example.cwl.yaml"
connector = CWLToNetworkxConnector(dir)
dag = connector.convert_to_networkx()
dagviz.Dagre(dag)
dagviz.Metro(dag) # github tree dag style
Visualization in the terminal
To get a light visualization of the workflow in the terminal, just use the code from this GitHub repo https://github.com/ctongfei/py-dagviz/blob/main/dagviz.py and import visualize_dag function :
from cwl2nx import CWLToNetworkxConnector
import networkx as nx
dir = "workflow_example.cwl.yaml"
dag = CWLToNetworkxConnector(dir).convert_to_networkx(datasets_as_node=True)
print(visualization_function(dag))
output :
• #nsbas.proc
│ • #nsbas_config.json
│ │ • #parameter.py
╰─┴─│─• #tache_init
│ ╰─• ivwgayim.dep
╰───┼─• #tache_inter1
╰─│─• #tache_inter2
│ ╰─• azbouvks2.dep
╰───│─• azbouvks1.dep
╰─┴─• #tache_end
╰─• agxlvirt.dep
Basic networkx display
from cwl2nx import CWLToNetworkxConnector
import networkx as nx
import matplotlib.pyplot as plt
dir = "workflow_example.cwl.yaml"
connector = CWLToNetworkxConnector(dir)
dag = connector.convert_to_networkx(datasets_as_nodes=True)
nx.draw_networkx(dag)
plt.show()
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file cwl2nx-0.0.7.tar.gz.
File metadata
- Download URL: cwl2nx-0.0.7.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc673b8f639fb5f76eb6e2c18bf0fb22fa1aabfab871e9183988181653a5a7fe
|
|
| MD5 |
6d7bde19b78d1c7b20960611ccd88ad9
|
|
| BLAKE2b-256 |
39b36324491e20727a0f9c15b7636b920dcae4cd2e6bb0c0d22ed539a1a2dff4
|