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))
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)
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)
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()))
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))
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)
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)