def OnSavePerImageCountsToCSV(self, evt): defaultFileName = 'Per_Image_Counts.csv' saveDialog = wx.FileDialog(self, message="Save as:", defaultDir=os.getcwd(), defaultFile=defaultFileName, wildcard='csv|*', style=(wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT | wx.FD_CHANGE_DIR)) if saveDialog.ShowModal() == wx.ID_OK: colHeaders = list(dbconnect.image_key_columns()) pos = len(colHeaders) if p.plate_id: colHeaders += [p.plate_id] if p.well_id: colHeaders += [p.well_id] colHeaders += ['total_count'] colHeaders += [ 'count_' + bin.label for bin in self.GetParent().classBins ] data = list(self.GetParent().keysAndCounts) for row in data: if p.table_id: where = '%s=%s AND %s=%s' % (p.table_id, row[0], p.image_id, row[1]) total = sum(row[2:]) else: where = '%s=%s' % (p.image_id, row[0]) total = sum(row[1:]) row.insert(pos, total) # Plate and Well are written separately IF they are found in the props file # TODO: ANY column could be reported by this mechanism if p.well_id: res = db.execute('SELECT %s FROM %s WHERE %s' % (p.well_id, p.image_table, where), silent=True) well = res[0][0] row.insert(pos, well) if p.plate_id: res = db.execute('SELECT %s FROM %s WHERE %s' % (p.plate_id, p.image_table, where), silent=True) plate = res[0][0] row.insert(pos, plate) self.SaveCSV(saveDialog.GetPath(), data, colHeaders) saveDialog.Destroy()
def LoadCSV(self, csvfile, group='Image'): try: self.grid.Destroy() except: pass try: # Remove the previous column show/hide menu (should be the third menu) self.GetMenuBar().Remove(2) self.colmenu.Destroy() except: pass r = csv.reader(open(csvfile)) labels = next(r) dtable = dbconnect.get_data_table_from_csv_reader(r) coltypes = db.InferColTypesFromData(dtable, len(labels)) for i in range(len(coltypes)): if coltypes[i] == 'INT': coltypes[i] = int elif coltypes[i] == 'FLOAT': coltypes[i] = float else: coltypes[i] = str r = csv.reader(open(csvfile)) next(r) # skip col-headers data = [] for row in r: data += [[coltypes[i](v) for i, v in enumerate(row)]] data = np.array(data, dtype=object) if group == DO_NOT_LINK_TO_IMAGES: keycols = [] elif group == 'Image': keycols = list(range(len(dbconnect.image_key_columns()))) else: keycols = list(range(len(dm.GetGroupColumnNames(group)))) self.grid = HugeTableGrid(self, data, labels, key_col_indices=keycols, grouping=group, chMap=p.image_channel_colors) self.Title = '%s (%s)' % (csvfile, group) self.file = csvfile self.CreateColumnMenu() self.RescaleGrid()
if coltypes[i] == 'INT': coltypes[i] = int elif coltypes[i] == 'FLOAT': coltypes[i] = float else: coltypes[i] = str r = csv.reader(open(csvfile)) next(r) # skip col-headers data = [] for row in r: data += [[coltypes[i](v) for i, v in enumerate(row)]] data = np.array(data, dtype=object) group = 'Image' if len(sys.argv) == 4: group = sys.argv[3] if group == 'Image': keycols = list(range(len(dbconnect.image_key_columns()))) else: keycols = list(range(len(dm.GetGroupColumnNames(group)))) grid = DataGrid(data, labels, grouping=group, key_col_indices=keycols, chMap=p.image_channel_colors, title=csvfile, autosave=False) grid.Show() app.MainLoop()