Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from moonso/annotate-vcf
Annotate vcf
- Loading branch information
Showing
21 changed files
with
625 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
[2.2] | ||
|
||
- Adds CLI function to annotate variants | ||
- Adds CLI functionality to dump and restore a database | ||
|
||
[2.1] | ||
|
||
- Fix bug with inserting variants | ||
|
||
[2.0] | ||
|
||
- Adds structural variants to loqus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Admin Guide | ||
|
||
This section will include documentation for admins and developers | ||
|
||
* [Dump database](./dump.md) | ||
* [Restore database](./restore.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Dumping a database | ||
|
||
Loqus have a command to dump a database to a zipped file. | ||
This command just wraps the mongo command dump with some defaults. | ||
|
||
```bash | ||
$loqusdb dump --help | ||
Usage: loqusdb dump [OPTIONS] | ||
|
||
Dump the database to a zipped file. | ||
|
||
Default filename is loqusdb.<todays date>.gz (e.g loqusdb.19971004.gz) | ||
|
||
Options: | ||
-f, --filename PATH If custom named file is to be used | ||
--help Show this message and exit. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Restore a database | ||
|
||
It is possible to load all information from a dumped loqusdb instance. | ||
This command just wraps the mongo command `mongo restore` | ||
Loqusdb is shipped with a database instance that includes structural variants from ~740 1000G individuals. | ||
Those have been called with [manta][manta], [tiddit][tiddit] and [CNVnator][cnvnator] | ||
and the calls are merged with [svdb][svdb]. | ||
If no file is pointed at `loqusdb restore` will use this database as default. | ||
|
||
```bash | ||
Usage: loqusdb restore [OPTIONS] | ||
|
||
Restore the database from a zipped file. | ||
|
||
Default is to restore from db dump in loqusdb/resources/ | ||
|
||
Options: | ||
-f, --filename PATH If custom named file is to be used | ||
--help Show this message and exit. | ||
``` | ||
|
||
[manta]: https://github.com/Illumina/manta | ||
[tiddit]: https://github.com/SciLifeLab/TIDDIT | ||
[svdb]: https://github.com/J35P312/SVDB | ||
[cnvnator]: https://github.com/abyzovlab/CNVnator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Annotating variants | ||
|
||
Loqusdb can annotate a VCF with observations from an instance. | ||
|
||
Use command: | ||
|
||
```bash | ||
Usage: loqusdb annotate [OPTIONS] <vcf_file> | ||
|
||
Annotate the variants in a VCF | ||
|
||
Options: | ||
--sv | ||
--help Show this message and exit. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import os | ||
import logging | ||
import click | ||
|
||
from pprint import pprint as pp | ||
|
||
from datetime import datetime | ||
|
||
from loqusdb.exceptions import (VcfError) | ||
from loqusdb.utils.load import load_database | ||
from loqusdb.utils.vcf import (get_file_handle, check_vcf, add_headers) | ||
from loqusdb.utils.annotate import (annotate_snvs, annotate_svs) | ||
|
||
from . import base_command | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
@base_command.command('annotate', short_help="Annotate a VCF with observations") | ||
@click.argument('variant-file', | ||
type=click.Path(exists=True), | ||
metavar='<vcf_file>', | ||
) | ||
@click.option('--sv', is_flag=True) | ||
@click.pass_context | ||
def annotate(ctx, variant_file, sv): | ||
"""Annotate the variants in a VCF | ||
""" | ||
adapter = ctx.obj['adapter'] | ||
|
||
variant_path = os.path.abspath(variant_file) | ||
|
||
expected_type = 'snv' | ||
if sv: | ||
expected_type = 'sv' | ||
|
||
if 'sv': | ||
nr_cases = adapter.nr_cases(sv_cases=True) | ||
else: | ||
nr_cases = adapter.nr_cases(snv_cases=True) | ||
LOG.info("Found {0} {1} cases in database".format(nr_cases, expected_type)) | ||
|
||
vcf_obj = get_file_handle(variant_path) | ||
add_headers(vcf_obj, nr_cases=nr_cases, sv=sv) | ||
# Print the headers | ||
for header_line in vcf_obj.raw_header.split('\n'): | ||
if len(header_line) == 0: | ||
continue | ||
click.echo(header_line) | ||
|
||
start_inserting = datetime.now() | ||
|
||
if sv: | ||
annotated_variants = annotate_svs(adapter, vcf_obj) | ||
else: | ||
annotated_variants = annotate_snvs(adapter, vcf_obj) | ||
# try: | ||
for variant in annotated_variants: | ||
click.echo(str(variant).rstrip()) | ||
# except (Exception) as error: | ||
# LOG.warning(error) | ||
# ctx.abort() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
import logging | ||
import subprocess | ||
|
||
from datetime import datetime | ||
|
||
import click | ||
|
||
from . import base_command | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
@base_command.command('dump', short_help="Dump the database") | ||
@click.option('-f' ,'--filename', | ||
help='If custom named file is to be used', | ||
type=click.Path(exists=False) | ||
) | ||
@click.pass_context | ||
def dump(ctx, filename): | ||
"""Dump the database to a zipped file. | ||
Default filename is loqusdb.<todays date>.gz (e.g loqusdb.19971004.gz) | ||
""" | ||
|
||
if not filename: | ||
filename = "loqusdb.{}.gz".format(datetime.now().strftime('%Y%m%d')) | ||
|
||
if os.path.isfile(filename): | ||
LOG.warning("File {} already exists. Please remove file or change name with '--filename'".format(filename)) | ||
ctx.abort() | ||
|
||
call = ['mongodump', '--gzip', '--db', 'loqusdb', '--archive={}'.format(filename)] | ||
|
||
LOG.info('dumping database...') | ||
start_time = datetime.now() | ||
try: | ||
completed = subprocess.run(call, check=True) | ||
except subprocess.CalledProcessError as err: | ||
LOG.warning(err) | ||
LOG.info("Deleting dump..") | ||
os.path.remove(filename) | ||
ctx.abort() | ||
|
||
LOG.info('Database dumped succesfully') | ||
LOG.info('Time to dump database: {0}'.format(datetime.now()-start_time)) | ||
|
||
|
Oops, something went wrong.