def get_tables(self): '''returns all tables required in the from clause for this query. ''' tables = self.get_queried_tables() # add the tables required to link the above tables together db = DBConnect.getInstance() exps = db.get_linking_expressions(tables) for exp in exps: tables += exp.get_tables() return list(set(tables))
def __init__(self, parent, properties = None, show_controls = True, size=(600, 600), loadData = True, **kwargs): wx.Frame.__init__(self, parent, -1, size=size, title='Dimensionality Reduction Plot', **kwargs) self.SetName('Plot main') if properties is not None: global p p = properties if not p.is_initialized(): logging.critical('Classifier requires a properties file. Exiting.') raise Exception('Classifier requires a properties file. Exiting.') global db db = DBConnect.getInstance() global classifier classifier = parent if loadData: # Define a progress dialog dlg = wx.ProgressDialog('Fetching cell data...', '0% Complete', 100, classifier, wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME | wx.PD_CAN_ABORT) def cb(frac): cont, skip = dlg.Update(int(frac * 100.), '%d%% Complete'%(frac * 100.)) if not cont: # cancel was pressed dlg.Destroy() raise StopCalculating() # Load the data for each object try: self.data, self.data_dic = self.load_obj_measurements(cb) except StopCalculating: self.PostMessage('User canceled updating training set.') return dlg.Destroy() else: self.data, self.data_dic = None, None self.features_dic = self.load_feature_names() self.class_masks = None self.class_names = None self.object_opacity = None figpanel = PlotNotebook(self) self.figure_scores = figpanel.add('Scores') self.figure_loadings = figpanel.add('Loadings') self.update_figures() sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(figpanel, 1, wx.EXPAND) configpanel = PlotControl(self, self.figure_scores, self.figure_loadings) sizer.Add(configpanel, 0, wx.EXPAND | wx.ALL, 5) self.SetSizer(sizer) self.Centre()
def extractDataFromGroupsMysql(self, dependentDataValues, independentDataValues): from properties import Properties from dbconnect import ( DBConnect, UniqueImageClause, UniqueObjectClause, GetWhereClauseForImages, GetWhereClauseForObjects, image_key_columns, object_key_columns, ) import sqltools as sql p = Properties.getInstance() p.LoadFile("C:\\Users\\Dalitso\\Desktop\\workspace2\\abhakar\\Properties_README.txt") db = DBConnect.getInstance() def buildquery(self, theGroup, var): pairs = theGroup.pairsDict if var == "dep": for i in pairs.keys(): print i q = "SELECT " + "`" + self.dependentVariable + "`" + "FROM " + self.table + " WHERE " q2 = [i + " LIKE `" + pairs[i] + "` AND " for i in pairs.keys()] result = q + "".join(q2)[:-4] print result if var == "ind": for i in pairs.keys(): print i q = "SELECT " + "`" + self.independentVariable + "`" + "FROM " + self.table + "WHERE" q2 = [i + "`" + " LIKE `" + pairs[i] + "` AND " for i in pairs.keys()] result = q + "".join(q2)[:-4] print result return result import numpy as np dataDict = {} dependentDataValues = np.array(dependentDataValues) independentDataValues = np.array(independentDataValues) tmp = {} for iGrp in self.groupDefinitions: theGroup = iGrp theGroup.checkMatchCount tmp["dependentData"] = db.execute(buildquery(self, theGroup, "dep")) tmp["independentData"] = db.execute(buildquery(self, theGroup, "ind")) # tmp['pairs'] = theGroup.pairsDict[theGroup.description] dataDict[theGroup.description] = tmp # print iGrp,theGroup.description,tmp return dataDict
def get_where_clause(self): '''Build the where clause from conditions given by the user and conditions that link all the tables together. ''' db = DBConnect.getInstance() conditions = [] conditions += ['(%s)'%(str(f)) for f in self.filters] queried_tables = self.get_queried_tables() if len(queried_tables) > 1: link_exps = db.get_linking_expressions(queried_tables) if link_exps: conditions += [str(exp) for exp in link_exps] if self.old_filters: conditions += ['%s.%s = subquery_%d.%s'%(p.image_table, col, i, col) for i in range(len(self.old_filters)) for col in image_key_columns()] if self.wheres: conditions += [str(where) for where in self.wheres] return ' AND '.join(conditions)
from __future__ import with_statement from dbconnect import DBConnect from properties import Properties from singleton import Singleton from heapq import heappush, heappop from weakref import WeakValueDictionary import imagetools import logging import numpy import threading import wx import os db = DBConnect.getInstance() p = Properties.getInstance() def load_lock(): return TileCollection.getInstance().load_lock class List(list): pass class TileCollection(Singleton): ''' Main access point for loading tiles through the TileLoader. ''' def __init__(self): self.tileData = WeakValueDictionary()
import properties import logging import matplotlib.cm import numpy as np from itertools import groupby import os import sys import re import wx import cpa.helpmenu import csv p = properties.Properties.getInstance() # Hack the properties module so it doesn't require the object table. properties.optional_vars += ['object_table'] db = DBConnect.getInstance() required_fields = ['plate_shape', 'well_id'] fixed_width = (200,-1) class PlateViewer(wx.Frame, CPATool): def __init__(self, parent, size=(800,-1), **kwargs): wx.Frame.__init__(self, parent, -1, size=size, title='Plate Viewer', **kwargs) CPATool.__init__(self) self.SetName(self.tool_name) self.SetBackgroundColour("white") # Fixing the color # Check for required properties fields. fail = False for field in required_fields:
def HTS_GroupDataExtractMySql(dataSelector,table): from HTS_dataDict import HTS_dataDict import xlrd as xl import numpy as np import matplotlib.pyplot as plt from properties import Properties from dbconnect import DBConnect, UniqueImageClause, UniqueObjectClause, GetWhereClauseForImages, GetWhereClauseForObjects, image_key_columns, object_key_columns import sqltools as sql p = Properties.getInstance() db = DBConnect.getInstance() dependentDataValues = False independentDataValues = False # def buildquery(self, table): # q = 'SELECT ' + self.independentVar + ', '+ self.dependentVar +' FROM ' + table # q2= [' WHERE '+ y[1] +' LIKE ' +y[0] for y in group.pairs] # return q + ''.join(q2) returnDict = HTS_dataDict(dataSelector) #for iFile in range(nFiles): dataSelector.clearAllIndici print('HTS_GroupDataExtract: using sheet %s for %s\n',table) query ='SELECT `' + dataSelector.independentVariable + '` FROM ' + '`' +table+'`' print query dataSelector.findValidIndiciFromDataColumn(dataSelector.independentVariable,db.execute(query)) query = 'SELECT `' + dataSelector.dependentVariable + '` FROM ' + '`' +table+'`' print query dataSelector.findValidIndiciFromDataColumn(dataSelector.dependentVariable,db.execute(query)) print dependentDataValues, independentDataValues, "variables" if not dependentDataValues: print 'HTS_GroupDataExtract: dependent variable not found in %s', if not independentDataValues: print 'HTS_GroupDataExtract: independent variable not found in %s' # print dataSelector.extractDataFromGroups(dependentDataValues,independentDataValues) dataSelector.table = table returnDict.dict[table] = dataSelector.extractDataFromGroupsMysql(dependentDataValues,independentDataValues) # if nFiles > 1: # # Get data from the selector # nGroups = dataSelector.nGroups # groupKeys = dataSelector.getGroupDescriptions() # # Create the combined group # combinedData = {} # tmpStruct = {} # tmpStruct['dependentData'] = np.array([]) # tmpStruct['independentData'] = np.array([]) # for iGrp in range(nGroups): # combinedData[groupKeys[iGrp]] = tmpStruct # for iFile in range(nFiles): # #print('the key = %s\n') # fileData = returnDict.dict[dataFiles[iFile]] # for iGrp in range(nGroups): # grpKey = groupKeys[iGrp] # #combDepData = combinedData[grpKey]['dependentData'] # fileDepData = fileData[grpKey]['dependentData'] # tmpStruct['dependentData'] = np.concatenate((tmpStruct['dependentData'],fileDepData[:])) # #combIndData = [combinedData[grpKey]['independentData']] # fileIndData = fileData[grpKey]['independentData'] # tmpStruct['independentData'] = np.concatenate((tmpStruct['independentData'],fileIndData[:])) # combinedData[grpKey] = tmpStruct # # returnDict.dict['combinedData'] = combinedData return returnDict
f.write('\n') f.close() def make_unique_plot_name(self, prefix): '''This function must be called to generate a unique name for each plot. eg: plot.SetName(wx.GetApp().make_unique_plot_name('Histogram')) ''' plot_num = max([int(plot.Name[len(prefix):]) for plot in self.plots if plot.Name.startswith(prefix)]) return '%s %d'%(prefix, plot_num) if __name__ == "__main__": # Initialize the app early because the fancy exception handler # depends on it in order to show a dialog. app = CPAnalyst(redirect=False) if sys.platform=='darwin': import bioformats # Install our own pretty exception handler unless one has already # been installed (e.g., a debugger) if sys.excepthook == sys.__excepthook__: from errors import show_exception_as_dialog sys.excepthook = show_exception_as_dialog # Black magic: Bus errors occur on certain Macs if we wait until # later to connect, so we'll do it here. DBConnect.getInstance().connect() app.MainLoop() os._exit(0)
def __init__(self, parent, properties=None, show_controls=True, size=(600, 600), loadData=True, **kwargs): wx.Frame.__init__(self, parent, -1, size=size, title='Dimensionality Reduction Plot', **kwargs) self.SetName('Plot main') if properties is not None: global p p = properties if not p.is_initialized(): logging.critical( 'Classifier requires a properties file. Exiting.') raise Exception( 'Classifier requires a properties file. Exiting.') global db db = DBConnect.getInstance() global classifier classifier = parent if loadData: # Define a progress dialog dlg = wx.ProgressDialog( 'Fetching cell data...', '0% Complete', 100, classifier, wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME | wx.PD_CAN_ABORT) def cb(frac): cont, skip = dlg.Update(int(frac * 100.), '%d%% Complete' % (frac * 100.)) if not cont: # cancel was pressed dlg.Destroy() raise StopCalculating() # Load the data for each object try: self.data, self.data_dic = self.load_obj_measurements(cb) except StopCalculating: self.PostMessage('User canceled updating training set.') return dlg.Destroy() else: self.data, self.data_dic = None, None self.features_dic = self.load_feature_names() self.class_masks = None self.class_names = None self.object_opacity = None figpanel = PlotNotebook(self) self.figure_scores = figpanel.add('Scores') self.figure_loadings = figpanel.add('Loadings') self.update_figures() sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(figpanel, 1, wx.EXPAND) configpanel = PlotControl(self, self.figure_scores, self.figure_loadings) sizer.Add(configpanel, 0, wx.EXPAND | wx.ALL, 5) self.SetSizer(sizer) self.Centre()