Skip to content

Commit

Permalink
Merge pull request #17 from NBISweden/plugin
Browse files Browse the repository at this point in the history
MultiQC plugin
  • Loading branch information
pontushojer authored Jul 6, 2020
2 parents 28d852c + f599ca0 commit de2c535
Show file tree
Hide file tree
Showing 23 changed files with 658 additions and 67 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,21 @@ Install blr into the environment in "editable install" mode.
This will install blr in such a way that you can still modify the source code
and get any changes immediately without re-installing.

#### 2.1 Linux users (not macOS)
#### 2.1 MultiQC plugin

There is a MultiQC plugin included in the BLR pipeline called
MultiQC_BLR. If you which to run MultiQC without this plugin include
`--disable-blr-plugin` in your multiqc command.

The plugin allows for comparision between different runs. In this case go to
the directory containing the folders for the runs you wish to compare. Then run:

multiqc -d .

The `-d` option prepends the directory name to each sample allowing differentiation
between the runs.

#### 2.2 Linux users (not macOS)

To enable DeepVariant, install it separately to your environment.

Expand Down
17 changes: 16 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,29 @@
"tqdm",
"snakemake",
"importlib_resources; python_version<'3.7'",
"multiqc"
],
extras_require={
"dev": ["flake8"],
},
package_dir={"": "src"},
packages=find_namespace_packages("src"),
package_data={"blr": ["Snakefile", "rules/*.smk", "config.schema.yaml", "blr.yaml"]},
entry_points={"console_scripts": ["blr = blr.__main__:main"]},
entry_points={
"console_scripts": [
"blr = blr.__main__:main"
],
"multiqc.modules.v1": [
"stats = multiqc_blr.modules.stats:MultiqcModule",
"hapcut2 = multiqc_blr.modules.hapcut2:MultiqcModule",
],
"multiqc.cli_options.v1": [
"disable_plugin = multiqc_blr.cli:disable_plugin"
],
"multiqc.hooks.v1": [
"execution_start = multiqc_blr.multiqc_blr:execution_start"
]
},
classifiers=[
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
Expand Down
2 changes: 1 addition & 1 deletion src/blr/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_multiqc_input(wildcards):
"figures/mapped",
]
if config["phasing_ground_truth"]:
inputs.append("mapped.phasing_stats.tsv")
inputs.append("mapped.phasing_stats.txt")

return inputs

Expand Down
13 changes: 6 additions & 7 deletions src/blr/cli/calculate_haplotype_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ def main(args):
logging.info("Starting analysis")
stats = vcf_vcf_error_rate(args.vcf1, args.vcf2, args.indels)

with open(args.output + ".txt", "w") as file:
print(stats.to_txt(), file=file)

with open(args.output + ".tsv", "w") as file:
print(stats.to_tsv(), file=file)

if args.output:
with open(args.output, "w") as file:
print(stats.to_txt(), file=file)
else:
print(stats.to_txt())
logging.info("Finished")


Expand Down Expand Up @@ -639,4 +638,4 @@ def add_arguments(parser):
help="A phased, single sample VCF file to use as the 'ground truth' haplotype.")
parser.add_argument('-i', '--indels', action="store_true",
help='Use this flag to consider indel variants. Default: %(default)s', default=False)
parser.add_argument("-o", "--output", default="phasing_stats", help="Output file prefix. Default: %(default)s.")
parser.add_argument("-o", "--output", help="Output file name. Default: Print to stdout.")
53 changes: 0 additions & 53 deletions src/blr/multiqc_config.yaml
Original file line number Diff line number Diff line change
@@ -1,56 +1,3 @@
title: "BLR run report"
intro_text: "This is a collection of results from the BLR pipeline. Go to our
<a href=https://github.com/FrickTobias/BLR>github page</a> for more information."

custom_data:
phasing_stats:
id: 'phasing_stats'
section_name: 'Phasing metrics'
description: '- Phasing statistics from HapCUP2 calculate_phasing_stats.py script.'
plot_type: 'table'
pconfig:
id: 'phasing_stats'
title: 'Phasing metrics table'
scale: false
share_key: false
headers:
'switch rate':
title: 'Switch rate'
description: 'switch errors as a fraction of possible positions for switch errors'
format: '{:,.7f}'
placement: 1
'mismatch rate':
title: 'Mismatch rate'
description: 'mismatch errors as a fraction of possible positions for mismatch errors'
format: '{:,.7f}'
placement: 2
'flat rate':
title: 'Flat rate'
description: 'flat errors as a fraction of possible positions for flat errors'
format: '{:,.7f}'
hidden: true
'phased count':
title: 'Phased count'
description: 'count of total SNVs phased in the test haplotype'
format: '{:,.0f}'
placement: 3
AN50:
title: 'AN50 (Mbp)'
description: 'the AN50 metric of haplotype completeness'
format: '{:,.3f}'
hidden: true
N50:
title: 'N50 (Mbp)'
description: 'the N50 metric of haplotype completeness'
format: '{:,.3f}'
placement: 4
'num snps max blk':
title: 'SNPs in max blk'
description: 'the fraction of SNVs in the largest (most variants phased) block'
format: '{:,.0f}'
placement: 5


sp:
phasing_stats:
fn: 'phasing_stats.tsv'
6 changes: 2 additions & 4 deletions src/blr/rules/phasing.smk
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,15 @@ rule hapcut2_stats:
"""Get phasing statistics relative the ground truth. See https://github.com/vibansal/HapCUT2/tree/master/utilities
for details. """
output:
stats = expand("{{base}}.phasing_stats.{ext}", ext=["txt", "tsv"])
stats = "{base}.phasing_stats.txt"
input:
vcf1 = "{base}.calling.phased.vcf",
vcf2 = "ground_truth.phased.vcf"
params:
stats_prefix = "{base}.phasing_stats"
shell:
"blr calculate_haplotype_statistics"
" -v1 {input.vcf1}"
" -v2 {input.vcf2}"
" -o {params.stats_prefix}"
" -o {output.stats}"


def get_haplotag_input(wildcards):
Expand Down
Empty file added src/multiqc_blr/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions src/multiqc_blr/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python
"""
MultiQC command line options - we tie into the MultiQC
core here and add some new command line parameters.
See the Click documentation for more command line flag types:
http://click.pocoo.org/5/
"""

import click

# Sets config.kwargs['disable_plugin'] to True if specified (will be False otherwise)
disable_plugin = click.option(
'--disable-blr-plugin', 'disable_plugin',
is_flag=True,
help="Disable the MultiQC BLR plugin on this run")
Empty file.
3 changes: 3 additions & 0 deletions src/multiqc_blr/modules/hapcut2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from __future__ import absolute_import

from .hapcut2 import MultiqcModule # noqa
Loading

0 comments on commit de2c535

Please sign in to comment.