-
Notifications
You must be signed in to change notification settings - Fork 2
/
poredb_main.py
105 lines (89 loc) · 4.18 KB
/
poredb_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Thanks for Andreas Klosterman for dask suggestion
# Thanks to Aaron Quinlan for the argparse implementation from poretools.
import sys
import md5
import hashlib
import re
import argparse
import sqlite3
import version
def run_subtool(parser, args):
if args.command == 'create':
import create as submodule
elif args.command == 'import':
import importfiles as submodule
elif args.command == 'fastq':
import fastq as submodule
elif args.command == 'updatelengths':
import updatelengths as submodule
elif args.command == 'worklist':
import worklist as submodule
elif args.command == 'stats':
import stats as submodule
elif args.command == 'find':
import find as submodule
# run the chosen submodule.
submodule.run(parser, args)
class ArgumentParserWithDefaults(argparse.ArgumentParser):
def __init__(self, *args, **kwargs):
super(ArgumentParserWithDefaults, self).__init__(*args, **kwargs)
self.add_argument("-q", "--quiet", help="Do not output warnings to stderr",
action="store_true",
dest="quiet")
def main():
parser = argparse.ArgumentParser(prog='poredb', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-v", "--version", help="Installed poretools version",
action="version",
version="%(prog)s " + str(version.__version__))
subparsers = parser.add_subparsers(title='[sub-commands]', dest='command', parser_class=ArgumentParserWithDefaults)
# newdb
parser_create = subparsers.add_parser('create',
help='Create an empty poredb database')
parser_create.add_argument('db', metavar='DB',
help='The name of the database.')
parser_create.set_defaults(func=run_subtool)
# import
parser_import = subparsers.add_parser('import',
help='Import files into a poredb database')
parser_import.add_argument('db', metavar='DB',
help='The poredb database.')
parser_import.add_argument('fofn', metavar='FOFN',
help='A file containing a list of file names.')
parser_import.add_argument('--alternate-path', metavar='alternate_path')
parser_import.set_defaults(func=run_subtool)
# fastq
parser_fastq = subparsers.add_parser('fastq',
help='Export basecalls from database in FASTQ format')
parser_fastq.add_argument('db', metavar='DB',
help='The name of the database.')
parser_fastq.add_argument('-l', '--lengths', dest='report_lengths', default=False, action='store_true', help="Report lengths instead of bases")
parser_fastq.add_argument('--group-by-asic', default=False, action='store_true', help='Split into one file per asic_id')
parser_fastq.set_defaults(func=run_subtool)
# stats
parser_stats = subparsers.add_parser('stats', help='Show basic summary statistics about database')
parser_stats.add_argument('db', metavar='DB',
help='The name of the database.')
parser_stats.add_argument('--group-by-asic', default=False, action='store_true', help='Split into one file per asic_id')
parser_stats.set_defaults(func=run_subtool)
# worklist
parser_worklist = subparsers.add_parser('worklist')
parser_worklist.add_argument('db', metavar='DB',
help='The name of the database.')
parser_worklist.add_argument('fofn', metavar='FOFN',
help='A file containing a list of file names.')
parser_worklist.set_defaults(func=run_subtool)
# updatelengths
parser_updatelengths = subparsers.add_parser('updatelengths', help='')
parser_updatelengths.add_argument('db', metavar='DB', help='The name of the database.')
parser_updatelengths.set_defaults(func=run_subtool)
# findfiles
parser_find = subparsers.add_parser('find', help='Find path to files by UUID')
parser_find.add_argument('db', metavar='DB', help='The name of the database.')
parser_find.add_argument('fofn', metavar='FOFN', help='A file containing a list of UUIDs.')
parser_find.set_defaults(func=run_subtool)
args = parser.parse_args()
if args.quiet:
logger.setLevel(logging.ERROR)
args.func(parser, args)
if __name__ == "__main__":
main()