cwltoo学习笔记

执行工作流:cwltool /home/zcy/download/cwl/wf.cwl /home/zcy/download/cwl/echo-job.yml 
from ruamel.yaml import YAML
import json
def parse_cwl_file(file_path):
    with open(file_path, 'r') as file:
        yaml = YAML(typ='safe', pure=True)
        cwl_data = yaml.load(file)
    return cwl_data

cwl_file_path = 'echo.cwl'
cwl_data = parse_cwl_file(cwl_file_path)
print(json.dumps(cwl_data))

print(cwl_data['inputs'])

print(type(cwl_data['inputs']))

 


wf.cwl
cwlVersion: v1.2
class: Workflow


inputs:
  message: string

outputs:
  out:
    type: File
    outputSource: uppercase/example_out

steps:
  echo:
    run: /home/zcy/download/cwl/zzz_print.cwl
    in:
      message: message
    out: [out]
  uppercase:
    run: /home/zcy/download/cwl/ccc.cwl
    in:
      mypath:
        source: echo/out
    out: [example_out]

echo-job.yml

message: Hello world!

zzz_print.cwl

cwlVersion: v1.0
class: CommandLineTool
stdout: tst_stdout.txt
baseCommand: [python, /home/zcy/download/cwl/input/zzz_print.py]
inputs:
  message:
    type: string
    inputBinding:
      position: 1
outputs:
  out:
    type: string
    outputBinding:
      glob: tst_stdout.txt 
      loadContents: true
      outputEval: $(self[0].contents)

zzz_print.py

import argparse
parser = argparse.ArgumentParser(description='download files by ftp')
parser.add_argument('message', type=str, help='PDB')

def tst(args):
    with open('/home/zzz_print.out', 'w') as f:
      f.write(args)
    print('/home/zzz_print.out')

if __name__ == '__main__':
    args = parser.parse_args()
    tst(args.message)
 

 

ccc.cwl

cwlVersion: v1.0
class: CommandLineTool
baseCommand: [python, /home/zcy/download/cwl/input/ccc.py]
inputs:
  mypath:
    type: string
    inputBinding:
      position: 1
outputs:
  example_out:
    type: stdout
stdout: output_ccc.txt
ccc.py
import argparse
parser = argparse.ArgumentParser(description='download files by ftp')
parser.add_argument('mypath', type=str, help='PDB')

def tst(args):
    fpath = args.split(None)[0]
    with open(fpath, 'r') as f:
      data = f.read()
    print('final result:')
    print(data)

if __name__ == '__main__':
    args = parser.parse_args()
    tst(args.mypath)

 

posted on 2023-08-22 15:46  我和你并没有不同  阅读(10)  评论(0编辑  收藏  举报