Mercurial > repos > sanbi-uwc > vcf2neo
annotate vcf2neo_wrapper.py @ 0:3e14eda348d3 draft default tip
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
author | sanbi-uwc |
---|---|
date | Mon, 19 Jun 2017 00:08:18 -0400 |
parents | |
children |
rev | line source |
---|---|
0
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
2 |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
3 from __future__ import print_function |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
4 import argparse |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
5 import os |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
6 import shlex |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
7 import subprocess |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
8 import uuid |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
9 import sys |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
10 |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
11 parser = argparse.ArgumentParser( |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
12 description="Call vcf2neo on VCF inputs from Galaxy") |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
13 |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
14 parser.add_argument('--vcf_dataset_names', nargs='+', |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
15 help='Names of VCF datasets') |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
16 parser.add_argument('--neo4j_db_path', help='Neo4j database directory') |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
17 parser.add_argument('--user', help='Email of Galaxy user running this tool') |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
18 parser.add_argument('--variantset_name', |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
19 help='Name for the VariantSet containing all the variants') |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
20 parser.add_argument('--vcf_files', |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
21 help='VCF format variant file', nargs='+') |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
22 |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
23 args = parser.parse_args() |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
24 |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
25 os.mkdir(args.variantset_name) |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
26 |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
27 print("VCF names:", len(args.vcf_dataset_names), args.vcf_dataset_names, file=sys.stderr) |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
28 print("VCF files:", len(args.vcf_files), args.vcf_files, file=sys.stderr) |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
29 for i, vcf_file in enumerate(args.vcf_files): |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
30 print("XXXX I:", i, vcf_file, file=sys.stderr) |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
31 callset_name = args.vcf_dataset_names[i] |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
32 os.symlink(vcf_file, os.path.join(args.variantset_name, |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
33 callset_name) + '.vcf') |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
34 # Usage: vcf2neo init [OPTIONS] VCF_DIR OWNER [HISTORY_ID] [OUTPUT_DIR] |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
35 # |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
36 # Copy reference database and load VCF to Neo4j Graph database. :param |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
37 # vcf_dir: :param refdb_dir: :param d: :return: |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
38 # |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
39 # Options: |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
40 # -d / -D Run Neo4j docker container. |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
41 # --help Show this message and exit. |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
42 |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
43 history_id = str(uuid.uuid4()) |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
44 cmd_str = ('vcf2neo init -d ' + |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
45 '{input_vcf_dir} {email} {history_id} {neo4j_db_path}'.format( |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
46 input_vcf_dir=args.variantset_name, |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
47 email=args.user, |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
48 history_id=history_id, |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
49 neo4j_db_path=args.neo4j_db_path)) |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
50 cmd = shlex.split(cmd_str) |
3e14eda348d3
planemo upload for repository https://github.com/sanbi-sa/tools-sanbi-uwc commit 0245b4efed8ced6d06d76f1249a47d2178285385
sanbi-uwc
parents:
diff
changeset
|
51 subprocess.check_call(cmd) |