def run_tests_main(): parser = cli.createArgumentParser("runs tests for a ga4gh package") versionString = "GA4GH Runtests Version {}".format( ga4gh.common.__version__) parser.add_argument("--version", version=versionString, action="version") parser.parse_args() travisSimulator = TravisSimulator() travisSimulator.runTests()
def testArgumentParser(self): parser = cli.createArgumentParser("test parser") subparsers = parser.add_subparsers(title='subparsers') subparserName = "test-subparser" subparser = cli.addSubparser( subparsers, subparserName, "test subparser") argumentName = 'argument' subparser.add_argument(argumentName) parser.parse_args([subparserName, argumentName])
def configtest_main(parser=None): if parser is None: parser = common_cli.createArgumentParser( "GA4GH server configuration validator") parser.add_argument("--config", "-c", default='DevelopmentConfig', type=str, help="The configuration to use") parser.add_argument("--config-file", "-f", type=str, default=None, help="The configuration file to use") cli.addVersionArgument(parser) args = parser.parse_args() configStr = 'ga4gh.serverconfig:{0}'.format(args.config) configtest.TestConfig.configStr = configStr configtest.TestConfig.configFile = args.config_file configtest.TestConfig.configEnv = "GA4GH_CONFIGURATION" loader = unittest.TestLoader() tests = loader.loadTestsFromModule(configtest) results = SimplerResult() tests.run(results) logging.basicConfig(level=logging.INFO) log = logging.getLogger(__name__) log.info('{0} Tests run. {1} errors, {2} failures, {3} skipped'.format( results.testsRun, len(results.errors), len(results.failures), len(results.skipped))) for result in results.errors: if result is not None: log.critical('Error: {0}: {1}'.format(result[0].id(), result[1])) for result in results.failures: if result is not None: log.critical('Failure: {0}: {1}'.format(result[0].id(), result[1])) for result in results.skipped: if result is not None: log.info('Skipped: {0}: {1}'.format(result[0].id(), result[1]))
def getGa2VcfParser(): parser = common_cli.createArgumentParser(( "GA4GH VCF conversion tool. Converts variant information " "stored in a GA4GH repository into VCF format.")) cli_client.addClientGlobalOptions(parser) cli.addOutputFileArgument(parser) cli_client.addUrlArgument(parser) parser.add_argument("variantSetId", help="The variant set to convert") parser.add_argument( "--outputFormat", "-O", choices=['vcf', 'bcf'], default="vcf", help=( "The format for object output. Currently supported are " "'vcf' (default), which is a text-based format and " "'bcf', which is the binary equivalent")) cli_client.addReferenceNameArgument(parser) cli_client.addCallSetIdsArgument(parser) cli_client.addStartArgument(parser) cli_client.addEndArgument(parser) cli_client.addPageSizeArgument(parser) return parser
def configtest_main(parser=None): if parser is None: parser = common_cli.createArgumentParser( "GA4GH server configuration validator") parser.add_argument( "--config", "-c", default='DevelopmentConfig', type=str, help="The configuration to use") parser.add_argument( "--config-file", "-f", type=str, default=None, help="The configuration file to use") cli.addVersionArgument(parser) args = parser.parse_args() configStr = 'ga4gh.serverconfig:{0}'.format(args.config) configtest.TestConfig.configStr = configStr configtest.TestConfig.configFile = args.config_file configtest.TestConfig.configEnv = "GA4GH_CONFIGURATION" loader = unittest.TestLoader() tests = loader.loadTestsFromModule(configtest) results = SimplerResult() tests.run(results) logging.basicConfig(level=logging.INFO) log = logging.getLogger(__name__) log.info('{0} Tests run. {1} errors, {2} failures, {3} skipped'. format(results.testsRun, len(results.errors), len(results.failures), len(results.skipped))) for result in results.errors: if result is not None: log.critical('Error: {0}: {1}'.format(result[0].id(), result[1])) for result in results.failures: if result is not None: log.critical('Failure: {0}: {1}'.format(result[0].id(), result[1])) for result in results.skipped: if result is not None: log.info('Skipped: {0}: {1}'.format(result[0].id(), result[1]))
def getGa2SamParser(): parser = common_cli.createArgumentParser("GA4GH SAM conversion tool") cli_client.addClientGlobalOptions(parser) cli_client.addUrlArgument(parser) parser.add_argument("readGroupId", help="The ReadGroup to convert to SAM/BAM format.") cli_client.addPageSizeArgument(parser) cli_client.addStartArgument(parser) cli_client.addEndArgument(parser) parser.add_argument("--referenceId", default=None, help="The referenceId to search over") parser.add_argument( "--outputFormat", "-O", default="sam", choices=["sam", "bam"], help=("The format for object output. Currently supported are " "'sam' (default), which is a text-based format and " "'bam', which is the binary equivalent")) cli.addOutputFileArgument(parser) return parser
def getParser(cls): parser = common_cli.createArgumentParser( "GA4GH data repository management tool") subparsers = parser.add_subparsers(title='subcommands',) cli.addVersionArgument(parser) initParser = common_cli.addSubparser( subparsers, "init", "Initialize a data repository") initParser.set_defaults(runner="init") cls.addRepoArgument(initParser) cls.addForceOption(initParser) verifyParser = common_cli.addSubparser( subparsers, "verify", "Verifies the repository by examing all data files") verifyParser.set_defaults(runner="verify") cls.addRepoArgument(verifyParser) listParser = common_cli.addSubparser( subparsers, "list", "List the contents of the repo") listParser.set_defaults(runner="list") cls.addRepoArgument(listParser) addDatasetParser = common_cli.addSubparser( subparsers, "add-dataset", "Add a dataset to the data repo") addDatasetParser.set_defaults(runner="addDataset") cls.addRepoArgument(addDatasetParser) cls.addDatasetNameArgument(addDatasetParser) cls.addAttributesArgument(addDatasetParser) cls.addDescriptionOption(addDatasetParser, "dataset") removeDatasetParser = common_cli.addSubparser( subparsers, "remove-dataset", "Remove a dataset from the data repo") removeDatasetParser.set_defaults(runner="removeDataset") cls.addRepoArgument(removeDatasetParser) cls.addDatasetNameArgument(removeDatasetParser) cls.addForceOption(removeDatasetParser) objectType = "reference set" addReferenceSetParser = common_cli.addSubparser( subparsers, "add-referenceset", "Add a reference set to the data repo") addReferenceSetParser.set_defaults(runner="addReferenceSet") cls.addRepoArgument(addReferenceSetParser) cls.addFilePathArgument( addReferenceSetParser, "The path of the FASTA file to use as a reference set. This " "file must be bgzipped and indexed.") cls.addAttributesArgument(addReferenceSetParser) cls.addRelativePathOption(addReferenceSetParser) cls.addNameOption(addReferenceSetParser, objectType) cls.addDescriptionOption(addReferenceSetParser, objectType) addReferenceSetParser.add_argument( "--species", default=None, help="The species ontology term as a JSON string") addReferenceSetParser.add_argument( "--isDerived", default=False, type=bool, help="Indicates if this reference set is derived from another") addReferenceSetParser.add_argument( "--assemblyId", default=None, help="The assembly id") addReferenceSetParser.add_argument( "--sourceAccessions", default=None, help="The source accessions (pass as comma-separated list)") addReferenceSetParser.add_argument( "--sourceUri", default=None, help="The source URI") removeReferenceSetParser = common_cli.addSubparser( subparsers, "remove-referenceset", "Remove a reference set from the repo") removeReferenceSetParser.set_defaults(runner="removeReferenceSet") cls.addRepoArgument(removeReferenceSetParser) removeReferenceSetParser.add_argument( "referenceSetName", help="the name of the reference set") cls.addForceOption(removeReferenceSetParser) objectType = "ReadGroupSet" addReadGroupSetParser = common_cli.addSubparser( subparsers, "add-readgroupset", "Add a read group set to the data repo") addReadGroupSetParser.set_defaults(runner="addReadGroupSet") cls.addRepoArgument(addReadGroupSetParser) cls.addDatasetNameArgument(addReadGroupSetParser) cls.addNameOption(addReadGroupSetParser, objectType) cls.addReferenceSetNameOption(addReadGroupSetParser, "ReadGroupSet") cls.addAttributesArgument(addReadGroupSetParser) cls.addRelativePathOption(addReadGroupSetParser) addReadGroupSetParser.add_argument( "dataFile", help="The file path or URL of the BAM file for this ReadGroupSet") addReadGroupSetParser.add_argument( "-I", "--indexFile", default=None, help=( "The file path of the BAM index for this ReadGroupSet. " "If the dataFile argument is a local file, this will " "be automatically inferred by appending '.bai' to the " "file name. If the dataFile is a remote URL the path to " "a local file containing the BAM index must be provided")) addOntologyParser = common_cli.addSubparser( subparsers, "add-ontology", "Adds an ontology in OBO format to the repo. Currently, " "a sequence ontology (SO) instance is required to translate " "ontology term names held in annotations to ontology IDs. " "Sequence ontology files can be found at " "https://github.com/The-Sequence-Ontology/SO-Ontologies") addOntologyParser.set_defaults(runner="addOntology") cls.addRepoArgument(addOntologyParser) cls.addFilePathArgument( addOntologyParser, "The path of the OBO file defining this ontology.") cls.addRelativePathOption(addOntologyParser) cls.addNameOption(addOntologyParser, "ontology") removeOntologyParser = common_cli.addSubparser( subparsers, "remove-ontology", "Remove an ontology from the repo") removeOntologyParser.set_defaults(runner="removeOntology") cls.addRepoArgument(removeOntologyParser) cls.addOntologyNameArgument(removeOntologyParser) cls.addForceOption(removeOntologyParser) removeReadGroupSetParser = common_cli.addSubparser( subparsers, "remove-readgroupset", "Remove a read group set from the repo") removeReadGroupSetParser.set_defaults(runner="removeReadGroupSet") cls.addRepoArgument(removeReadGroupSetParser) cls.addDatasetNameArgument(removeReadGroupSetParser) cls.addReadGroupSetNameArgument(removeReadGroupSetParser) cls.addForceOption(removeReadGroupSetParser) objectType = "VariantSet" addVariantSetParser = common_cli.addSubparser( subparsers, "add-variantset", "Add a variant set to the data repo based on one or " "more VCF files. ") addVariantSetParser.set_defaults(runner="addVariantSet") cls.addRepoArgument(addVariantSetParser) cls.addDatasetNameArgument(addVariantSetParser) cls.addRelativePathOption(addVariantSetParser) addVariantSetParser.add_argument( "dataFiles", nargs="+", help=( "The VCF/BCF files representing the new VariantSet. " "These may be specified either one or more paths " "to local files or remote URLS, or as a path to " "a local directory containing VCF files. Either " "a single directory argument may be passed or a " "list of file paths/URLS, but not a mixture of " "directories and paths.") ) addVariantSetParser.add_argument( "-I", "--indexFiles", nargs="+", metavar="indexFiles", help=( "The index files for the VCF/BCF files provided in " "the dataFiles argument. These must be provided in the " "same order as the data files.")) cls.addNameOption(addVariantSetParser, objectType) cls.addReferenceSetNameOption(addVariantSetParser, objectType) cls.addSequenceOntologyNameOption(addVariantSetParser, objectType) cls.addAttributesArgument(addVariantSetParser) addVariantSetParser.add_argument( "-a", "--addAnnotationSets", action="store_true", help=( "If the supplied VCF file contains annotations, create the " "corresponding VariantAnnotationSet.")) removeVariantSetParser = common_cli.addSubparser( subparsers, "remove-variantset", "Remove a variant set from the repo") removeVariantSetParser.set_defaults(runner="removeVariantSet") cls.addRepoArgument(removeVariantSetParser) cls.addDatasetNameArgument(removeVariantSetParser) cls.addVariantSetNameArgument(removeVariantSetParser) cls.addForceOption(removeVariantSetParser) addFeatureSetParser = common_cli.addSubparser( subparsers, "add-featureset", "Add a feature set to the data repo") addFeatureSetParser.set_defaults(runner="addFeatureSet") cls.addRepoArgument(addFeatureSetParser) cls.addDatasetNameArgument(addFeatureSetParser) cls.addAttributesArgument(addFeatureSetParser) cls.addRelativePathOption(addFeatureSetParser) cls.addFilePathArgument( addFeatureSetParser, "The path to the converted SQLite database containing Feature " "data") cls.addReferenceSetNameOption(addFeatureSetParser, "feature set") cls.addSequenceOntologyNameOption(addFeatureSetParser, "feature set") cls.addClassNameOption(addFeatureSetParser, "feature set") removeFeatureSetParser = common_cli.addSubparser( subparsers, "remove-featureset", "Remove a feature set from the repo") removeFeatureSetParser.set_defaults(runner="removeFeatureSet") cls.addRepoArgument(removeFeatureSetParser) cls.addDatasetNameArgument(removeFeatureSetParser) cls.addFeatureSetNameArgument(removeFeatureSetParser) cls.addForceOption(removeFeatureSetParser) addBiosampleParser = common_cli.addSubparser( subparsers, "add-biosample", "Add a Biosample to the dataset") addBiosampleParser.set_defaults(runner="addBiosample") cls.addRepoArgument(addBiosampleParser) cls.addDatasetNameArgument(addBiosampleParser) cls.addBiosampleNameArgument(addBiosampleParser) cls.addBiosampleArgument(addBiosampleParser) removeBiosampleParser = common_cli.addSubparser( subparsers, "remove-biosample", "Remove a Biosample from the repo") removeBiosampleParser.set_defaults(runner="removeBiosample") cls.addRepoArgument(removeBiosampleParser) cls.addDatasetNameArgument(removeBiosampleParser) cls.addBiosampleNameArgument(removeBiosampleParser) cls.addForceOption(removeBiosampleParser) addIndividualParser = common_cli.addSubparser( subparsers, "add-individual", "Add an Individual to the dataset") addIndividualParser.set_defaults(runner="addIndividual") cls.addRepoArgument(addIndividualParser) cls.addDatasetNameArgument(addIndividualParser) cls.addIndividualNameArgument(addIndividualParser) cls.addIndividualArgument(addIndividualParser) removeIndividualParser = common_cli.addSubparser( subparsers, "remove-individual", "Remove an Individual from the repo") removeIndividualParser.set_defaults(runner="removeIndividual") cls.addRepoArgument(removeIndividualParser) cls.addDatasetNameArgument(removeIndividualParser) cls.addIndividualNameArgument(removeIndividualParser) cls.addForceOption(removeIndividualParser) objectType = "RnaQuantification" addRnaQuantificationParser = common_cli.addSubparser( subparsers, "add-rnaquantification", "Add an RNA quantification to the data repo") addRnaQuantificationParser.set_defaults( runner="addRnaQuantification") cls.addFilePathArgument( addRnaQuantificationParser, "The path to the RNA SQLite database to create or modify") cls.addQuantificationFilePathArgument( addRnaQuantificationParser, "The path to the expression file.") cls.addRnaFormatArgument(addRnaQuantificationParser) cls.addRepoArgument(addRnaQuantificationParser) cls.addDatasetNameArgument(addRnaQuantificationParser) addRnaQuantificationParser.add_argument( "--biosampleName", default=None, help="Biosample Name") addRnaQuantificationParser.add_argument( "--readGroupSetName", default=None, help="Read Group Set Name") addRnaQuantificationParser.add_argument( "--featureSetNames", default=None, help="Comma separated list") cls.addNameOption(addRnaQuantificationParser, "rna quantification") cls.addDescriptionOption(addRnaQuantificationParser, objectType) cls.addRnaFeatureTypeOption(addRnaQuantificationParser) cls.addAttributesArgument(addRnaQuantificationParser) objectType = "RnaQuantificationSet" initRnaQuantificationSetParser = common_cli.addSubparser( subparsers, "init-rnaquantificationset", "Initializes an RNA quantification set") initRnaQuantificationSetParser.set_defaults( runner="initRnaQuantificationSet") cls.addRepoArgument(initRnaQuantificationSetParser) cls.addFilePathArgument( initRnaQuantificationSetParser, "The path to the resulting Quantification Set") addRnaQuantificationSetParser = common_cli.addSubparser( subparsers, "add-rnaquantificationset", "Add an RNA quantification set to the data repo") addRnaQuantificationSetParser.set_defaults( runner="addRnaQuantificationSet") cls.addRepoArgument(addRnaQuantificationSetParser) cls.addDatasetNameArgument(addRnaQuantificationSetParser) cls.addFilePathArgument( addRnaQuantificationSetParser, "The path to the converted SQLite database containing RNA data") cls.addReferenceSetNameOption( addRnaQuantificationSetParser, objectType) cls.addNameOption(addRnaQuantificationSetParser, objectType) cls.addAttributesArgument(addRnaQuantificationSetParser) removeRnaQuantificationSetParser = common_cli.addSubparser( subparsers, "remove-rnaquantificationset", "Remove an RNA quantification set from the repo") removeRnaQuantificationSetParser.set_defaults( runner="removeRnaQuantificationSet") cls.addRepoArgument(removeRnaQuantificationSetParser) cls.addDatasetNameArgument(removeRnaQuantificationSetParser) cls.addRnaQuantificationSetNameArgument( removeRnaQuantificationSetParser) cls.addForceOption(removeRnaQuantificationSetParser) addPhenotypeAssociationSetParser = common_cli.addSubparser( subparsers, "add-phenotypeassociationset", "Adds phenotypes in ttl format to the repo.") addPhenotypeAssociationSetParser.set_defaults( runner="addPhenotypeAssociationSet") cls.addRepoArgument(addPhenotypeAssociationSetParser) cls.addDatasetNameArgument(addPhenotypeAssociationSetParser) cls.addDirPathArgument( addPhenotypeAssociationSetParser, "The path of the directory containing ttl files.") cls.addNameOption( addPhenotypeAssociationSetParser, "PhenotypeAssociationSet") cls.addAttributesArgument(addPhenotypeAssociationSetParser) removePhenotypeAssociationSetParser = common_cli.addSubparser( subparsers, "remove-phenotypeassociationset", "Remove an phenotypes from the repo") removePhenotypeAssociationSetParser.set_defaults( runner="removePhenotypeAssociationSet") cls.addRepoArgument(removePhenotypeAssociationSetParser) cls.addDatasetNameArgument(removePhenotypeAssociationSetParser) cls.addNameArgument( removePhenotypeAssociationSetParser, "phenotype association set") cls.addForceOption(removePhenotypeAssociationSetParser) return parser
def getServerParser(): parser = common_cli.createArgumentParser("GA4GH reference server") addServerOptions(parser) return parser