def initFromDatabase(self, identifier, connection): """ method for initialising labResourceList from database""" # first init base class - this will get obid ob.initFromDatabase(self, identifier, "labResourceList", connection) # now get the complete object self.databaseFields = getObjectRecord(connection, "labResourceList", self.databaseFields['obid']) # for this object type we need to get the members of the list sql = "select labresourceob from labresourcelistmembershiplink where labresourcelist = %s " % self.databaseFields[ 'obid'] #print "executing " + sql obCursor = connection.cursor() obCursor.execute(sql) obFieldValues = obCursor.fetchall() self.databaseFields.update( {'labresources': [item[0] for item in obFieldValues]}) obCursor.close() self.obState.update({ 'ERROR': 0, 'NEW': 0, 'DB_PENDING': 0, 'MESSAGE': "initialised from database OK" })
def initFromDatabase(self, identifier, connection): """ method for initialising bioLibraryOb from database """ # first init base class - this will get obid ob.initFromDatabase(self, identifier, "bioLibraryOb", connection) # now get the complete object self.databaseFields = getObjectRecord(connection, "bioLibraryOb", self.databaseFields['obid'])
def initFromDatabase(self, identifier, connection): """ method for initialising sequencealignmentfact from database """ # first init base class - this will get obid ob.initFromDatabase(self, identifier, "sequenceAlignmentFact", connection) # now get the complete object self.databaseFields = getObjectRecord(connection, "sequenceAlignmentFact", self.databaseFields['obid'])
def initFromDatabase(self, identifier, connection): """ method for initialising geneticob from database """ # first init base class - this will get obid ob.initFromDatabase(self, identifier, "bioSequenceFeatureFact", connection) # now get the complete object self.databaseFields = getObjectRecord(connection, "bioSequenceFeatureFact", self.databaseFields['obid'])
def initFromDatabase(self, identifier, connection): """ method for initialising workFlowStageOb from database""" # first init base class - this will get obid ob.initFromDatabase(self, identifier, "workFlowStageOb", connection) # now get the complete object self.databaseFields = getObjectRecord(connection, "workFlowStageOb", self.databaseFields['obid']) self.obState.update({ 'ERROR': 0, 'NEW': 0, 'MESSAGE': "initialised from database OK" })
def initFromDatabase(self, identifier, connection): """ method for initialising an object from database""" # initialise base fields from ob table ob.initFromDatabase(self, identifier, "batchOb", connection) # now get the complete object self.databaseFields = getObjectRecord(connection, "batchOb", self.databaseFields['obid']) self.obState.update({ 'ERROR': 0, 'NEW': 0, 'MESSAGE': "initialised from database OK" })
def initFromDatabase(self, identifier, connection): """ method for initialising an object from database - arg can be an integer obid, or a string importProcedureName""" # initialise base fields from ob table ob.initFromDatabase(self, identifier, "bioSubjectOb", connection) # now get the complete object self.databaseFields = getObjectRecord(connection, "bioSubjectOb", self.databaseFields['obid']) self.obState.update({ 'ERROR': 0, 'NEW': 0, 'MESSAGE': "initialised from database OK" })
def initFromDatabase(self, identifier, connection): """ method for initialising microarraySpotFact from database""" # first init base class - this will get obid ob.initFromDatabase(self, identifier, "microarraySpotFact", connection) # now get the complete object self.databaseFields = getObjectRecord(connection, "microarraySpotFact", self.databaseFields['obid']) self.obState.update({ 'ERROR': 0, 'NEW': 0, 'MESSAGE': "initialised from database OK" }) # obtain display procedures that are linked to the parent study object , and have the virtual flag set sql = """ select df.invocation, df.functioncomment, dp.xreflsid, dp.procedurename, ds.datasourcename, ds.physicalsourceuri, ds.datasourcetype, df.voptypeid from (displayfunction df join displayprocedureob dp on df.displayprocedureob = dp.obid) left outer join datasourceob ds on ds.obid = df.datasourceob where df.ob = %(labresourceob)s and df.voptypeid is not null """ labresourcemodulelogger.info( 'executing SQL to retrieve virtual dynamic display functions : %s' % str(sql % self.databaseFields)) displayCursor = connection.cursor() displayCursor.execute(sql, self.databaseFields) self.virtualDisplayFunctions = displayCursor.fetchall() labresourcemodulelogger.info(str(self.virtualDisplayFunctions)) if displayCursor.rowcount > 0: self.obState.update({ 'VIRTUAL_DYNAMIC_DISPLAYS': displayCursor.rowcount, 'MESSAGE': "virtual dynamic displays initialised from database OK" })
def initFromDatabase(self, identifier, connection): """ method for initialising namedListMembershipLink from database""" # first init base class - this will get obid ob.initFromDatabase(self, identifier, "namedListMembershipLink", connection) # now get the complete object self.databaseFields = getObjectRecord(connection, "namedListMembershipLink", self.databaseFields['obid']) self.obState.update({ 'ERROR': 0, 'NEW': 0, 'DB_PENDING': 0, 'MESSAGE': "initialised from database OK" })
def initFromDatabase(self, identifier, connection): """ method for initialising geneExpressionExperimentSeriesFact from database""" # first init base class - this will get obid ob.initFromDatabase(self, identifier, "geneExpressionExperimentSeriesFact", connection) # now get the complete object self.databaseFields = getObjectRecord( connection, "geneExpressionExperimentSeriesFact", self.databaseFields['obid']) self.obState.update({ 'ERROR': 0, 'NEW': 0, 'DB_PENDING': 0, 'MESSAGE': "initialised from database OK" })
def initFromDatabase(self, identifier, connection, startAtItem=0, maxItems=15, asSet=True): """ method for initialising predicateLink from database""" # first init base class - this will get obid ob.initFromDatabase(self, identifier, "predicateLink", connection) # now get the complete object self.databaseFields = getObjectRecord(connection, "predicateLink", self.databaseFields['obid']) self.obState.update({ 'NEW': 0, 'DB_PENDING': 0, 'MESSAGE': "init from database OK" })
def initFromDatabase(self, identifier, connection, startAtItem=0, maxItems=15, asSet=True): """ method for initialising list from database, The asSet option causes the list to prune identical obids after loading - i.e. so that it ends up being a set (no duplcates) rather than a list. This is mainly as a workaround for the lack of adequate array support in the current postgres database - in version 8.0.3 we can easily and efficiently ensure that we do not insert duplicate obids into a list, however this code does not work in 7.4.3 - the array assignments execute without error , however the code using these assignments does not produce expected results. Once the db is upgraded , then code like this can be used in the search function : create function testarray(integer) returns integer as ' declare intarg alias for $1; intarray int[]; result int; begin intarray[0] := 2; intarray[1] := 4; intarray[2] := 6; intarray[3] := 8; if not intarg = ANY(intarray) then result = intarg; else result = 0; end if; return result; END; ' LANGUAGE plpgsql; (note that it is assumed we can't use naive SQL to avoid duplicate entries .....insert into .... and not in .... due to the potential performance problems this would cause. """ self.chunkSize = maxItems # first init base class - this will get obid ob.initFromDatabase(self, identifier, "obList", connection) # now get the complete object self.databaseFields = getObjectRecord(connection, "obList", self.databaseFields['obid']) # for this object type we need to get the members of the list. We get the obid and listorder for # up to maxItems members of the list, in the order specified by listOrder. #sql = "select l.ob,l.listorder,o.xreflsid from ob o,listmembershiplink l where l.oblist = %s and l.listorder >= %s and o.obid = l.ob order by listorder" % (self.databaseFields['obid'],maxItems) if not asSet: sql = """ select l.ob, l.listorder, l.obxreflsid, l.membershipcomment from listmembershiplink l where l.oblist = %s and l.listorder >= %s order by listorder""" % (self.databaseFields['obid'], startAtItem) else: sql = """ select l.ob, l.listorder, l.obxreflsid, l.membershipcomment from listmembershiplink l where l.oblist = %s order by listorder""" % (self.databaseFields['obid']) listmodulelogger.info("list executing %s" % sql) obCursor = connection.cursor() obCursor.execute(sql) if not asSet: obFieldValues = obCursor.fetchall() self.databaseFields.update({ 'alllistitems': [(item[0], item[1], item[2], item[3]) for item in obFieldValues] }) #obFieldValues = obCursor.fetchmany(maxItems) self.databaseFields.update({ 'listitems': [(item[0], item[1], item[2], item[3]) for item in obFieldValues[0:maxItems]] }) self.obState.update({'LIST_MODE': 'LIST'}) else: # if we are to make a set , then do so. A problem is that we do not know the size of the # set (as a set rather than as a list) - but this is needed by the user interface to # figure out how many pages to display - so need to get wholelist listmodulelogger.info("creating a set ") setDict = {} row = obCursor.fetchone() listmodulelogger.info("row count = %d" % obCursor.rowcount) listmodulelogger.info("fetched %s" % str(row)) self.databaseFields['alllistitems'] = [] # update 5/2012 - psycopg driver leaves rowcount set to # 1 when fetching past the last record :-( #while obCursor.rowcount == 1 while obCursor.rowcount >= 1 and row != None: item = tuple(row) self.databaseFields['alllistitems'].append(item) setDict[item[0]] = (item[1], item[2], item[3]) row = obCursor.fetchone() # sort the set by list order and get a chunk, starting from startAtItem listmodulelogger.info( "sorting and selecting bookmarks > %s chunk size %s" % (startAtItem, maxItems)) setKeys = setDict.keys() setKeys.sort(lambda x, y: setDict[x][0] - setDict[y][0]) chunkDict = {} for i in range(0, len(setDict)): #listmodulelogger.info("checking %s"%str(setDict[setKeys[i]])) if (int(setDict[setKeys[i]][0]) >= int(startAtItem)) and (len(chunkDict) < maxItems): #listmodulelogger.info("selecting %s"%str(setDict[setKeys[i]])) chunkDict[setKeys[i]] = setDict[setKeys[i]] #listmodulelogger.info(str(chunkDict)) self.databaseFields.update({ 'listitems': [(key, chunkDict[key][0], chunkDict[key][1], chunkDict[key][2]) for key in chunkDict.keys()], 'currentmembership': len(setDict) }) self.obState.update({'LIST_MODE': 'SET'}) obCursor.close() self.obState.update({ 'ERROR': 0, 'NEW': 0, 'MESSAGE': "initialised from database OK" })