code: def dag_to_cwl(dag):
      """Convert a given DAG to a CWL workflow, which is returned as a JSON object."""
      snakemake_cwl = {
          "class": "CommandLineTool",
          "id": "#snakemake-job",
          "label": "Snakemake job executor",
          "hints": [
              {
                  "dockerPull": get_container_image(),
                  "class": "DockerRequirement",
              }
          ],
          "baseCommand": "snakemake",
          "requirements": {
              "ResourceRequirement": {"coresMin": "$(inputs.cores)"}
          },
          "arguments": [
              "--force",
              "--target-files-omit-workdir-adjustment",
              "--keep-remote",
              "--force-use-threads",
              "--wrapper-prefix",
              dag.workflow.workflow_settings.wrapper_prefix,
              "--notemp",
              "--quiet",
              "--use-conda",
              "--no-hooks",
              "--nolock",
              "--mode",
              str(ExecMode.SUBPROCESS.item_to_choice()),
          ],
          "inputs": {
              "snakefile": {
                  "type": "File",
                  "default": {
                      "class": "File",
                      "location": os.path.relpath(
                          dag.workflow.main_snakefile
                      ),
                  },
                  "inputBinding": {"prefix": "--snakefile"},
              },
              "sources": {
                  "type": "File[]",
                  "default": [
                      {"class": "File", "location": f}
                      for f in dag.get_sources()
                  ],
              },
              "cores": {
                  "type": "int",
                  "default": 1,
                  "inputBinding": {"prefix": "--cores"},
              },
              "rules": {
                  "type": "string[]?",
                  "inputBinding": {"prefix": "--allowed-rules"},
              },
              "input_files": {"type": "File[]", "default": []},
              "target_files": {
                  "type": "string[]?",
                  "inputBinding": {"position": 0},
              },
          },
          "outputs": {
              "output_files": {
                  "type": {"type": "array", "items": "File"},
                  "outputBinding": {"glob": "$(inputs.target_files)"},
              }
          },
      }
      groups = dag.get_jobs_or_groups()
      outputs = []
      inputs = []
  
      dag_cwl = [
          job_to_cwl(job, dag, outputs, inputs) for job in groups
      ]
  
      return {
          "cwlVersion": "v1.0",
          "$graph": [
              snakemake_cwl,
              {
                  "class": "Workflow",
                  "requirements": {
                      "InlineJavascriptRequirement": {},
                      "MultipleInputFeatureRequirement": {},
                  },
                  "steps": dag_cwl,
                  "inputs": inputs,
                  "outputs": outputs,
                  "id": "#main",
              },
          ],
      }
  
file_path: snakemake/snakemake/cwl.py
imports: from urllib.request import pathname2url
  import os
  import tempfile
  import json
  import shutil
  from itertools import chain
  from snakemake.utils import format
  from snakemake.exceptions import WorkflowError
  from snakemake.shell import shell
  from snakemake.common import get_container_image
  from snakemake_interface_executor_plugins.settings import ExecMode
label_desc: Use image node_id 3 for calling a global function with example usage: dag_to_cwl(dag) and returns: dict