def get_upload_settings(self, general = True, file = None): ''' ''' if file in self.fileSpecificSettings: prevSettings = OrderedDict([(k,[v]) for k,v in self.fileSpecificUserSettings[file].items()]) else: prevSettings = self.generalLoadSettings dialog = simpleUserInputDialog(list(prevSettings.keys()), [x[0] for x in prevSettings.values()], list(self.generalLoadSettings.values()), 'Upload Settings', 'Settings have to be define for all files that should be uploaded.') if len(dialog.selectionOutput) == len(comboBoxToGetInputFromUser): if general: self.loadSettings = self.adjust_setting_names(dialog.selectionOutput) if len(self.fileSpecificSettings) != 0: quest = tk.messagebox.askquestion('Overwrite?', 'File specific upload paramters were given. Do you want to discard them?', parent=self.toplevel) if quest == 'yes': self.fileSpecificSettings = dict() elif file is not None and general == False: self.fileSpecificUserSettings[file] = dialog.selectionOutput.copy() self.fileSpecificSettings[file] = self.adjust_setting_names(dialog.selectionOutput) self.get_file_columns(self.dir,list(self.fileColumns.keys()))
def modify_legend(self,event = None, legendTitle = False): ''' Let's the user modify the legend. ''' if event is None: event = self.event ax = event.inaxes legend = self.check_for_legend(ax) if legend is not None: if legendTitle: textItems = [legend.get_title()] else: textItems = legend.get_texts() textStrings = [txt.get_text() for txt in textItems] optionList = [['None',textStrings[n]] for n in range(len(textStrings))] dialogWindow = simple_dialog.simpleUserInputDialog(textStrings,textStrings, optionList,'Change Legend Text','Modify legend text.') for txt in textItems: oldText = txt.get_text() if oldText in dialogWindow.selectionOutput: newText = dialogWindow.selectionOutput[oldText] txt.set_text(newText) self.redraw()
def change_limits(self, event = None): ''' Allows the user to change axis limits. ''' if event is None: event = self.event ax = event.inaxes axisId = self.identify_id_of_axis(ax) settingList = ['x min', 'x max', 'y min', 'y max'] textStrings = [self.axisItems[axisId]['xLimit'][0], self.axisItems[axisId]['xLimit'][1], self.axisItems[axisId]['yLimit'][0], self.axisItems[axisId]['yLimit'][1]] optionList = [[],[],[],[]] dialogWindow = simple_dialog.simpleUserInputDialog(settingList,textStrings, optionList,'Change axis limits','Change axis limits.') if len(dialogWindow.selectionOutput) == 4: try: ax.set_xlim((float(dialogWindow.selectionOutput['x min']), float(dialogWindow.selectionOutput['x max']))) ax.set_ylim((float(dialogWindow.selectionOutput['y min']), float(dialogWindow.selectionOutput['y max']))) except: tk.messagebox.showinfo('Error ..', 'Could not interpret input (examples: 2.3, 100, 34.0). Axis limits not changed.', parent = self.toplevel)
def define_features(self, id): dfString = self.blocks[id]['dataFrame'].get() if dfString not in self.blockIdtoDfId: tk.messagebox.showinfo('Error..', 'Please select a data frame.', parent=self.toplevel) return dfID = self.blockIdtoDfId[dfString] numColumns = self.dfClass.get_numeric_columns_by_id(dfID) if self.blocks[id]['featureInCols'].instate(['selected']): pass else: catColumns = self.dfClass.get_categorical_columns_by_id(dfID) featureNamesDialog = simple_dialog.simpleUserInputDialog( ['Feature Names'], [catColumns[0]], catColumns, 'Select feature names column', 'Please select Column that holds feature names (Gene names, Lipid names)' ) if len(featureNamesDialog.selectionOutput) == 0: return dialog = simple_dialog.simpleListboxSelection( 'Select feature columns.', numColumns, 'Feature Selection') if len(dialog.selection) > 0: featureColumns = dialog.selection blockDF = self.dfClass.dfs[dfID][featureColumns] if self.blocks[id]['featureInCols'].instate(['selected']): self.blocks[id]['blockDF'] = blockDF self.blocks[id][ 'featureNames'] = blockDF.columns.values.tolist() else: self.blocks[id]['blockDF'] = blockDF.transpose().values self.blocks[id][ 'featureNames'] = featureNamesDialog.selectionOutput[ 'Feature Names'] if self.blocks[id]['scaleData'].instate(['selected']): self.blocks[id]['blockDF'] = StandardScaler().fit_transform( self.blocks[id]['blockDF']) self.blocks[id]['featureButton'].configure(text="\u221A")
def import_data(self): ''' ''' importer = importDataFromDf( self.dfClass, title='Select data from preview as your x values.' + ' They must match either in row- or column-number the' + ' selected numeric columns: {}.'.format(self.n_cols), requiredDataPoints=self.n_cols, allowMultSelection=True) ## get selected data selectionData = importer.get_data_selection() ## ensure that df Class has correct data selected (if user change it to select data) #self.dfClass.set_current_data_by_id(self.dfID) #print(selectionData) if selectionData is None: del importer return else: shape = selectionData.shape if shape[0] == self.n_cols and shape[1] == self.n_cols: askAxis = simpleUserInputDialog( ['observations are in'], ['rows'], ['rows', 'columns'], title='Select axis.', infoText= 'Data selection shape matches in rows and columns. Please select where the observations are stored.' ) results = askAxis.selectionOutput if len(results) == 0: tk.messagebox.showinfo('Error..', 'No axis selected.', parent=self) elif results['observations are in'] == 'rows': self.corr_data = selectionData elif results['observations are in'] == 'columns': self.corr_data = selectionData.transpose() elif shape[1] == self.n_cols: self.corr_data = selectionData.transpose() elif shape[0] == self.n_cols: self.corr_data = selectionData self.correlationColumns = self.corr_data.columns.values.tolist() self.corrButton.configure(state=tk.ACTIVE)
def add_image_to_axis(self, pathToFile = None, axisId = None): ''' Add an image to a selected subplot. ''' if self.check_if_axes_created() == False: return if pathToFile is None: pathToFile = tf.askopenfilename(initialdir=path_file, title="Choose File",parent = self.toplevel) if pathToFile == '': return fileEnd = pathToFile.split('.')[-1] if fileEnd != 'png': tk.messagebox.showinfo('File error ..','At the moment only png files are supported.'+ ' Your file path ends with: {}'.format(fileEnd), parent = self.toplevel) return im = plt.imread(pathToFile) if axisId is None: axesInFigure = [] for id, props in self.figureProps.items(): axesInFigure.append('Subplot Id: {} - Label: {}'.format(id,props['axisLabel'])) ## select axis dialog = simple_dialog.simpleUserInputDialog(['Subplot: '], [axesInFigure[0]],[axesInFigure], title='Select subplot',infoText='Select subplot.') axisId = int(float(dialog.selectionOutput['Subplot: '].split(' ')[2])) ax = self.figureProps[axisId]['ax'] axOrigPosition = ax.get_position() ## show image ax.imshow(im) ax.axis('off') self.infolabel.set('The original resolution is restored upon export.') self.redraw() self.align_image_in_axis(ax,axOrigPosition) self.redraw() self.mainFigureCollection.store_image_export(axisId,self.figureId,pathToFile)
def define_class(self, id): ''' ''' dfString = self.blocks[id]['dataFrame'].get() if dfString not in self.blockIdtoDfId: tk.messagebox.showinfo('Error..', 'Please select a data frame.', parent=self.toplevel) return dfID = self.blockIdtoDfId[dfString] catColumns = self.dfClass.get_categorical_columns_by_id(dfID) dialog = simple_dialog.simpleUserInputDialog( ['Class'], [catColumns[0]], catColumns, 'Select Class Columns', 'Please define column that holds information about the classes.') self.blocks[id]['classNames'] = self.dfClass.dfs[dfID][ dialog.selectionOutput['Class']].values self.blocks[id]['classButton'].configure(text="\u221A")
def rename_groups(self, event=None): ''' ''' selection = self.get_selected_groups() commonStart = self.find_longest_item_match(selection) optionValues = [[commonStart[n], groupId] for n, groupId in enumerate(selection)] groupRenameDialog = simpleUserInputDialog(selection, commonStart, optionValues, title='Rename groups', infoText='') renameOutput = groupRenameDialog.selectionOutput if len(renameOutput) != 0: for groupId, newName in renameOutput.items(): if newName == '': continue self.rename_group_in_tree(groupId, newName)