Snakemake是用Python3寫(xiě)的一個(gè)流程化工具, 非常方便. 官網(wǎng)上的例子有點(diǎn)難度, 這里用最簡(jiǎn)單的案例解釋一下snakemake的應(yīng)用方法.
安裝方法
easy_install3 snakemake
或者:
pip3 install snakemake
也可以從源文件安裝:
git clone https://bitbucket.org/snakemake/snakemake.git
cd snakemake
virtualenv -p python3 .venv
source .venv/bin/activate
python setup.py install
思路:
1, 生成一個(gè)1.txt文件
2, 生成一個(gè)2.txt文件
3, 使用cat命令, 將兩者合并為hebing.txt
echo "hello number1" >1.txt
echo "hello number2" >2.txt
cat 1.txt 2.txt
cat 1.txt 2.txt >hebing.txt
生成一個(gè)名為:Snakemake的文件
(base) [dengfei@localhost example]$ cat Snakefile
rule test_cat:
input:
"1.txt",
"2.txt"
output:
"hebing.txt"
shell:
"cat {input} >> {output}"
這里有四個(gè)參數(shù):
rule: 是名稱, 這里命名為test_cat
Input: 輸入文件, 這里是”1.txt”, “2.txt”
Output: 輸出文件, 這里是”hebing.txt”
Shell: 這里是要執(zhí)行的腳本, 輸入文件是{input}, 輸出文件是{output}
使用-np查看轉(zhuǎn)化后的命令
(base) [dengfei@localhost example]$ snakemake -np
rule test_cat:
input: 1.txt, 2.txt
output: hebing.txt
jobid: 0
cat 1.txt 2.txt >> hebing.txt
Job counts:
count jobs
1 test_cat
1
snakemake默認(rèn)執(zhí)行的文件名是: Snakemake, 如果想要指定自己編寫(xiě)的文件名, 可以加上參數(shù): —snakefile
比如: 文件名為a.snake
snakemake --snakefile a.snake
如果文件名是默認(rèn)的Snakemake, 不用加參數(shù), 直接運(yùn)行snakemake即可直接執(zhí)行.
(base) [dengfei@localhost example]$ snakemake
Provided cores: 1
Rules claiming more threads will be scaled down.
Job counts:
count jobs
1 test_cat
1
rule test_cat:
input: 1.txt, 2.txt
output: hebing.txt
jobid: 0
Finished job 0.
1 of 1 steps (100%) done
查看結(jié)果:
(base) [dengfei@localhost example]$ cat hebing.txt
hello number1
hello number2
可以看到, 使用snakemake, 成功的將1.txt 和2.txt 合并為hebing.txt.
顯示Nothing to be done, 即不會(huì)執(zhí)行.
(base) [dengfei@localhost example]$ snakemake
Nothing to be done.
如果heibng.txt文件被刪掉了, 再執(zhí)行, 就會(huì)重新執(zhí)行.
這是一小步, 也是一大步.
聯(lián)系客服