{"id":30349,"date":"2024-02-29T15:08:08","date_gmt":"2024-02-29T07:08:08","guid":{"rendered":"http:\/\/www.biocloudservice.com\/wordpress\/?p=30349"},"modified":"2024-02-29T15:08:11","modified_gmt":"2024-02-29T07:08:11","slug":"snakemake-%e6%9c%80%e5%a5%bd%e7%94%a8%e7%9a%84%e6%b5%81%e7%a8%8b%e7%ae%a1%e7%90%86%e5%b7%a5%e5%85%b7%e4%b9%8b%e4%b8%80%ef%bc%8c%e4%bd%a0%e5%80%bc%e5%be%97%e6%8b%a5%e6%9c%89","status":"publish","type":"post","link":"http:\/\/www.biocloudservice.com\/wordpress\/?p=30349","title":{"rendered":"snakemake&#8211;\u6700\u597d\u7528\u7684\u6d41\u7a0b\u7ba1\u7406\u5de5\u5177\u4e4b\u4e00\uff0c\u4f60\u503c\u5f97\u62e5\u6709"},"content":{"rendered":"<p>snakemake&#8211;\u6700\u597d\u7528\u7684\u6d41\u7a0b\u7ba1\u7406\u5de5\u5177\u4e4b\u4e00\uff0c\u4f60\u503c\u5f97\u62e5\u6709<\/p>\n<p>\u8fd8\u5728\u5bf9\u7740\u5b9e\u9a8c\u5ba4\u4e0a\u53e4\u5927\u4f6c\u7559\u4e0b\u811a\u672c\u53d1\u6101\u5417\uff1f\u8fd8\u5728\u5934\u75bc\u5927shell\u5957\u5c0fshell\u7684\u5c4e\u5c71\u5417?\u8fd8\u5728\u4e3a\u627e\u4e0d\u5230\u95ee\u9898\u6b65\u9aa4\u7684shell\u800c\u70e6\u607c\u5417\uff1f\u5feb\u8ddf\u7740\u5c0f\u679c\u628asnakemake\u5b66\u8d77\u6765\u5427\u3002<\/p>\n<p>1-Snakemake\u7684\u5b89\u88c5<\/p>\n<p>\u9996\u5148\u5f53\u7136\u662f\u521b\u5efa\u4e00\u4e2asnakemake\u7684\u6587\u4ef6\u5939\u5566\uff0c\u6587\u4ef6\u7ba1\u7406\u8fd8\u662f\u5f88\u91cd\u8981\u6ef4\u3002<\/p>\n<p>$ mkdir snakemake<\/p>\n<p>$ cd snakemake<\/p>\n<p>\u7136\u540e\u4e0b\u8f7d\u89e3\u538b\u5b98\u65b9\u7684\u793a\u4f8b\u6587\u6863<\/p>\n<p><strong>$ <\/strong>curl -L <a href=\"https:\/\/api.github.com\/repos\/snakemake\/snakemake-tutorial-data\/tarball%20-o%20snakemake-tutorial-data.tar.gz\">https:\/\/api.github.com\/repos\/snakemake\/snakemake-tutorial-data\/tarball -o snakemake-tutorial-data.tar.gz<\/a><\/p>\n<p><strong>$ <\/strong>tar &#8211;wildcards -xf snakemake-tutorial-data.tar.gz<\/p>\n<p>\u770b\u5230\u90a3\u4e2aenvironment.yaml\u4e86\u5417\uff0c\u90a3\u5c31\u662f\u6559\u5458\u4f5b\u7956\u771f\u4e3b\u8d50\u4e88\u6211\u7b49\u83dc\u9e21\u6551\u8d4e\uff0c<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"640\" height=\"125\" class=\"wp-image-30350\" src=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/unnamed-file-133.png?resize=640%2C125\" alt=\"\u7535\u8111\u5c4f\u5e55\u622a\u56fe\n\n\u4f4e\u53ef\u4fe1\u5ea6\u63cf\u8ff0\u5df2\u81ea\u52a8\u751f\u6210\" srcset=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/unnamed-file-133.png?w=1210 1210w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/unnamed-file-133.png?resize=300%2C59 300w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/unnamed-file-133.png?resize=1024%2C201 1024w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/unnamed-file-133.png?resize=768%2C150 768w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/unnamed-file-133.png?resize=600%2C118 600w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/p>\n<p>Snakemake\u8fde\u8fd0\u884c\u73af\u5883\u90fd\u5e2e\u6211\u4eec\u914d\u7f6e\u597d\u4e86\uff0cgithub\u4e0b\u8f7d\u7684\u5927\u795epipeline\u76f4\u63a5\u8fd0\u884cmamba(\u4e0d\u8981\u614c\uff0cmamba\u662fconda\u7684\u5f3a\u529b\u66ff\u4ee3\u54c1)<\/p>\n<p><strong>$ <\/strong>mamba env create &#8211;name snakemake &#8211;file environment.yaml<\/p>\n<p><strong>$ <\/strong>conda activate snakemake<\/p>\n<p>\u5b98\u65b9\u793a\u4f8b\u6587\u4ef6\u7ed3\u6784\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"640\" height=\"217\" class=\"wp-image-30351\" src=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/img.png?resize=640%2C217\" alt=\"img\" srcset=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/img.png?w=671 671w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/img.png?resize=300%2C102 300w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/img.png?resize=600%2C204 600w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/p>\n<p>\u63a5\u4e0b\u6765\u5c31\u5230\u4e86\u6fc0\u52a8\u4eba\u5fc3\u7684\u6d41\u7a0b\u642d\u5efa\u4e86<\/p>\n<p>rule bwa_map: #\u5b9a\u4e49\u7b2c\u4e00\u6761\u89c4\u5219\uff0c\u547d\u540d\u4e3abwa_map<\/p>\n<p>input: #input \uff1a\u8f93\u5165\u6587\u4ef6<\/p>\n<p>&#8220;data\/genome.fa&#8221;,<\/p>\n<p>&#8220;data\/samples\/A.fastq&#8221;<\/p>\n<p>output: #output\uff1a\u8f93\u51fa\u6587\u4ef6<\/p>\n<p>&#8220;mapped_reads\/A.bam&#8221;<\/p>\n<p>shell: #shell\uff1a\u8fd0\u884c\u7684shell\u811a\u672c\uff0c\u4e5f\u53ef\u7528run\uff1a\u8fd0\u884cpython\u811a\u672c<\/p>\n<p>&#8220;bwa mem {input} | samtools view -Sb &#8211; &gt; {output}&#8221;<\/p>\n<p>\u5f53\u7136\uff0c\u5b9e\u9645\u9879\u76ee\u600e\u4e48\u53ef\u80fd\u53ea\u6709\u4e00\u4e2a\u6837\u672c\uff0c\u6211\u4eec\u5c31\u4e0d\u80fd\u76f4\u63a5\u5199\u6837\u672c\u540d\u4e86\uff0csnakemake\u652f\u6301\u4f7f\u7528\u901a\u914d\u7b26\u6765\u6279\u91cf\u8fd0\u884c\u547d\u4ee4\uff0c\u4fee\u6539\u4e00\u4e0b\u4e0a\u9762\u7684\u4ee3\u7801,\u5f53\u7136\uff0csample\u53ef\u4ee5\u505a\u4e2ayaml\u6587\u4ef6\uff0c\u6216\u8005\u5728shell\u91cc\u5199\u4e2afor\uff0c\u8fd9\u91cc\u5bb9\u5c0f\u679c\u5077\u4e2a\u61d2<\/p>\n<p><a id=\"post-30349-_Hlk132159550\"><\/a> rule bwa_map: #\u5b9a\u4e49\u7b2c\u4e00\u6761\u89c4\u5219\uff0c\u547d\u540d\u4e3abwa_map<\/p>\n<p>input: #input \uff1a\u8f93\u5165\u6587\u4ef6<\/p>\n<p>&#8220;data\/genome.fa&#8221;,<\/p>\n<p>&#8220;data\/samples\/{sample}.fastq&#8221;<\/p>\n<p>output: #output\uff1a\u8f93\u51fa\u6587\u4ef6<\/p>\n<p>&#8220;mapped_reads\/{sample}.bam&#8221;<\/p>\n<p>shell: #shell\uff1a\u8fd0\u884c\u7684shell\u811a\u672c\uff0c\u4e5f\u53ef\u7528run\uff1a\u8fd0\u884cpython\u811a\u672c<\/p>\n<p>&#8220;bwa mem {input} | samtools view -Sb &#8211; &gt; {output}&#8221;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"640\" height=\"665\" class=\"wp-image-30352\" src=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/img-1.png?resize=640%2C665\" alt=\"img\" srcset=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/img-1.png?w=671 671w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/img-1.png?resize=289%2C300 289w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/img-1.png?resize=600%2C623 600w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/p>\n<p>\u6d41\u7a0b\u6d41\u7a0b\uff0c\u5f53\u7136\u4e0d\u80fd\u53ea\u6709\u4e00\u4e2a\u89c4\u5219\u5566\u3002\u63a5\u4e0b\u6765\u518d\u5199\u4e2asort\u89c4\u5219\uff0c\u5728\u5934\u6587\u4ef6\u628asample\u5b9a\u4e49\u4e86,\u5c0f\u6837\u672c\u6d4b\u8bd5\u53ef\u4ee5\u8fd9\u6837\u5077\u61d2\uff0c\u5927\u6837\u672c\u8fd8\u662f\u8981yaml\u6587\u4ef6\u54e6<\/p>\n<p>sample = [\u201cA\u201d, \u201cB\u201d, \u201cC\u201d]<\/p>\n<p>rule bwa_map: #\u5b9a\u4e49\u7b2c\u4e00\u6761\u89c4\u5219\uff0c\u547d\u540d\u4e3abwa_map<\/p>\n<p>input: #input \uff1a\u8f93\u5165\u6587\u4ef6<\/p>\n<p>&#8220;data\/genome.fa&#8221;,<\/p>\n<p>&#8220;data\/samples\/{sample}.fastq&#8221;<\/p>\n<p>output: #output\uff1a\u8f93\u51fa\u6587\u4ef6<\/p>\n<p>&#8220;mapped_reads\/{sample}.bam&#8221;<\/p>\n<p>shell: #shell\uff1a\u8fd0\u884c\u7684shell\u811a\u672c\uff0c\u4e5f\u53ef\u7528run\uff1a\u8fd0\u884cpython\u811a\u672c<\/p>\n<p>&#8220;bwa mem {input} | samtools view -Sb &#8211; &gt; {output}&#8221;<\/p>\n<p>rule samtools_sort:<\/p>\n<p>input:<\/p>\n<p>&#8220;mapped_reads\/{sample}.bam&#8221;<\/p>\n<p>output:<\/p>\n<p>&#8220;sorted_reads\/{sample}.bam&#8221;<\/p>\n<p>shell:<\/p>\n<p>&#8220;samtools sort -T sorted_reads\/{wildcards.sample} &#8221;<\/p>\n<p>&#8220;-O bam {input} &gt; {output}&#8221;<\/p>\n<p>rule samtools_index:<\/p>\n<p>input:<\/p>\n<p>&#8220;sorted_reads\/{sample}.bam&#8221;<\/p>\n<p>output:<\/p>\n<p>&#8220;sorted_reads\/{sample}.bam.bai&#8221;<\/p>\n<p>shell:<\/p>\n<p>&#8220;samtools index {input}&#8221;<\/p>\n<p>\u73b0\u5728\uff0c\u89c1\u8bc1\u5947\u8ff9\u7684\u65f6\u523b<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"151\" height=\"154\" class=\"wp-image-30353\" src=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/word-image-30349-4.png?resize=151%2C154\" data-recalc-dims=\"1\" \/><\/p>\n<p>$ snakemake &#8211;dag sorted_reads\/{A,B}.bam.bai | dot -Tsvg &gt; dag.svg<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"280\" height=\"251\" class=\"wp-image-30354\" src=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/unnamed-file-134.png?resize=280%2C251\" alt=\"\u56fe\u793a\n\n\u63cf\u8ff0\u5df2\u81ea\u52a8\u751f\u6210\" data-recalc-dims=\"1\" \/><\/p>\n<p>\u8fd9\u624d\u662fsnakemake\u7684\u7cbe\u9ad3\u6709\u6728\u6709\uff0c\u76f4\u63a5\u751f\u6210\u53ef\u89c6\u5316\u7684\u6d41\u7a0b\u56fe\uff0c\u5988\u5988\u518d\u4e5f\u4e0d\u6015\u5c0f\u679c\u770b\u6d41\u7a0bshell\u4e00\u8138\u61f5\u4e86\uff0c\u5929\u4e0b\u5c31\u6ca1\u6709\u6211\u5c0f\u679c\u770b\u4e0d\u61c2\u7684\u6d41\u7a0b\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"534\" height=\"500\" class=\"wp-image-30355\" src=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/unnamed-file-1.jpeg?resize=534%2C500\" alt=\"\u7a7f\u7740\u84dd\u8272\u8863\u670d\u7684\u718a\n\n\u63cf\u8ff0\u5df2\u81ea\u52a8\u751f\u6210\" srcset=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/unnamed-file-1.jpeg?w=534 534w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/02\/unnamed-file-1.jpeg?resize=300%2C281 300w\" sizes=\"(max-width: 534px) 100vw, 534px\" data-recalc-dims=\"1\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>snakemake&#8211;\u6700\u597d\u7528\u7684\u6d41\u7a0b\u7ba1\u7406\u5de5\u5177\u4e4b\u4e00\uff0c\u4f60\u503c\u5f97\u62e5\u6709 \u8fd8\u5728\u5bf9\u7740\u5b9e\u9a8c\u5ba4\u4e0a\u53e4\u5927\u4f6c\u7559\u4e0b\u811a\u672c\u53d1\u6101\u5417\uff1f\u8fd8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":""},"categories":[1],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/30349"}],"collection":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=30349"}],"version-history":[{"count":1,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/30349\/revisions"}],"predecessor-version":[{"id":30356,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/30349\/revisions\/30356"}],"wp:attachment":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=30349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=30349"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=30349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}