Package DataStructs :: Module BitEnsembleDb
[hide private]
[frames] | no frames]

Source Code for Module DataStructs.BitEnsembleDb

 1  # $Id: BitEnsembleDb.py 2 2006-05-06 22:54:39Z glandrum $ 
 2  # 
 3  # Copyright (C) 2003-2006 greg Landrum and Rational Discovery LLC 
 4  # 
 5  #   @@ All Rights Reserved  @@ 
 6  # 
 7  """ This functionality gets mixed into the BitEnsemble class 
 8   
 9  """ 
10  from DataStructs.BitEnsemble import BitEnsemble 
11   
12 -def _InitScoreTable(self,dbConn,tableName,idInfo='',actInfo=''):
13 """ inializes a db table to store our scores 14 15 idInfo and actInfo should be strings with the definitions of the id and 16 activity columns of the table (when desired) 17 18 """ 19 if idInfo: 20 cols = [idInfo] 21 else: 22 cols = [] 23 for bit in self.GetBits(): 24 cols.append('Bit_%d smallint'%(bit)) 25 if actInfo : 26 cols.append(actInfo) 27 dbConn.AddTable(tableName,','.join(cols)) 28 self._dbTableName=tableName
29
30 -def _ScoreToDb(self,sig,dbConn,tableName=None,id=None,act=None):
31 """ scores the "signature" that is passed in and puts the 32 results in the db table 33 34 """ 35 if tableName is None: 36 try: 37 tableName = self._dbTableName 38 except AttributeError: 39 raise ValueError,'table name not set in BitEnsemble pre call to ScoreToDb()' 40 if id is not None: 41 cols = [id] 42 else: 43 cols = [] 44 score = 0 45 for bit in self.GetBits(): 46 b = sig[bit] 47 cols.append(b) 48 score += b 49 if act is not None: 50 cols.append(act) 51 dbConn.InsertData(tableName,cols)
52 53 BitEnsemble.InitScoreTable = _InitScoreTable 54 BitEnsemble.ScoreToDb = _ScoreToDb 55