小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

snakemake 學(xué)習(xí)筆記1

 育種數(shù)據(jù)分析 2021-11-18
snakemake是一個(gè)寫(xiě)流程的工具, 功能非常強(qiáng)大, 特別是針對(duì)批量化處理時(shí), 效率很高, 而且語(yǔ)法非常人性化, 下面是一個(gè)簡(jiǎn)單的示例, 介紹怎么用snakemake書(shū)寫(xiě)自己的第一個(gè)程序. 

1, snakemake介紹

Snakemake是用Python3寫(xiě)的一個(gè)流程化工具, 非常方便. 官網(wǎng)上的例子有點(diǎn)難度, 這里用最簡(jiǎn)單的案例解釋一下snakemake的應(yīng)用方法.
安裝方法

easy_install3 snakemake

或者:

pip3 install snakemake

也可以從源文件安裝:

git clone https:///snakemake/snakemake.git
cd snakemake
virtualenv -p python3 .venv
source .venv/bin/activate
python setup.py install

2, 一個(gè)簡(jiǎn)單的案例

思路:

  • 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

3, 生成snakemake腳本

生成一個(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}

4, snakemake -np

使用-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

5, 執(zhí)行命令 snakemake

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.

6, 運(yùn)行成功, 重新運(yùn)行時(shí)

顯示Nothing to be done, 即不會(huì)執(zhí)行.

(base) [dengfei@localhost example]$ snakemake
Nothing to be done.

如果heibng.txt文件被刪掉了, 再執(zhí)行, 就會(huì)重新執(zhí)行.

這是一小步, 也是一大步.

    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多