WDL-第3學(xué)

接下來多個(gè)章節(jié)都是基于 v1.1語法

主要的介紹方法有點(diǎn)類似借鑒Python Cookbook,采取提出問題-解決問題,從實(shí)戰(zhàn)中學(xué)會WDL

  • 問題1: 通過egrep抓取文件中含有特定pattern的行
  • 解決代碼:
    • 運(yùn)行的腳本:egrep.wdl
version 1.0
task hello {
    # 定義輸入
    input {
        String pattern
        File in
    }
    # 相關(guān)命令
    command <<<
        # 當(dāng)執(zhí)行有問題立刻終止
        set -e
        egrep '~{pattern}' '~{in}'
    >>>
    # 相關(guān)輸出
    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"
}
  • 執(zhí)行及輸出信息
$ 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
    }
}

多個(gè)文件輸入的json文件如下(一定要用絕對路徑)

{
    "wf_parallel.pattern": "^[a-z]+$",
    "wf_parallel.infile": ["/Users/liji/cromwell/00.question1/file.txt", "/Users/liji/cromwell/00.question1/file2.txt"]
}
  • 執(zhí)行及輸出信息
$ java -jar /Users/liji/cromwell/cromwell-57.jar run egrep2.wdl --inputs egrep2.json
...
{
  "wf_parallel.all_matches": [["abcdef", "fhhh", "hhh"], ["abcdefaaaaa", "fhhheeee", "hhhgggg"]]
}
...
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容