17
17
import ga4gh .datamodel .variants as variants
18
18
19
19
20
+ # the maximum value of a long type in avro = 2**63 - 1
21
+ # (64 bit signed integer)
22
+ # http://avro.apache.org/docs/1.7.7/spec.html#schema_primitive
23
+ # AVRO_LONG_MAX = (1 << 63) - 1
24
+ # TODO in the meantime, this is the max value wormtable can handle
25
+ AVRO_LONG_MAX = (1 << 32 ) - 2
26
+
27
+
20
28
def setCommaSeparatedAttribute (request , args , attr ):
21
29
attribute = getattr (args , attr )
22
30
if attribute is not None :
@@ -122,11 +130,7 @@ def createGAListReferenceBasesRequest(self):
122
130
##############################################################################
123
131
124
132
125
- def server_main (parser = None ):
126
- if parser is None :
127
- parser = argparse .ArgumentParser (
128
- description = "GA4GH reference server" )
129
- # Add global options
133
+ def addGlobalOptions (parser ):
130
134
parser .add_argument (
131
135
"--port" , "-P" , default = 8000 , type = int ,
132
136
help = "The port to listen on" )
@@ -137,32 +141,47 @@ def server_main(parser=None):
137
141
"--config-file" , "-F" , type = str ,
138
142
help = "The configuration file to use" )
139
143
140
- subparsers = parser .add_subparsers (title = 'subcommands' ,)
141
144
142
- # help
145
+ def addServerHelpParser ( subparsers ):
143
146
subparsers .add_parser (
144
147
"help" ,
145
148
description = "ga4gh_server help" ,
146
149
help = "show this help message and exit" )
147
- # Wormtable backend
148
- wtbParser = subparsers .add_parser (
150
+
151
+
152
+ def addWormtableParser (subparsers ):
153
+ parser = subparsers .add_parser (
149
154
"wormtable" ,
150
155
description = "Serve the API using a wormtable based backend." ,
151
156
help = "Serve data from tables." )
152
- wtbParser .add_argument (
157
+ parser .add_argument (
153
158
"dataDir" ,
154
159
help = "The directory containing the wormtables to be served." )
155
- wtbParser .set_defaults (variantSetClass = variants .WormtableVariantSet )
156
- # Tabix
157
- tabixParser = subparsers .add_parser (
160
+ parser .set_defaults (variantSetClass = variants .WormtableVariantSet )
161
+ return parser
162
+
163
+
164
+ def addTabixParser (subparsers ):
165
+ parser = subparsers .add_parser (
158
166
"tabix" ,
159
167
description = "Serve the API using a tabix based backend." ,
160
168
help = "Serve data from Tabix indexed VCFs" )
161
- tabixParser .add_argument (
169
+ parser .add_argument (
162
170
"dataDir" ,
163
171
help = "The directory containing VCFs" )
164
- tabixParser .set_defaults (variantSetClass = variants .TabixVariantSet )
172
+ parser .set_defaults (variantSetClass = variants .TabixVariantSet )
173
+ return parser
174
+
165
175
176
+ def server_main (parser = None ):
177
+ if parser is None :
178
+ parser = argparse .ArgumentParser (
179
+ description = "GA4GH reference server" )
180
+ addGlobalOptions (parser )
181
+ subparsers = parser .add_subparsers (title = 'subcommands' ,)
182
+ addServerHelpParser (subparsers )
183
+ addWormtableParser (subparsers )
184
+ addTabixParser (subparsers )
166
185
args = parser .parse_args ()
167
186
if "variantSetClass" not in args :
168
187
parser .print_help ()
@@ -172,6 +191,7 @@ def server_main(parser=None):
172
191
args .dataDir , args .variantSetClass )
173
192
frontend .app .run (host = "0.0.0.0" , port = args .port , debug = True )
174
193
194
+
175
195
##############################################################################
176
196
# Client
177
197
##############################################################################
@@ -182,7 +202,9 @@ class AbstractQueryRunner(object):
182
202
Abstract base class for runner classes
183
203
"""
184
204
def __init__ (self , args ):
185
- self ._workarounds = set (args .workarounds .split (',' ))
205
+ self ._workarounds = set ()
206
+ if args .workarounds is not None :
207
+ self ._workarounds = set (args .workarounds .split (',' ))
186
208
self ._key = args .key
187
209
self ._verbosity = args .verbose
188
210
self ._httpClient = client .HttpClient (
@@ -256,6 +278,15 @@ class SearchVariantsRunner(AbstractSearchRunner):
256
278
def __init__ (self , args ):
257
279
super (SearchVariantsRunner , self ).__init__ (args )
258
280
request = RequestFactory (args ).createGASearchVariantsRequest ()
281
+ # if no variantSets have been specified, send a request to
282
+ # the server to grab all variantSets and then continue
283
+ if args .variantSetIds is None :
284
+ variantSetsRequest = protocol .GASearchVariantSetsRequest ()
285
+ response = self ._httpClient .searchVariantSets (variantSetsRequest )
286
+ variantSetIds = [variantSet .id for variantSet in response ]
287
+ request .variantSetIds = variantSetIds
288
+ else :
289
+ setCommaSeparatedAttribute (request , args , 'variantSetIds' )
259
290
self ._setRequest (request , args )
260
291
261
292
def run (self ):
@@ -456,7 +487,7 @@ def addVariantSearchOptions(parser):
456
487
457
488
def addVariantSetIdsArgument (parser ):
458
489
parser .add_argument (
459
- "--variantSetIds" , "-V" ,
490
+ "--variantSetIds" , "-V" , default = None ,
460
491
help = "The variant set id(s) to search over" )
461
492
462
493
@@ -468,7 +499,7 @@ def addStartArgument(parser):
468
499
469
500
def addEndArgument (parser ):
470
501
parser .add_argument (
471
- "--end" , "-e" , default = 1 , type = int ,
502
+ "--end" , "-e" , default = AVRO_LONG_MAX , type = int ,
472
503
help = "The end of the search range (exclusive)." )
473
504
474
505
@@ -521,7 +552,7 @@ def addNameArgument(parser):
521
552
def addClientGlobalOptions (parser ):
522
553
parser .add_argument ('--verbose' , '-v' , action = 'count' , default = 0 )
523
554
parser .add_argument (
524
- "--workarounds" , "-w" , default = '' , help = "The workarounds to use" )
555
+ "--workarounds" , "-w" , default = None , help = "The workarounds to use" )
525
556
parser .add_argument (
526
557
"--key" , "-k" , help = "The auth key to use" )
527
558
parser .add_argument (
0 commit comments