LoginSignup
1
0

More than 3 years have passed since last update.

CWLのインプットにwildcard(glob)を使いたい

Last updated at Posted at 2020-12-22

背景

  • 2021/01/13 追記
  • 2021/03/08 コマンドライン上で実行する方法を追記

CWL(Common Workflow Language)で作られたスクリプトは、type: File[]とすることで複数ファイルを入力パラメータとして入力することが可能です。
ただし、*.txtのようにwildcard(glob)を入力とした実行は、CWLでは考えられておらずユーザー側で対処する必要があります。

解決策

1. 変数に配列として代入後、引数付きで変数展開する

手軽に実行するならこれが一番手っ取り早いです。

a=(fuga.*)
cwltool hoge.cwl ${a[@]/#/--infile }
# cwltool hoge.cwl --infile fuga.1 --infile fuga.2 --infile fuga.3 という形になる

2. yml形式に出力してymlで実行

以下のワンライナーを実行するか、関数にして使ってください

ls *.* | awk '{print "- class: File"; print "  path: " $0}'
or 
ls2cwlyml() { ls $@ | awk '{print "- class: File"; print "  path: " $0}'}
ls2cwlyml *.*

以下のように出力されるので、cwl実行用のymlに貼り付けてください

- class: File
  path: README.md
- class: File
  path: RT.png
- class: File
  path: log.txt

3. glob用のcltを使う

以下のCLTをWFに組み込んで使う。
出力がtype: File[]になるので、次のCLTにファイルとして渡すことができます。

glob.cwl
#!/usr/bin/env cwltool
class: CommandLineTool
cwlVersion: v1.0
baseCommand: echo
arguments: 
    - "glob $(inputs.glob_glob.basename) in"
inputs:
    glob_root:
        type: Directory
        inputBinding:
            position: 1
    glob_glob:
        type: string
outputs:
    glob_file:
        type: File[]
        outputBinding:
            glob: $(inputs.glob_root.basename)/$(inputs.glob_glob)
requirements:
    InitialWorkDirRequirement:
        listing:
            - $(inputs.glob_root)

cwltool glob.cwl --glob_root hoge --glob_glob "*.txt"
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0