接下来多个章节都是基于 v1.1语法
主要的介绍方法有点类似借鉴Python Cookbook,采取提出问题-解决问题,从实战中学会WDL
- 问题1: 通过
egrep
抓取文件中含有特定pattern的行 - 解决代码:
- 运行的脚本:egrep.wdl
version 1.0
task hello {
# 定义输入
input {
String pattern
File in
}
# 相关命令
command <<<
# 当执行有问题立刻终止
set -e
egrep '~{pattern}' '~{in}'
>>>
# 相关输出
output {
Array[String] matches = read_lines(stdout())
}
}
workflow wf {
input {
File infile
String pattern
}
call hello {
input:
in=infile,
pattern=pattern
}
output {
Array[String] matches = hello.matches
}
}
- 输入json
{
"wf.pattern": "^[a-z]+$",
"wf.infile": "/Users/your_name/cromwell/00.question1/file.txt"
}
- 执行及输出信息
$ java -jar cromwell-57.jar run egrep.wdl --inputs egrep.json
...
[2021-03-29 17:59:48,60] [info] SingleWorkflowRunnerActor workflow finished with status 'Succeeded'.
{
"outputs": {
"wf.matches": ["abcdef", "fhhh", "hhh"]
},
"id": "c8898489-99f0-41f2-bec4-7a3d0a36c6dc"
}
...
- 问题2: 通过
egrep
抓取文件中含有特定pattern的行,并行处理文件
主要是修改wf地方:
workflow wf_parallel {
input {
Array[File] files
String pattern
}
scatter (path in files){
call hello {
input:
in=path,
pattern=pattern
}
}
output {
Array[Array[String]] all_matches = hello.matches
}
}
多个文件输入的json文件如下(一定要用绝对路径)
{
"wf_parallel.pattern": "^[a-z]+$",
"wf_parallel.infile": ["/Users/liji/cromwell/00.question1/file.txt", "/Users/liji/cromwell/00.question1/file2.txt"]
}
- 执行及输出信息
$ java -jar /Users/liji/cromwell/cromwell-57.jar run egrep2.wdl --inputs egrep2.json
...
{
"wf_parallel.all_matches": [["abcdef", "fhhh", "hhh"], ["abcdefaaaaa", "fhhheeee", "hhhgggg"]]
}
...
网友评论