示例#1
0
    def testPopulationFromCommandLineSequencesAndFastaFile(self):
        """
        Using both command line sequences and --databaseFasta must result in
        all the command line subjects and those in the file being added to the
        returned database.
        """
        parser = argparse.ArgumentParser()
        specifier = DatabaseSpecifier()
        specifier.addArgsToParser(parser)
        args = parser.parse_args([
            '--databaseFasta', 'file.fasta', '--databaseSequence', 'id1 FFF',
            '--databaseSequence', 'id2 RRR'
        ])
        data = '\n'.join(['>id3', 'FFFF', '>id4', 'RRRR'])
        mockOpener = mockOpen(read_data=data)
        with patch.object(builtins, 'open', mockOpener):
            db = specifier.getDatabaseFromArgs(args)

        allSubjects = [subject.read for subject in db.getSubjects()]
        self.assertEqual(
            {
                AARead('id1', 'FFF'),
                AARead('id2', 'RRR'),
                AARead('id3', 'FFFF'),
                AARead('id4', 'RRRR'),
            }, set(allSubjects))
示例#2
0
 def testNoArgs(self):
     """
     If no arguments are given, getDatabaseFromArgs must return a database.
     """
     parser = argparse.ArgumentParser()
     specifier = DatabaseSpecifier()
     specifier.addArgsToParser(parser)
     args = parser.parse_args([])
     db = specifier.getDatabaseFromArgs(args)
     self.assertIsInstance(db, Database)
示例#3
0
 def testPassedParamsAreUsed(self):
     """
     If specific parameters are given, they must be used.
     """
     parser = argparse.ArgumentParser()
     specifier = DatabaseSpecifier()
     specifier.addArgsToParser(parser)
     args = parser.parse_args([])
     dbParams = DatabaseParameters()
     db = specifier.getDatabaseFromArgs(args, dbParams)
     self.assertIs(db.dbParams, dbParams)
示例#4
0
 def testNoArgsDefaultParameters(self):
     """
     The database returned from getDatabaseFromKeywords when it is
     passed no keywords must have the default database parameters.
     """
     parser = argparse.ArgumentParser()
     specifier = DatabaseSpecifier()
     specifier.addArgsToParser(parser)
     args = parser.parse_args([])
     db = specifier.getDatabaseFromArgs(args)
     self.assertIs(None, db.dbParams.compare(DatabaseParameters()))
示例#5
0
 def testPopulationFromCommandLineSequences(self):
     """
     Passing --databaseSequence arguments must result in the subjects in the
     sequences being added to the returned database.
     """
     parser = argparse.ArgumentParser()
     specifier = DatabaseSpecifier()
     specifier.addArgsToParser(parser)
     args = parser.parse_args(
         ['--databaseSequence', 'id1 FFF', '--databaseSequence', 'id2 RRR'])
     db = specifier.getDatabaseFromArgs(args)
     allSubjects = [subject.read for subject in db.getSubjects()]
     self.assertEqual(
         {AARead('id1', 'FFF'), AARead('id2', 'RRR')}, set(allSubjects))
示例#6
0
    def testPopulationFromFastaFile(self):
        """
        Passing a --databaseFasta argument must result in the subjects in the
        file being added to the returned database.
        """
        parser = argparse.ArgumentParser()
        specifier = DatabaseSpecifier()
        specifier.addArgsToParser(parser)
        args = parser.parse_args(['--databaseFasta', 'file.fasta'])
        data = '\n'.join(['>id1', 'FFF', '>id2', 'RRR'])
        mockOpener = mockOpen(read_data=data)
        with patch.object(builtins, 'open', mockOpener):
            db = specifier.getDatabaseFromArgs(args)

        allSubjects = [subject.read for subject in db.getSubjects()]
        self.assertEqual(
            {AARead('id1', 'FFF'), AARead('id2', 'RRR')}, set(allSubjects))
#!/usr/bin/env python

import argparse

from autobahn.asyncio.wamp import ApplicationRunner

from light.autobahn.database import DatabaseComponent
from light.database import DatabaseSpecifier

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='Start a WAMP-based distributed light-matter database.')

    databaseSpecifier = DatabaseSpecifier(allowInMemory=False)
    databaseSpecifier.addArgsToParser(parser)
    args = parser.parse_args()
    # We're always using WAMP for distributed databases.
    args.wampServer = True

    database = databaseSpecifier.getDatabaseFromArgs(args)
    runner = ApplicationRunner(args.wampUrl,
                               args.realm,
                               extra=dict(database=database))
    runner.run(DatabaseComponent)
示例#8
0
import argparse
from time import time

from light.database import DatabaseSpecifier
from light.parameters import DatabaseParameters

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description=('Create a light-matter database from sequences in a '
                     'FASTA file and/or given on the command line.'))

    databaseSpecifier = DatabaseSpecifier(allowInMemory=False)
    databaseSpecifier.addArgsToParser(parser)
    args = parser.parse_args()
    if args.filePrefix is None:
        parser.print_help()
        raise RuntimeError('You must supply a database save file prefix.')

    startTime = time()
    dbParams = DatabaseParameters.fromArgs(args)
    database = databaseSpecifier.getDatabaseFromArgs(args, dbParams)
    print(database.print_(), file=sys.stderr)
    print('Database built in %.2f seconds. Saving...' % (time() - startTime),
          end=' ',
          file=sys.stderr)

    # Save.
    saveStartTime = time()
    database.save()
    print('saved in %.2f seconds.' % (time() - saveStartTime), file=sys.stderr)