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   我和你并没有不同  阅读(16)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-08-22 JavaScript 廖2
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示