Skip to content

Commit fe7187f

Browse files
committed
no arg variants-search call returns all variants
Issue ga4gh#119
1 parent 8211c1d commit fe7187f

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

README.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ the downloaded datafile::
8787

8888
To run queries against this server, we can use the ``ga4gh_client`` program;
8989
for example, here we run the ``variants/search`` method over the
90-
``1000g_2013`` variant set, where the reference name is ``1``, the end coordinate
91-
is 60000 and we only want calls returned for call set ID HG03279::
90+
``1000g_2013`` variant set, where the reference name is ``1``
91+
and we only want calls returned for call set ID HG03279::
9292

93-
$ ga4gh_client variants-search http://localhost:8000/v0.5.1 -V 1000g_2013 -r 1 -e 60000 -c HG03279 | less -S
93+
$ ga4gh_client variants-search http://localhost:8000/v0.5.1 -V 1000g_2013 -r 1 -c HG03279 | less -S
9494

9595
We can also query against the *variant name*; here we return the variant that
9696
has variant name ``rs75454623``::
9797

98-
$ ga4gh_client variants-search http://localhost:8000/v0.5.1 -V 1000g_2013 -r 1 -e 60000 -n rs75454623 | less -S
98+
$ ga4gh_client variants-search http://localhost:8000/v0.5.1 -V 1000g_2013 -r 1 -n rs75454623 | less -S
9999

100100
+++++++++++++++++++++
101101
Converting 1000G data

ga4gh/cli.py

+50-19
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
import ga4gh.datamodel.variants as variants
1818

1919

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+
2028
def setCommaSeparatedAttribute(request, args, attr):
2129
attribute = getattr(args, attr)
2230
if attribute is not None:
@@ -122,11 +130,7 @@ def createGAListReferenceBasesRequest(self):
122130
##############################################################################
123131

124132

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):
130134
parser.add_argument(
131135
"--port", "-P", default=8000, type=int,
132136
help="The port to listen on")
@@ -137,32 +141,47 @@ def server_main(parser=None):
137141
"--config-file", "-F", type=str,
138142
help="The configuration file to use")
139143

140-
subparsers = parser.add_subparsers(title='subcommands',)
141144

142-
# help
145+
def addServerHelpParser(subparsers):
143146
subparsers.add_parser(
144147
"help",
145148
description="ga4gh_server help",
146149
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(
149154
"wormtable",
150155
description="Serve the API using a wormtable based backend.",
151156
help="Serve data from tables.")
152-
wtbParser.add_argument(
157+
parser.add_argument(
153158
"dataDir",
154159
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(
158166
"tabix",
159167
description="Serve the API using a tabix based backend.",
160168
help="Serve data from Tabix indexed VCFs")
161-
tabixParser.add_argument(
169+
parser.add_argument(
162170
"dataDir",
163171
help="The directory containing VCFs")
164-
tabixParser.set_defaults(variantSetClass=variants.TabixVariantSet)
172+
parser.set_defaults(variantSetClass=variants.TabixVariantSet)
173+
return parser
174+
165175

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)
166185
args = parser.parse_args()
167186
if "variantSetClass" not in args:
168187
parser.print_help()
@@ -172,6 +191,7 @@ def server_main(parser=None):
172191
args.dataDir, args.variantSetClass)
173192
frontend.app.run(host="0.0.0.0", port=args.port, debug=True)
174193

194+
175195
##############################################################################
176196
# Client
177197
##############################################################################
@@ -182,7 +202,9 @@ class AbstractQueryRunner(object):
182202
Abstract base class for runner classes
183203
"""
184204
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(','))
186208
self._key = args.key
187209
self._verbosity = args.verbose
188210
self._httpClient = client.HttpClient(
@@ -256,6 +278,15 @@ class SearchVariantsRunner(AbstractSearchRunner):
256278
def __init__(self, args):
257279
super(SearchVariantsRunner, self).__init__(args)
258280
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')
259290
self._setRequest(request, args)
260291

261292
def run(self):
@@ -456,7 +487,7 @@ def addVariantSearchOptions(parser):
456487

457488
def addVariantSetIdsArgument(parser):
458489
parser.add_argument(
459-
"--variantSetIds", "-V",
490+
"--variantSetIds", "-V", default=None,
460491
help="The variant set id(s) to search over")
461492

462493

@@ -468,7 +499,7 @@ def addStartArgument(parser):
468499

469500
def addEndArgument(parser):
470501
parser.add_argument(
471-
"--end", "-e", default=1, type=int,
502+
"--end", "-e", default=AVRO_LONG_MAX, type=int,
472503
help="The end of the search range (exclusive).")
473504

474505

@@ -521,7 +552,7 @@ def addNameArgument(parser):
521552
def addClientGlobalOptions(parser):
522553
parser.add_argument('--verbose', '-v', action='count', default=0)
523554
parser.add_argument(
524-
"--workarounds", "-w", default='', help="The workarounds to use")
555+
"--workarounds", "-w", default=None, help="The workarounds to use")
525556
parser.add_argument(
526557
"--key", "-k", help="The auth key to use")
527558
parser.add_argument(

tests/unit/test_cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def run(self, *args, **kwargs):
6464
def testVariantsSearchArguments(self):
6565
self.cliInput = """variants-search --referenceName REFERENCENAME
6666
--variantName VARIANTNAME --callSetIds CALL,SET,IDS --start 0
67-
--end 1 --pageSize 2"""
67+
--end 1 --pageSize 2 --variantSetIds VARIANT,SET,IDS"""
6868

6969
def testVariantSetsSearchArguments(self):
7070
self.cliInput = """variantsets-search --pageSize 1 --datasetIds

0 commit comments

Comments
 (0)