NANOPLOT
nanoplot from nanopack.
URL: https://github.com/wdecoster/nanoplot
Example
This wrapper can be used in the following way:
# test nanoplot.
rule nanoplot_fastq:
input:
fastqs = ["test.fq.gz"]
output:
html = "nanoplot_fq/test.NanoPlot-report.html"
params:
title = "test.fq",
extras = "--tsv_stats --N50"
wrapper:
"No_Tags/bio/nanopack/nanoplot"
rule nanoplot_bam:
input:
bams = ["test.bam"]
output:
html = "nanoplot_bam/test.NanoPlot-report.html"
params:
title = "test.bam",
extras = "--tsv_stats --N50"
wrapper:
"No_Tags/bio/nanopack/nanoplot"
Note that input, output and log file paths can be chosen freely.
When running with
snakemake --use-conda
the software dependencies will be automatically deployed into an isolated environment before execution.
Input/Output
Input:
fastqs
: input fastqs list, not with bams.bams
: input bams list, not with fastqs.
Output:
html
: xxx.NanoPlot-report.html. full path to html summary report. Using for parse outdir and prefix.
Params
title
: title name in plot.(optional)extras
: extra arguments add to nanoplot.(optional)
Code
__author__ = "yangqun"
import sys
import os
from snakemake.shell import shell
fastqs = snakemake.input.get('fastqs', '')
bams = snakemake.input.get('bams', '')
out_html = snakemake.output.get('html')
title = snakemake.params.get('title', '')
extras = snakemake.params.get('extras', '')
if not out_html.endswith(".NanoPlot-report.html"):
sys.exit(
"html report must be endswith .NanoPlot-report.html"
)
# 准备输入参数
input_files = ""
if fastqs and bams:
# 两者都有
sys.exit("Either provide fastqs or bams, not both.")
elif not fastqs and not bams:
# 两者都空
sys.exit("Either provide fastqs or bams.")
elif fastqs and not bams:
# fastqs
input_files = "--fastq " + " --fastq ".join(fastqs)
elif bams and not fastqs:
# bams
input_files = "--bam " + " --bam ".join(bams)
# 准备输出
out_prefix = os.path.basename(out_html).replace("NanoPlot-report.html", "")
out_dir = os.path.dirname(out_html)
title = "" if not title else f"--title {title}"
threads = "" if snakemake.threads <= 1 else "-t {}".format(snakemake.threads)
shell(
"NanoPlot {threads} -o {out_dir} -p {out_prefix} {extras} {title} {input_files}"
)