Exemplo n.º 1
0
    def testArgs(self):
        """
        It must be possible to parse command line arguments to create a new
        instance of FindParameters.
        """
        parser = argparse.ArgumentParser()
        FindParameters.addArgsToParser(parser)
        args = parser.parse_args([
            '--significanceMethod',
            'Always',
            '--significanceFraction',
            '0.4',
            '--binScoreMethod',
            'MinHashesScore',
            '--featureMatchScore',
            '5',
            '--featureMismatchScore',
            '6',
            '--weights',
            'AlphaHelix 2',
            '--deltaScale',
            '0.2',
        ])

        # Parsing must do the expected thing.
        self.assertEqual('Always', args.significanceMethod)
        self.assertEqual(0.4, args.significanceFraction)
        self.assertEqual('MinHashesScore', args.binScoreMethod)
        self.assertEqual(5, args.featureMatchScore)
        self.assertEqual(6, args.featureMismatchScore)
        self.assertEqual(0.2, args.deltaScale)

        # We must be able to make an instance from the parsed args.
        findParams = FindParameters.fromArgs(args)
        self.assertEqual('Always', findParams.significanceMethod)
        self.assertEqual(0.4, findParams.significanceFraction)
        self.assertEqual('MinHashesScore', findParams.binScoreMethod)
        self.assertEqual(5, findParams.featureMatchScore)
        self.assertEqual(6, findParams.featureMismatchScore)
        self.assertEqual(0.2, findParams.deltaScale)
Exemplo n.º 2
0
        help=('A test id prefix. Tests whose ids do not contain this pattern '
              'will not be run. The pattern is case-sensitive.'))

    FindParameters.addArgsToParser(parser)
    DatabaseParameters.addArgsToParser(parser)

    args = parser.parse_args()

    # If no parameter sets were specified, use the ones on the command line.
    if not args.parameterSets:
        args.parameterSets = ['command-line']

    if 'command-line' in args.parameterSets:
        PARAMETER_SETS['command-line'] = {
            'dbParams': DatabaseParameters.fromArgs(args),
            'findParams': FindParameters.fromArgs(args),
        }

    if args.printParams:
        for parameterSet in args.parameterSets:
            print('Parameter set %r' % parameterSet, file=sys.stderr)
            params = PARAMETER_SETS[parameterSet]
            print(params['dbParams'].print_(margin='  '), file=sys.stderr)
            print(params['findParams'].print_(margin='  '), file=sys.stderr)

    # Make the command-line args available to the tests. There doesn't seem
    # to be another way to pass information like this when using a unittest
    # test suite.
    light.performance.testArgs = args

    suite = unittest.defaultTestLoader.discover(args.startDir,
        for i, feature in enumerate(ALL_FEATURES):
            print(ALL_FEATURES[i][0], '\t', ALL_FEATURES[i][1], '\t',
                  COLORS[i])

    if args.params:
        givenParams = []
        for paramsStr in args.params:
            paramsParser = argparse.ArgumentParser()
            # Change '+' to ' ' to make it easy to specify finders that
            # have a space in their names.
            subArgs = [arg.replace('+', ' ') for arg in paramsStr.split()]
            FindParameters.addArgsToParser(paramsParser)
            DatabaseParameters.addArgsToParser(paramsParser)
            paramArgs = paramsParser.parse_args(subArgs)
            dbParams = DatabaseParameters.fromArgs(paramArgs)
            findParams = FindParameters.fromArgs(paramArgs)
            givenParams.append((dbParams, findParams))

        if len(givenParams) < len(args.structureNames):
            # We were given fewer parameter sets than structures.  Re-use
            # the final given parameters for structures that don't have a
            # correspondign set of given parameters.
            params = ichain(givenParams, repeat(givenParams[-1]))
        else:
            params = givenParams
    else:
        # The parameter settings for all structures will be the defaults.
        params = zip(repeat(DatabaseParameters()), repeat(FindParameters()))

    first = True