annotate ecoli_serotyping/commandLineOptions.py @ 10:5b52b3842765 draft

Uploaded
author jpetteng
date Sat, 06 Jan 2018 13:32:23 -0500
parents fe3ceb5c4214
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
1 #!/usr/bin/env python
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
2
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
3 import argparse
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
4
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
5
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
6 def parse_command_line(args=None):
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
7 """
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
8 The options for both the serotyper, and virulence finder.
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
9 The returned object is used by both, but the options do not
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
10 necessarily apply to both.
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
11
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
12 Args:
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
13 args: Optional args to be passed to argparse.parse_args()
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
14
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
15 Returns:
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
16 The populated argparse Namespace
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
17 """
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
18
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
19 def check_percentage(value):
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
20 """
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
21 type checker for percentage input
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
22 """
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
23 ivalue = int(value)
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
24 if ivalue <= 0 or ivalue > 100:
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
25 raise argparse.ArgumentTypeError(
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
26 "{0} is an invalid positive int percentage value".format(value)
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
27 )
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
28 return ivalue
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
29
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
30 parser = argparse.ArgumentParser()
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
31 parser.add_argument(
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
32 "-i",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
33 "--input",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
34 help="Location of new file(s). Can be a single file or \
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
35 a directory",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
36 required=True
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
37 )
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
38
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
39 parser.add_argument(
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
40 "-d",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
41 "--percentIdentity",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
42 type=check_percentage,
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
43 help="Percentage of identity wanted to use against the\
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
44 database. From 0 to 100, default is 90%%.",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
45 default=90
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
46 )
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
47
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
48 parser.add_argument(
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
49 "-l",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
50 "--percentLength",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
51 type=check_percentage,
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
52 help="Percentage of length wanted to use against the \
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
53 database. From 0 to 100, default is 50%%.",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
54 default=50
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
55 )
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
56
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
57 parser.add_argument(
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
58 "--verify",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
59 action="store_true",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
60 help="Enable E. Coli. verification"
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
61 )
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
62
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
63 parser.add_argument(
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
64 "-s",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
65 "--species",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
66 action="store_true",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
67 help="Enable species identification when non-ecoli genome is found\n\
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
68 Note: refseq downloading is required when running this option for the first time."
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
69 )
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
70
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
71 parser.add_argument(
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
72 '--detailed',
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
73 action='store_true',
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
74 help='Enable detailed output'
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
75 )
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
76
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
77 parser.add_argument(
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
78 "-o",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
79 "--output",
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
80 help="Directory location of output files."
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
81 )
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
82
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
83 if args is None:
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
84 return parser.parse_args()
fe3ceb5c4214 Uploaded
jpetteng
parents:
diff changeset
85 return parser.parse_args(args)