|||
Snakemake是用Python3写的一个流程化工具, 非常方便. 官网上的例子有点难度, 这里用最简单的案例解释一下snakemake的应用方法.
安装方法
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
思路:
echo "hello number1" >1.txt
echo "hello number2" >2.txt
cat 1.txt 2.txt
cat 1.txt 2.txt >hebing.txt
生成一个名为:Snakefile的文件
(base) [dengfei@localhost example]$ cat Snakefile
rule test_cat:
input:
"1.txt",
"2.txt"
output:
"hebing.txt"
shell:
"cat {input} >> {output}"
这里有四个参数:
使用-np查看转化后的命令
(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默认执行的文件名是: Snakefile, 如果想要指定自己编写的文件名, 可以加上参数: —snakefile
比如: 文件名为a.snake
snakemake --snakefile a.snake
如果文件名是默认的Snakemake, 不用加参数, 直接运行snakemake即可直接执行.
(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
查看结果:
(base) [dengfei@localhost example]$ cat hebing.txt
hello number1
hello number2
可以看到, 使用snakemake, 成功的将1.txt 和2.txt 合并为hebing.txt.
显示Nothing to be done, 即不会执行.
(base) [dengfei@localhost example]$ snakemake
Nothing to be done.
如果heibng.txt文件被删掉了, 会重新执行.
这是一小步, 也是一大步.
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-12-26 21:51
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社