Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #19 from dcolligan/new_common
Browse files Browse the repository at this point in the history
Use newer ga4gh-* packages
  • Loading branch information
dcolligan authored Oct 28, 2016
2 parents 0fd4375 + eb67f51 commit 80f6def
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 90 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ cache:
install:
- pip install pip --upgrade
- pip install setuptools
- pip install ga4gh-common # need ga4gh_common.setup for sdist
- python setup.py sdist
- pip install dist/ga4gh_client*.tar.gz
# every installable in setup.py's entry_points should be tested here
Expand All @@ -29,3 +28,7 @@ script:
--cover-branches --cover-erase
- make clean -C docs
- make html -C docs

after_success:
# run codecov
- bash <(curl -s https://codecov.io/bash)
108 changes: 31 additions & 77 deletions ga4gh_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import json
import logging
import requests
import argparse
import operator

import ga4gh_client
import ga4gh_client.client as client
import ga4gh_client.exceptions as exceptions
import ga4gh_client.protocol as protocol

import ga4gh_common.cli as cli


###############
# Common
Expand All @@ -25,52 +25,12 @@
AVRO_LONG_MAX = 2**31 - 1


class SortedHelpFormatter(argparse.HelpFormatter):
"""
An argparse HelpFormatter that sorts the flags and subcommands
in alphabetical order
"""
def add_arguments(self, actions):
"""
Sort the flags alphabetically
"""
actions = sorted(
actions, key=operator.attrgetter('option_strings'))
super(SortedHelpFormatter, self).add_arguments(actions)

def _iter_indented_subactions(self, action):
"""
Sort the subcommands alphabetically
"""
try:
get_subactions = action._get_subactions
except AttributeError:
pass
else:
self._indent()
if isinstance(action, argparse._SubParsersAction):
for subaction in sorted(
get_subactions(), key=lambda x: x.dest):
yield subaction
else:
for subaction in get_subactions():
yield subaction
self._dedent()


def addDisableUrllibWarningsArgument(parser):
parser.add_argument(
"--disable-urllib-warnings", default=False, action="store_true",
help="Disable urllib3 warnings")


def createArgumentParser(description):
parser = argparse.ArgumentParser(
description=description,
formatter_class=SortedHelpFormatter)
return parser


def addVersionArgument(parser):
# TODO argparse strips newlines from version output
versionString = (
Expand All @@ -81,12 +41,6 @@ def addVersionArgument(parser):
"--version", version=versionString, action="version")


def addSubparser(subparsers, subcommand, description):
parser = subparsers.add_parser(
subcommand, description=description, help=description)
return parser


###############
# Client
###############
Expand Down Expand Up @@ -1262,7 +1216,7 @@ def addHelpParser(subparsers):


def addVariantsSearchParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "variants-search", "Search for variants")
parser.set_defaults(runner=SearchVariantsRunner)
addUrlArgument(parser)
Expand All @@ -1272,7 +1226,7 @@ def addVariantsSearchParser(subparsers):


def addVariantSetsSearchParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "variantsets-search", "Search for variantSets")
parser.set_defaults(runner=SearchVariantSetsRunner)
addOutputFormatArgument(parser)
Expand Down Expand Up @@ -1308,42 +1262,42 @@ def addVariantAnnotationSetsSearchParser(subparsers):


def addVariantAnnotationSetsGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "variantannotationsets-get", "Get a variantAnnotationSet")
parser.set_defaults(runner=GetVariantAnnotationSetRunner)
addGetArguments(parser)


def addVariantSetsGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "variantsets-get", "Get a variantSet")
parser.set_defaults(runner=GetVariantSetRunner)
addGetArguments(parser)


def addFeaturesGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "features-get", "Get a feature by ID")
parser.set_defaults(runner=GetFeatureRunner)
addGetArguments(parser)


def addFeatureSetsGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "featuresets-get", "Get a featureSet by ID")
parser.set_defaults(runner=GetFeatureSetRunner)
addGetArguments(parser)


def addBioSamplesGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "biosamples-get", "Get a biosample by ID")
parser.set_defaults(runner=GetBioSampleRunner)
addGetArguments(parser)


def addIndividualsGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "individuals-get", "Get a individual by ID")
parser.set_defaults(runner=GetIndividualRunner)
addGetArguments(parser)
Expand Down Expand Up @@ -1405,7 +1359,7 @@ def addFeatureSetsSearchParser(subparsers):


def addReferenceSetsSearchParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "referencesets-search", "Search for referenceSets")
parser.set_defaults(runner=SearchReferenceSetsRunner)
addUrlArgument(parser)
Expand All @@ -1420,7 +1374,7 @@ def addReferenceSetsSearchParser(subparsers):


def addReferencesSearchParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "references-search", "Search for references")
parser.set_defaults(runner=SearchReferencesRunner)
addUrlArgument(parser)
Expand All @@ -1433,7 +1387,7 @@ def addReferencesSearchParser(subparsers):


def addReadGroupSetsSearchParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "readgroupsets-search", "Search for readGroupSets")
parser.set_defaults(runner=SearchReadGroupSetsRunner)
addUrlArgument(parser)
Expand All @@ -1446,7 +1400,7 @@ def addReadGroupSetsSearchParser(subparsers):


def addCallSetsSearchParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "callsets-search", "Search for callSets")
parser.set_defaults(runner=SearchCallSetsRunner)
addUrlArgument(parser)
Expand All @@ -1459,7 +1413,7 @@ def addCallSetsSearchParser(subparsers):


def addReadsSearchParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "reads-search", "Search for reads")
parser.set_defaults(runner=SearchReadsRunner)
addOutputFormatArgument(parser)
Expand All @@ -1468,14 +1422,14 @@ def addReadsSearchParser(subparsers):


def addDatasetsGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "datasets-get", "Get a dataset")
parser.set_defaults(runner=GetDatasetRunner)
addGetArguments(parser)


def addDatasetsSearchParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "datasets-search", "Search for datasets")
parser.set_defaults(runner=SearchDatasetsRunner)
addUrlArgument(parser)
Expand All @@ -1498,71 +1452,71 @@ def addReadsSearchParserArguments(parser):


def addReferenceSetsGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "referencesets-get", "Get a referenceset")
parser.set_defaults(runner=GetReferenceSetRunner)
addGetArguments(parser)


def addReferencesGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "references-get", "Get a reference")
parser.set_defaults(runner=GetReferenceRunner)
addGetArguments(parser)


def addReadGroupSetsGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "readgroupsets-get", "Get a read group set")
parser.set_defaults(runner=GetReadGroupSetRunner)
addGetArguments(parser)


def addReadGroupsGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "readgroups-get", "Get a read group")
parser.set_defaults(runner=GetReadGroupRunner)
addGetArguments(parser)


def addCallSetsGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "callsets-get", "Get a callSet")
parser.set_defaults(runner=GetCallSetRunner)
addGetArguments(parser)


def addVariantsGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "variants-get", "Get a variant")
parser.set_defaults(runner=GetVariantRunner)
addGetArguments(parser)


def addRnaQuantificationSetGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "rnaquantificationsets-get",
"Get a rna quantification set")
parser.set_defaults(runner=GetRnaQuantificationSetRunner)
addGetArguments(parser)


def addRnaQuantificationGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "rnaquantifications-get", "Get a rna quantification")
parser.set_defaults(runner=GetRnaQuantificationRunner)
addGetArguments(parser)


def addExpressionLevelGetParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "expressionlevels-get", "Get a expression level")
parser.set_defaults(runner=GetExpressionLevelRunner)
addGetArguments(parser)


def addReferencesBasesListParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "references-list-bases", "List bases of a reference")
parser.add_argument(
"--outputFormat", "-O", choices=['text', 'fasta'], default="text",
Expand Down Expand Up @@ -1625,7 +1579,7 @@ def addExpressionLevelsSearchParser(subparsers):


def addGenotypePhenotypeSearchParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "genotypephenotype-search",
"Search for genotype to phenotype associations")
parser.set_defaults(runner=SearchGenotypePhenotypeRunner)
Expand All @@ -1637,7 +1591,7 @@ def addGenotypePhenotypeSearchParser(subparsers):


def addPhenotypeSearchParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "phenotype-search", "Search for phenotypes")
parser.set_defaults(runner=SearchPhenotypeRunner)
addUrlArgument(parser)
Expand All @@ -1648,7 +1602,7 @@ def addPhenotypeSearchParser(subparsers):


def addPhenotypeAssociationSetsSearchParser(subparsers):
parser = addSubparser(
parser = cli.addSubparser(
subparsers, "phenotypeassociationsets-search",
"Search for phenotypeassociationsets")
parser.set_defaults(runner=SearchPhenotypeAssociationSetsRunner)
Expand All @@ -1659,7 +1613,7 @@ def addPhenotypeAssociationSetsSearchParser(subparsers):


def getClientParser():
parser = createArgumentParser("GA4GH reference client")
parser = cli.createArgumentParser("GA4GH reference client")
addClientGlobalOptions(parser)
subparsers = parser.add_subparsers(title='subcommands',)
addHelpParser(subparsers)
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# These requirements are read directly into setup.py, so specify them
# in the order that they should be in in setup.py
ga4gh_common
ga4gh_schemas
ga4gh_common==0.0.4
ga4gh_schemas==0.0.7
requests
protobuf==3.0.0b3
Loading

0 comments on commit 80f6def

Please sign in to comment.