2.8. カスタムタイプ#

CWL定義で使用・再利用するために、独自のカスタム型を書きたい場合があります。このようなカスタムタイプを使用することで、同じタイプを使用する複数の記述の間の冗長性を減らし、また、CWL定義を直接いじらずに、ツールや分析のカスタマイズや設定を追加できるようになります。

以下の例は、標準的なbiomテーブルファイルをhdf5形式に変換するbiom convert format ツールのCWL定義です。

custom-types.cwl#
#!/usr/bin/env cwl-runner
cwlVersion: v1.2
class: CommandLineTool

requirements:
  InlineJavascriptRequirement: {}
  ResourceRequirement:
    coresMax: 1
    ramMin: 100  # just a default, could be lowered
  SchemaDefRequirement:
    types:
      - $import: biom-convert-table.yaml

hints:
  DockerRequirement:
    dockerPull: 'quay.io/biocontainers/biom-format:2.1.15'
  SoftwareRequirement:
    packages:
      biom-format:
        specs: [ "https://doi.org/10.1186/2047-217X-1-7" ]
        version: [ "2.1.15" ]

inputs:
  biom:
    type: File
    format: edam:format_3746  # BIOM
    inputBinding:
      prefix: --input-fp
  table_type:
    type: biom-convert-table.yaml#table_type
    inputBinding:
      prefix: --table-type

  header_key:
    type: string?
    doc: |
      The observation metadata to include from the input BIOM table file when
      creating a tsv table file. By default no observation metadata will be
      included.
    inputBinding:
      prefix: --header-key

baseCommand: [ biom, convert ]

arguments:
  - valueFrom: $(inputs.biom.nameroot).hdf5
    prefix: --output-fp
  - --to-hdf5

outputs:
  result:
    type: File
    outputBinding: { glob: "$(inputs.biom.nameroot)*" }

$namespaces:
  edam: http://edamontology.org/
  s: https://schema.org/

$schemas:
  - http://edamontology.org/EDAM_1.16.owl
  - https://schema.org/version/latest/schemaorg-current-http.rdf

s:license: https://spdx.org/licenses/Apache-2.0
s:copyrightHolder: "EMBL - European Bioinformatics Institute"
custom-types.yml#
biom:
    class: File
    format: http://edamontology.org/format_3746
    path: rich_sparse_otu_table.biom
table_type: OTU table

注意: 以下の例に行うには、wgetなどでrich_sparse_otu_table.biomという入力ファイルをダウンロードする必要があります:

$ wget https://github.com/common-workflow-language/user_guide/raw/main/src/_includes/cwl/custom-types/rich_sparse_otu_table.biom

29行目のinputs:table_type で、テーブル変換で使用できるテーブルオプションのリストがカスタムオブジェクトとしてインポートされます:

inputs:
  biom:
    type: File
    format: edam:format_3746  # BIOM
    inputBinding:
      prefix: --input-fp
  table_type:
    type: biom-convert-table.yaml#table_type
    inputBinding:
      prefix: --table-type

カスタムタイプの参照は、そのオブジェクトが定義されているファイル名(biom-convert-table.yaml )と、カスタムタイプを定義するそのファイル内のオブジェクト名(table_type )を組み合わせたものです。この場合、インポートされたbiom-convert-table.yaml ファイルからのsymbols 配列が、許容されるテーブルオプションを定義します。例えば、custom-types.yml では、OTU tableinput として渡し、hdf5 形式の OTU table を作成するようツールに指示しています。

カスタムタイプを記述するYAMLファイルの内容を以下に示します:

biom-convert-table.yaml#
type: enum
name: table_type
label: The type of the table to produce
symbols:
  - OTU table
  - Pathway table
  - Function table
  - Ortholog table
  - Gene table
  - Metabolite table
  - Taxon table
  - Table

カスタム型をCWL定義で使用するためには、インポートする必要があります。インポートについては、requirements:SchemaDefRequirement で定義されており、例としてcustom-types.cwl の定義にあるように、インポートされます:

requirements:
  InlineJavascriptRequirement: {}
  ResourceRequirement:
    coresMax: 1
    ramMin: 100
  SchemaDefRequirement:
    types:
      - $import: biom-convert-table.yaml

また、この CWL 定義には、ResourceRequirementも含まれていることに注意してください。これは、ツールが正常に動作するために必要な最小限の RAM の量とコアの数、さらにその定義に書かれたソフトウェアのバージョンの詳細やその他の有用なメタデータを指定するものです。これらの機能については、このユーザーガイドの他の章で詳しく説明します。