def createNewFile( self, fileName, # name of the new file force=False, # should we check to see if this is a wise move? ): """Create a new MacaronDB database file""" # make a basic file BaseFile.createNewFile(self, fileName, type="MacaronDB_DB", version=__MACARONDB_DB_VERSION__, force=force)
def createNewFile( self, fileName, # name of the new file force=False, # should we check to see if this is a wise move? ): """Create a new FootballDB database file""" # make a basic file BaseFile.createNewFile(self, fileName, type="FootballDB_DB", version=__FOOTBALLDB_DB_VERSION__, force=force) self._addTable('results', { "season": "INT", "week": "INT", "team_a": "TEXT", "team_b": "TEXT", "score_a": "INT", "score_b": "INT", }, force=True)
def createNewFile(self, fileName, # name of the new file force=False, # should we check to see if this is a wise move? ): """Create a new FootballDB database file""" # make a basic file BaseFile.createNewFile(self, fileName, type="FootballDB_DB", version=__FOOTBALLDB_DB_VERSION__, force=force) self._addTable('results', { "season" : "INT", "week" : "INT", "team_a" : "TEXT", "team_b" : "TEXT", "score_a" : "INT", "score_b" : "INT", }, force=True)
def __init__(self, verbosity=0): BaseFile.__init__(self, verbosity)
class BaseFileTests(unittest.TestCase): BF = BaseFile(verbosity=-1) def open(self): self.done() self.BF.openFile("test.dp") def done(self): if self.BF.isOpen(): self.BF.closeFile() def testCreation(self): self.BF.createNewFile("test.dp", "testing_db", "1.0", force=True) self.done() def testFileType(self): self.open() self.assertTrue(self.BF.getFileType() == "testing_db") self.done() def testVersioning(self): self.open() self.assertTrue(self.BF.getVersion() == "1.0") self.BF.logVersion("1.1") self.assertTrue(self.BF.getVersion() == "1.1") self.done() def testHistory(self): self.open() self.BF.logMessage("test message") (message, message_time) = self.BF.getMessages()[-1] self.assertTrue(message == "test message") time.sleep(1) self.BF.logMessage("test message2") messages = self.BF.getMessages(fromTime=message_time + 1) self.assertTrue(len(messages) == 1) (message, message_time) = messages[0] self.assertTrue(message == "test message2") self.done() def testAddTable(self): self.open() self.BF._addTable("testing", { "time": "INT", "thing": "TEXT", "size": "INT" }, force=True) self.done() def testInsert(self): self.open() IF = Interface("test.dp") IF.db = self.BF to_db = [(1, "cat", 5), (2, "dog", 6), (2, "fish", 8), (4, "goat", 0), (5, "fish", 12)] IF.insert('testing', ['time', 'thing', 'size'], to_db) self.done() def testSelect(self): self.open() IF = Interface("test.dp") IF.db = self.BF C = Condition("thing", "=", "'fish'") rows = IF.select("testing", ['time'], condition=C) self.assertTrue(len(rows) == 2) C = Condition("thing", "=", "'dog'") rows = IF.select("testing", ['time'], condition=C) self.assertTrue(len(rows) == 1) self.done() def testSelectCondition(self): """ DB looks like: 1 cat 5 2 dog 6 3 fish 8 4 goat 0 5 fish 12 """ self.open() IF = Interface("test.dp") IF.db = self.BF C = Condition(Condition("thing", "="), "or", Condition("size", "<")) values = ("fish", 6) rows = IF.select("testing", ['*'], condition=C, values=values) self.assertTrue(len(rows) == 4) self.done() def testUpdate(self): self.open() IF = Interface("test.dp") IF.db = self.BF to_db = [("frog", 18, 2), ("yak", 20, 5)] C = Condition("time", "=") IF.update('testing', ['thing', 'size'], to_db, C) """ DB looks like: 1 cat 5 2 frog 18 2 frog 18 4 goat 0 5 yak 20 """ C = Condition("thing", "=", "'fish'") rows = IF.select("testing", ['time'], condition=C) self.assertTrue(len(rows) == 0) C = Condition("size", ">=", "'18'") rows = IF.select("testing", ['time'], condition=C) self.assertTrue(len(rows) == 3) # more complex updates (proxy as test for more complex selects s1 = Condition("size", ">=", "'18'") s2 = Condition("thing", "!=") C = Condition(s1, "and", s2) data = [(7, 'frog')] IF.update('testing', ['time'], data, C) C = Condition("thing", "=", "'yak'") rows = IF.select("testing", ['time'], condition=C) # should affect 1 row self.assertTrue(len(rows) == 1) # should be the yak row which should now have time = 7 self.assertTrue(rows[0][0] == 7) data = [(7, 8, "pig")] IF.update('testing', ['time', 'size', 'thing'], data, 1) C = Condition("time", "=", 7) rows = IF.select("testing", ['time'], condition=C) # should affect 1 row self.assertTrue(len(rows) == 5) self.done()
def createNewFile(self, fileName, # name of the new file force=False, # should we check to see if this is a wise move? ): """Create a new TrackM database file""" # make a basic file BaseFile.createNewFile(self, fileName, type="TrackM_DB", version=__TRACKM_DB_VERSION__, force=force) # add TrackM specific tables self._addTable("ids", # housekeeping information about highest ids { "sqid" : "INT", # highest sqid in the seqs table (-1 for None) "hid" : "INT", # highest hid in the hits table (-1 for None) "cid" : "INT", # highest cid in the contigs table (-1 for None) "oid" : "INT", # highest oid in the orfs table (-1 for None) }, force=True) self._addTable("paths", # information about the location of genome files { "gid" : "TEXT", # genomeTree compatible ID for genome 1 (primary key) "path" : "TEXT" # absolute path to fasta file }, force=True) self._addTable("pairs", # information about comparisons to make { "pid" : "INT", # unique ID describing this pair (primary key) "gid_1" : "TEXT", # genomeTree compatible ID for genome 1 (foreign key) "gid_2" : "TEXT", # genomeTree compatible ID for genome 2 (gid_2 > gid_1) (foreign key) "ani_1" : "REAL", # ANI from gid_1 -> gid_2 "ani_2" : "REAL", # ANI from gid_2 -> gid_1 "ident_tree" : "REAL", # GTDB (83 marker) identity "ident_16S" : "REAL", # 16S pairwise identity "batch" : "INT", # batch processed in "ani_comp" : "REAL" # which ani has this pair been processed as? }, force=True) self._addTable("hits", # information about hits between genome pairs { "hid" : "INT", # unique ID for this hit (primary key) "pid" : "INT", # pair ID from pairs table (foreign key) "cid_1" : "INT", # ID of the contig for this hit "start_1" : "INT", # start position for this hit in gid_1 "len_1" : "INT", # length of this hit in gid_1 "strand_1" : "INT", # strand of the hit in gid_1 "sqid_1" : "INT", # sequence ID for this hit from seqs table (foreign key) "cid_2" : "TEXT", "start_2" : "INT", "len_2" : "INT", "strand_2" : "INT", "sqid_2" : "INT", "ident" : "REAL", # percent identity for this hit }, force=True) self._addTable("contigs", # store contig headers once { "cid" : "INT", # unique ID for this contig (primary key) "header" : "TEXT", # contig header }, force=True) self._addTable("seqs", # information about orfs found on hits { "sqid" : "INT", # unique ID for this sequence (primary key) "seq" : "TEXT", # nucelotide sequence }, force=True) self._addTable("orfs", # information about orfs found on hits { "oid" : "INT", # unique ID for this orf (primary key) "sqid" : "INT", # hit ID for this orf from in hits table (foreign key) "start" : "INT", # start of the ORF "len" : "INT", # length of the orf "strand" : "INT", # strand of the orf "seq_nucl" : "TEXT", # nucelotide sequence "seq_prot" : "TEXT" # protein sequence }, force=True) self._addTable("ann_kegg", # kegg annotatations for orfs { "oid" : "INT", # orf id for this hit (foreign key) "hit_1" : "TEXT", # best hit "hit_1" : "TEXT", # second best hit "hit_1" : "TEXT" # third best hit }, force=True) self._addTable("ann_nog", # eggnog annotations for orfs { "oid" : "INT", # orf id for this hit (foreign key) "hit_1" : "TEXT", # best hit "hit_1" : "TEXT", # second best hit "hit_1" : "TEXT" # third best hit }, force=True) self._addTable("ann_nr", # nr annotations for orfs { "oid" : "INT", # orf id for this hit (foreign key) "hit_1" : "TEXT", # best hit "hit_1" : "TEXT", # second best hit "hit_1" : "TEXT" # third best hit }, force=True)