美文网首页
snakemake -- 学习

snakemake -- 学习

作者: QXPLUS | 来源:发表于2022-05-15 21:25 被阅读0次

snakemake document

一个例子

# 可以在 Snakefile 的顶部用纯 Python 临时定义样本列表
SAMPLES = ["A", "B"]

# Step 6: Adding a target rule
rule all:
    input:
        "plots/quals.svg"

# Step 1: Mapping reads
rule bwa_map:
    input:
        "data/genome.fa",
        "data/samples/{sample}.fastq"
    output:
        "mapped_reads/{sample}.bam"
    shell:
        "bwa mem {input} | samtools view -Sb - > {output}"

# Step 2: Sorting read alignments
rule samtools_sort:
    input:
        "mapped_reads/{sample}.bam"
    output:
        "sorted_reads/{sample}.bam"
    shell:
        "samtools sort -T sorted_reads/{wildcards.sample} "
        "-O bam {input} > {output}"

# Step 3: Indexing read alignments
rule samtools_index:
    input:
        "sorted_reads/{sample}.bam"
    output:
        "sorted_reads/{sample}.bam.bai"
    shell:
        "samtools index {input}"

# Step 4: Calling genomic variants
rule bcftools_call:
    input:
        fa="data/genome.fa",
        bam=expand("sorted_reads/{sample}.bam", sample=SAMPLES),
        bai=expand("sorted_reads/{sample}.bam.bai", sample=SAMPLES)
    output:
        "calls/all.vcf"
    shell:
        "bcftools mpileup -f {input.fa} {input.bam} | "
        "bcftools call -mv - > {output}"

# Step 5: Using custom scripts
rule plot_quals:
    input:
        "calls/all.vcf"
    output:
        "plots/quals.svg"
    script:
        "scripts/plot-quals.py"
  • 高级设置例子
# config.yaml
samples:
    A: data/samples/A.fastq
    B: data/samples/B.fastq

prior_mutation_rate: 0.001
configfile: "config.yaml"


rule all:
    input:
        "plots/quals.svg"


def get_bwa_map_input_fastqs(wildcards):
    return config["samples"][wildcards.sample]


rule bwa_map:
    input:
        "data/genome.fa",
        get_bwa_map_input_fastqs
    output:
        temp("mapped_reads/{sample}.bam")
    params:
        rg=r"@RG\tID:{sample}\tSM:{sample}"
    log:
        "logs/bwa_mem/{sample}.log"
    threads: 8
    shell:
        "(bwa mem -R '{params.rg}' -t {threads} {input} | "
        "samtools view -Sb - > {output}) 2> {log}"


rule samtools_sort:
    input:
        "mapped_reads/{sample}.bam"
    output:
        protected("sorted_reads/{sample}.bam")
    shell:
        "samtools sort -T sorted_reads/{wildcards.sample} "
        "-O bam {input} > {output}"


rule samtools_index:
    input:
        "sorted_reads/{sample}.bam"
    output:
        "sorted_reads/{sample}.bam.bai"
    shell:
        "samtools index {input}"


rule bcftools_call:
    input:
        fa="data/genome.fa",
        bam=expand("sorted_reads/{sample}.bam", sample=config["samples"]),
        bai=expand("sorted_reads/{sample}.bam.bai", sample=config["samples"])
    output:
        "calls/all.vcf"
    params:
        rate=config["prior_mutation_rate"]
    log:
        "logs/bcftools_call/all.log"
    shell:
        "(bcftools mpileup -f {input.fa} {input.bam} | "
        "bcftools call -mv -P {params.rate} - > {output}) 2> {log}"


rule plot_quals:
    input:
        "calls/all.vcf"
    output:
        "plots/quals.svg"
    script:
        "scripts/plot-quals.py"

相关文章

  • snakemake学习

    DAG(directed acyclic graph):有向无环图 条件:1. 每个顶点出现且只出现一次。2. 若...

  • snakemake -- 学习

    snakemake document[https://snakemake.readthedocs.io/en/st...

  • snakemake 学习(1)

    1、安装 Snakemake可以在PyPi以及Bioconda上获得,也可以从源代码获得。您可以使用以下方法之一安...

  • snakemake 学习(0)

    1. snkemake介绍 Snakemake工作流管理系统是一种创建可重复和可扩展的数据分析的工具。工作流程通过...

  • snakemake 学习(2)

    举一个小例子: 通过在Snakefile中指定规则来定义Snakemake工作流。 规则通过指定如何从输入文件集创...

  • 流程管理工具snakemake学习笔记杂记02

    snakemake学习笔记007~slurm的cluster提交任务 主要参考 https://eriqande....

  • Snakemake - 任务投递参数

    SnakeMake - 使用 snakemake主体是通过一个*.smk完成 相关命令: --dag --forc...

  • Shell 使用多线程提交任务-FIFO

    参考: 学习snakemake,三步轻松搭建生信流程![https://zhuanlan.zhihu.com/p/...

  • snakemake 学习笔记1

    1, snakemake介绍 Snakemake是用Python3写的一个流程化工具, 非常方便. 官网上的例子有...

  • snakemake 学习笔记3

    目标 这次, 我要实现这个路程图. 目标介绍 第一: 生成1.txt , 2.txt, 3.txt 第二: 向每个...

网友评论

      本文标题:snakemake -- 学习

      本文链接:https://www.haomeiwen.com/subject/ugiburtx.html