def __init__(self, parent, title): super(ChildFrame, self).__init__(parent, title='Admix', size=(300, 325)) #pan = wx.Panel(self,wx.ID_ANY) self.currentDirectory = os.getcwd() self.InitUI() self.Centre() self._DH = DataHolder self._FI = FileImporter() pub.subscribe(self.GetPanel, "GetPanelAdmix")
def __init__(self, parent, title): super(PCAFrame, self).__init__(parent, title='Pca', size=(400, 400), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) #pan = wx.Panel(self,wx.ID_ANY) self.currentDirectory = os.getcwd() self.InitUI() self.Centre() #creates File Importer for now self._FI = FileImporter() self._DH = DataHolder pub.subscribe(self.GetPanel, "GetPanelPca")
def setUp(self): self.FI = FileImporter() admixData = self.getAdmixData('../Data/small.Q.4') famData = self.getFamData('../Data/small.fam') pheData = self.getPhenoData('../Data/small.phe') self.graph = AdmixGraph.AdmixGraph(admixData, famData, None, "graph", phenoData=pheData) self.graph.groupColIndex = 2
def __init__(self, *args, **kwargs): super(windowClass, self).__init__(*args, **kwargs) self.Size = (3000, 4500) self._panel = self.basicGUI() self.AdmixPath = AdmixPath = '' #find data holder self._DH = DataHolder #create a fileimporter to hold graphs self._FI = FileImporter() self.Graphs = {} #the main graph is listening so that it can get file importers PCA and ADMIX main pub.subscribe(self.mylistener, "panelListener") #create a list of ids self._cid = [] #create a notebook to store graphs self.plotter = PlotNotebook(self._panel) currentGraphName = "" self.currentDirectory = os.getcwd() self.sb = self.CreateStatusBar() self.sb.SetStatusText("Genesis2.o")
def test_TestGetFileData(self): fi = FileImporter() _var =fi.GetFileData('..\\Data\\comm-SYMCL.pca.evec') self.assertIsNotNone(_var) _var =fi.GetFileData(None) self.assertIsNone(_var) _var =fi.GetFileData('') self.assertIsNone(_var) _var =fi.GetFileData('..\\Data\\Empty.txt') self.assertIsNone(_var)
class windowClass(wx.Frame): """ Creates the main interface for the program.""" def __init__(self, *args, **kwargs): super(windowClass, self).__init__(*args, **kwargs) self.Size = (3000, 4500) self._panel = self.basicGUI() self.AdmixPath = AdmixPath = '' #find data holder self._DH = DataHolder #create a fileimporter to hold graphs self._FI = FileImporter() self.Graphs = {} #the main graph is listening so that it can get file importers PCA and ADMIX main pub.subscribe(self.mylistener, "panelListener") #create a list of ids self._cid = [] #create a notebook to store graphs self.plotter = PlotNotebook(self._panel) currentGraphName = "" self.currentDirectory = os.getcwd() self.sb = self.CreateStatusBar() self.sb.SetStatusText("Genesis2.o") def returnPanel(self): """ Returns the panel for the main UI frame. """ return self._panel def basicGUI(self): """Initialises GUI for the main frame. """ panel = wx.Panel(self) menuBar = wx.MenuBar() #Declare new buttons fileButton = wx.Menu() graphButton = wx.Menu() helpButton = wx.Menu() #File Button options Save_Item = fileButton.Append(wx.ID_ANY, 'Save Project', 'status msg...') Load_Item = fileButton.Append(wx.ID_ANY, 'Load Project', 'status msg...') Export_Item = fileButton.Append(wx.ID_ANY, 'Export image', 'status msg...') Exit_Item = fileButton.Append(wx.ID_ANY, 'Exit', 'status msg...') self.Bind(wx.EVT_TOOL, self.SaveEvent, Save_Item) self.Bind(wx.EVT_TOOL, self.LoadEvent, Load_Item) self.Bind(wx.EVT_TOOL, self.ExportEvent, Export_Item) self.Bind(wx.EVT_TOOL, self.QuitEvent, Exit_Item) #Toolbars importItem = wx.Menu() Import_Admix = importItem.Append(wx.ID_ANY, 'New Admixture Graph') Import_PCA = importItem.Append(wx.ID_ANY, 'New PCA Graph') self.Bind(wx.EVT_TOOL, self.PCAEvent, Import_PCA) self.Bind(wx.EVT_TOOL, self.AdmixEvent, Import_Admix) fileButton.Append(wx.ID_ANY, 'New Graph', importItem) self.Makebar() #Graph Button options Data_Options_Item = graphButton.Append( wx.ID_ANY, 'Data options', 'status msg...') #Append new items to buttons Appearance_Options_Item = graphButton.Append(wx.ID_ANY, 'Appearence options', 'status msg...') Delete_Annotations_Item = graphButton.Append(wx.ID_ANY, 'Delete Annotations', 'status msg...') self.Bind(wx.EVT_TOOL, self.AppearenceEvent, Appearance_Options_Item) self.Bind(wx.EVT_TOOL, self.DataOptionsEvent, Data_Options_Item) self.Bind(wx.EVT_TOOL, self.DelAnnotationsEvent, Delete_Annotations_Item) #Help Button options Help_Item = helpButton.Append(wx.ID_EXIT, 'Help', 'status msg...') About_Item = helpButton.Append(wx.ID_EXIT, 'About', 'status msg...') #Add buttons to menubar menuBar.Append(fileButton, 'File') menuBar.Append(graphButton, 'Graph') menuBar.Append(helpButton, 'Help') self.SetMenuBar(menuBar) #self.Bind(wx.EVT_MENU, self.QuitEvent, exitItem) self.SetTitle('Genesis') self.Show(True) return panel def Makebar(self): """Initialises tool bar at the top of the GUI """ toolBar = self.CreateToolBar() #toolBar.SetBackgroundColour((0xff,0xcc,0xcc)) #Declare all toolbar buttons InputAdmixButton = toolBar.AddTool(wx.ID_ANY, 'Quite', wx.Bitmap('../images/admix.bmp'), shortHelp='Admix') self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter, InputAdmixButton) #InputAdmixButton.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter) InputPCAButton = toolBar.AddTool(wx.ID_ANY, 'Import', wx.Bitmap('../images/pca.bmp'), shortHelp='PCA') toolBar.AddSeparator() SaveButton = toolBar.AddTool(wx.ID_ANY, 'Import', wx.Bitmap('../images/save.bmp'), shortHelp='Save') OpenFilesButton = toolBar.AddTool(wx.ID_ANY, 'Import', wx.Bitmap('../images/open.bmp'), shortHelp='Open Files') toolBar.AddSeparator() DataOptionsButton = toolBar.AddTool(wx.ID_ANY, 'Import', wx.Bitmap('../images/dataOp.bmp'), shortHelp='Data Options') AppearenceButton = toolBar.AddTool( wx.ID_ANY, 'Import', wx.Bitmap('../images/appearanceOp.bmp'), shortHelp='Appearence') RefreshButton = toolBar.AddTool(wx.ID_ANY, 'Import', wx.Bitmap('../images/refresh.bmp'), shortHelp='Refresh') ShowHideButton = toolBar.AddTool(wx.ID_ANY, 'Import', wx.Bitmap('../images/hiddenInd.bmp'), shortHelp='Show/Hide Individual') SearchIndividualButton = toolBar.AddTool( wx.ID_ANY, 'Import', wx.Bitmap('../images/search.bmp'), shortHelp='Search for Individual') SearchHiddenIndividualButton = toolBar.AddTool( wx.ID_ANY, 'Import', wx.Bitmap('../images/hiddenInd.bmp'), shortHelp='Search Hidden Individual') toolBar.AddSeparator() DrawLineButton = toolBar.AddTool(wx.ID_ANY, 'Import', wx.Bitmap('../images/drawLine.bmp'), shortHelp='Draw Line') DrawArrowButton = toolBar.AddTool(wx.ID_ANY, 'Import', wx.Bitmap('../images/drawArrow.bmp'), shortHelp='Draw Arrow') toolBar.AddSeparator() ExportButton = toolBar.AddTool(wx.ID_ANY, 'Import', wx.Bitmap('../images/Export.bmp'), shortHelp='Export') CloseProjectButton = toolBar.AddTool( wx.ID_ANY, 'Import', wx.Bitmap('../images/closeProject.bmp'), shortHelp='Close Project') UndoButton = toolBar.AddTool(wx.ID_ANY, 'Import', wx.Bitmap('../images/Undo.bmp'), shortHelp='Undo') RedoButton = toolBar.AddTool(wx.ID_ANY, 'Import', wx.Bitmap('../images/redo.bmp'), shortHelp='Redo') toolBar.Realize() #Bind functions to buttons self.Bind(wx.EVT_TOOL, self.AdmixEvent, InputAdmixButton) self.Bind(wx.EVT_TOOL, self.PCAEvent, InputPCAButton) self.Bind(wx.EVT_TOOL, self.SaveEvent, SaveButton) self.Bind(wx.EVT_TOOL, self.LoadEvent, OpenFilesButton) self.Bind(wx.EVT_TOOL, self.DataOptionsEvent, DataOptionsButton) self.Bind(wx.EVT_TOOL, self.AppearenceEvent, AppearenceButton) self.Bind(wx.EVT_TOOL, self.RefreshEvent, RefreshButton) self.Bind(wx.EVT_TOOL, self.ShowHideEvent, ShowHideButton) self.Bind(wx.EVT_TOOL, self.SearchIndividualEvent, SearchIndividualButton) self.Bind(wx.EVT_TOOL, self.SearchHiddenIndividualEvent, SearchHiddenIndividualButton) self.Bind(wx.EVT_TOOL, self.DrawLineEvent, DrawLineButton) self.Bind(wx.EVT_TOOL, self.DrawArrowEvent, DrawArrowButton) self.Bind(wx.EVT_TOOL, self.ExportEvent, ExportButton) self.Bind(wx.EVT_TOOL, self.QuitEvent, CloseProjectButton) self.Bind(wx.EVT_TOOL, self.UndoEvent, UndoButton) self.Bind(wx.EVT_TOOL, self.RedoEvent, RedoButton) #All button and label functions def DelAnnotationsEvent(self, e): """Delete annotations from program """ #Not currently implemented pass def OnMouseEnter(self, e): """ Shows a description of the icons function.""" self.Statusbar.SetStatusText("TRIGGERED") e.Skip() def AdmixEvent(self, e): """Runs admix creator GUI. """ self.child = AdmixFrame(self, title='Admix') self.child.Show() self.child.SetFocus() pub.sendMessage('GetPanelAdmix', message=self.plotter) def PCAEvent(self, e): """Runs the pca creator GUI. """ self.child = PCAFrame(self, title='PCA') self.child.Show() pub.sendMessage('GetPanelPca', message=self.plotter) def SaveEvent(self, e): """Saves the current graph. """ graph = DataHolder.Graphs[windowClass.currentGraphName] defName = "" #determines graph type if (type(graph) is Admix): wildcard = admixSaveWildcard defName = windowClass.currentGraphName + ".gaf" elif (type(graph) is PCA): wildcard = pcaSaveWildcard defName = windowClass.currentGraphName + ".gpf" dlg = wx.FileDialog(self, message="Select a save locations", defaultDir=self.currentDirectory, defaultFile=defName, wildcard=wildcard, style=wx.FD_SAVE | wx.FD_CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: filePath = dlg.GetPath() baseName = ntpath.basename(filePath) #get base name #update dictionary key for graph and figure graph.setName(baseName, windowClass.currentGraphName) #Set notebook as none so it can be pickled graph.setNotebook(None) GraphSaver.saveGraph(graph, filePath) nb = self.plotter.getNoteBook() #reset notebook graph.setNotebook(self.plotter) pageIndex = nb.GetSelection() nb.SetPageText(pageIndex, baseName) windowClass.currentGraphName = baseName dlg.Destroy() def OpenFileEvent(self, e): """ Opens extra files GUI.""" wx.MessageBox('Open file') def DataOptionsEvent(self, e): """Opens data options GUI""" self.child = AdmixDataFrame(self, title='Graph Options') self.child.Show() def AppearenceEvent(self, e): """Opens up the relevant customization options GUI. """ graph = self._DH.Graphs.get(windowClass.currentGraphName) #Checks graph type and chooses relevant window to display if (isinstance(graph, PCA)): self.child = PcaCustom(self, windowClass.currentGraphName, self.plotter.nb.GetCurrentPage(), self.plotter.nb, self.plotter.nb.GetSelection()) self.child.Show() elif (isinstance(graph, Admix)): self.child = admixMM(self, graph, self.plotter, self.plotter.nb) self.child.Show() def RefreshEvent(self, e): """ Opens refresh GUI.""" wx.MessageBox('Refresh file') def ShowHideEvent(self, e): """ Opens Show hiders GUI.""" wx.MessageBox('Hide file') def SearchIndividualEvent(self, e): """ Opens search individual GUI.""" wx.MessageBox('Search Individual file') def SearchHiddenIndividualEvent(self, e): """ Opens search hidden individuals GUI.""" wx.MessageBox('Search Hidden Individual file') def DrawLineEvent(self, e): """Turns on ability to draw a line. """ An.Annotate(self._DH.Figures) def DrawArrowEvent(self, e): """ Turns on ability to draw an arrow.""" An.AnnotateArrow(self._DH.Figures) def ExportEvent(self, e): """Ooens export GUI. """ wx.MessageBox('Export file') self.child = EXFrame(self, title='Export as') self.child.Show() def QuitEvent(self, e): """Exits the program.""" wx.MessageBox('Exit') self.Destroy() def UndoEvent(self, e): """Will undo previous action. """ wx.MessageBox('Undo') def RedoEvent(self, e): """Will redo previous undo action. """ wx.MessageBox('Redo') def LoadEvent(self, e): """ Load graph object into the scene.""" #Creates a dialog to locate previous projects dlg = wx.FileDialog(self, message="Select a Genesis graph file", defaultDir=self.currentDirectory, defaultFile="", wildcard=loadWildcard, style=wx.FD_OPEN | wx.FD_CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: filePath = dlg.GetPath() graph = GraphSaver.loadGraph(filePath) nb = self.plotter graph.setNotebook(nb) if type(graph) is Admix: phenoCol = graph.getPhenoColumn() graph.plotGraph(False, phenoCol=phenoCol) elif type(graph) is PCA: graph.PlotPca( False ) #False indicates this graph is not being plotted the first time self._DH.Graphs.update({graph.getName(): graph}) def mylistener(self, message, arg2=None): """Gets file managers returned from graphing frames. """ _temp = message.GetManagers() for i in range(0, len(_temp)): self._FI.AddFileManager(_temp[i]) self._FI.PrintFileManagers()
class PCAFrame(wx.Frame): '''This is the main PCA frame.''' def __init__(self, parent, title): super(PCAFrame, self).__init__(parent, title='Pca', size=(400, 400), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) #pan = wx.Panel(self,wx.ID_ANY) self.currentDirectory = os.getcwd() self.InitUI() self.Centre() #creates File Importer for now self._FI = FileImporter() self._DH = DataHolder pub.subscribe(self.GetPanel, "GetPanelPca") def InitUI(self): '''Initialise user interface.''' panel = wx.Panel(self, wx.ID_ANY) self.Columns = [] self.m_textCtrl1 = wx.TextCtrl(panel, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0) self.comboPCA1 = wx.ComboBox(panel, choices=self.Columns) self.comboPCA1.Bind(wx.EVT_COMBOBOX, self.OnCombo) self.comboPCA2 = wx.ComboBox(panel, choices=self.Columns) self.comboPCA2.Bind(wx.EVT_COMBOBOX, self.OnCombo) self.comboPCA3 = wx.ComboBox(panel, choices=self.Columns) self.comboPCA3.Bind(wx.EVT_COMBOBOX, self.OnCombo) self.comboPhe = wx.ComboBox(panel, choices=self.Columns) self.comboPhe.Bind(wx.EVT_COMBOBOX, self.OnCombo) self.comboPCA1.Hide() self.comboPCA2.Hide() self.comboPCA3.Hide() self.comboPhe.Hide() self.ColumnLabel = wx.StaticText(panel, label="Select PCAs") self.ColumnLabel.Hide() self.PheLabel = wx.StaticText(panel, label="Which Column is the phenotype") self.PheLabel.Hide() self.m_textCtrl1.Value = "Name" vbox = wx.BoxSizer(wx.VERTICAL) fgsTop = wx.FlexGridSizer(2, 2, 15, 15) fgs = wx.FlexGridSizer(8, 1, 15, 15) fgsBotPhe = wx.FlexGridSizer(1, 2, 15, 15) fgsBot = wx.FlexGridSizer(1, 2, 15, 50) fgsBotRight = wx.FlexGridSizer(1, 2, 15, 15) OpenFileBtn = wx.Button(panel, wx.ID_ANY, label='Import Data File') OpenFileBtn.parameterVal = 'Data' OpenPheBtn = wx.Button(panel, wx.ID_ANY, label='Import Phe File') OpenPheBtn.parameterVal = 'Phe' AcceptBtn = wx.Button(panel, wx.ID_ANY, label='Accept') ExitBtn = wx.Button(panel, wx.ID_EXIT, label='Exit') OpenFileBtn.Bind(wx.EVT_BUTTON, self.onOpenFile) OpenPheBtn.Bind(wx.EVT_BUTTON, self.onOpenFile) AcceptBtn.Bind(wx.EVT_BUTTON, self.onAcceptFile) ExitBtn.Bind(wx.EVT_BUTTON, self.Quit) self.tc1 = wx.TextCtrl(panel) self.tc3 = wx.TextCtrl(panel) fgsTop.AddMany([(OpenFileBtn), (self.tc1, 1, wx.EXPAND), (OpenPheBtn, 1, wx.EXPAND), (self.tc3, 1, wx.EXPAND)]) fgsBotPhe.AddMany([(self.PheLabel, 1, wx.EXPAND), (self.comboPhe, 1, wx.EXPAND)]) fgsBot.AddMany([(AcceptBtn), (ExitBtn)]) fgs.AddMany([(self.m_textCtrl1, 1, wx.EXPAND), (fgsTop, 1, wx.EXPAND), (self.ColumnLabel, 1, wx.EXPAND), (self.comboPCA1, 1, wx.EXPAND), (self.comboPCA2, 1, wx.EXPAND), (self.comboPCA3, 1, wx.EXPAND), (fgsBotPhe, 1, wx.EXPAND), (fgsBot, 1, wx.EXPAND)]) fgsBotPhe.AddGrowableCol(1, 2) fgsTop.AddGrowableCol(1, 2) fgs.AddGrowableCol(0, 1) vbox.Add(fgs, proportion=2, flag=wx.ALL | wx.EXPAND, border=15) panel.SetSizer(vbox) def AppearFrame(self, event): '''Calls appearence frame.''' self.child = AppFrame(self, title='Appearance') self.child.Show() def Quit(self, event): '''Exits frame''' self.Destroy() pub.sendMessage('panelListener', message=self._FI) def OnCombo(self, event): '''Gets values from combobox.''' print(self.comboPhe.GetValue()) def onAcceptFile(self, event): '''Takes in file using file dialog.''' #splitting the coloumn names up to get the numbers name = self.m_textCtrl1.Value pheCol = self.comboPhe.Value.split(' ') Col1 = self.comboPCA1.Value.split(' ') Col2 = self.comboPCA2.Value.split(' ') Col3 = self.comboPCA3.Value.split(' ') #creates graph dependant on if there is phen data try: if (self.tc3.Value != ""): self._FI.CreatePca(self._FI, self.tc1.Value, self.tc3.Value, name, int(Col1[1]), int(Col2[1]), int(pheCol[1]), self._panel) else: self._FI.CreatePca(self._FI, self.tc1.Value, None, name, int(Col1[1]), int(Col2[1]), 3, self._panel) except IndexError: print("Index Error") plt.show() def onOpenFile(self, event): '''Gets file path for use.''' self.button = event.GetEventObject() if self.button.parameterVal == 'Data': wildcard = pcaWildcard if self.button.parameterVal == 'Phe': wildcard = pheWildcard dlg = wx.FileDialog(self, message="Choose a file", defaultDir=self.currentDirectory, defaultFile="", wildcard=wildcard, style=wx.FD_OPEN | wx.FD_CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: self.DataFilePath = dlg.GetPath() print('You chose the following file:') print(self.DataFilePath) if self.button.parameterVal == 'Data': if (VC.CheckPcaValid(self.DataFilePath)): self.tc1.SetValue(self.DataFilePath) else: dlg = wx.MessageDialog(None, "Invalid Admix File", "ERROR", wx.OK | wx.ICON_ERROR) dlg.ShowsModal() if self.button.parameterVal == 'Phe': if (VC.CheckPhenValid(self.DataFilePath)): self.tc3.SetValue(self.DataFilePath) else: dlg = wx.MessageDialog(None, "Invalid Phe File", "ERROR", wx.OK | wx.ICON_ERROR) dlg.ShowModal() print(self.button.parameterVal) #CountsColumns self.CountColumns(self.button) dlg.Destroy() #counts coloumns in the file def CountColumns(self, val): '''Counts number of columns in input file.''' self.Columns.clear() with open(self.DataFilePath) as myFile: reader = csv.reader(myFile, delimiter=' ', skipinitialspace=True) first_row = next(reader) num_cols = len(first_row) for index in range(0, num_cols): self.Columns.insert(index, 'Column ' + str(index + 1)) if self.button.parameterVal == 'Data': self.comboPCA1.Clear() self.comboPCA1.AppendItems(self.Columns) self.comboPCA1.Value = self.Columns[0] self.comboPCA2.Clear() self.comboPCA2.AppendItems(self.Columns) self.comboPCA2.Value = self.Columns[1] self.comboPCA3.Clear() self.comboPCA3.AppendItems(self.Columns) self.comboPCA1.Show() self.comboPCA2.Show() self.comboPCA3.Show() self.ColumnLabel.Show() self.Size = (401, 401) if self.button.parameterVal == 'Phe': self.comboPhe.Clear() self.comboPhe.AppendItems(self.Columns) self.comboPhe.Value = self.Columns[2] self.comboPhe.Show() self.PheLabel.Show() self.Size = (402, 402) def GetPanel(self, message, arg2=None): '''Gets panel to display graph.''' print("HI") self._panel = message
class ChildFrame(wx.Frame): ''' This is the primary admix frame for generating a new admix graph. This contains functionality to generate the interactable window and is linked to functions to fetch and process the input data ''' def __init__(self, parent, title): super(ChildFrame, self).__init__(parent, title='Admix', size=(300, 325)) #pan = wx.Panel(self,wx.ID_ANY) self.currentDirectory = os.getcwd() self.InitUI() self.Centre() self._DH = DataHolder self._FI = FileImporter() pub.subscribe(self.GetPanel, "GetPanelAdmix") def InitUI(self): '''Initilises user interface.''' panel = wx.Panel(self, wx.ID_ANY) self.Columns = [] self.m_textCtrl1 = wx.TextCtrl(panel, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0) self.m_textCtrl1.Value = "Name" self.combo = wx.ComboBox(panel, choices=self.Columns) self.combo.Bind(wx.EVT_COMBOBOX, self.OnCombo) ColumnLabel = wx.StaticText(panel, label="Phenotype Column") hbox = wx.BoxSizer(wx.HORIZONTAL) fgs = wx.FlexGridSizer(6, 2, 15, 15) #Wx.FlexiGridSizer(rows, cols, vgap, hgap) fgsWhole = wx.FlexGridSizer(2, 1, 15, 15) OpenFileBtn = wx.Button(panel, wx.ID_ANY, label='Import Data File') OpenFileBtn.parameterVal = 'Data' OpenFamBtn = wx.Button(panel, wx.ID_ANY, label='Import Fam File') OpenFamBtn.parameterVal = 'Fam' OpenPheBtn = wx.Button(panel, wx.ID_ANY, label='Import Phe File') OpenPheBtn.parameterVal = 'Phe' AcceptBtn = wx.Button(panel, wx.ID_ANY, label='Accept') ExitBtn = wx.Button(panel, wx.ID_EXIT, label='Exit') OpenFileBtn.Bind(wx.EVT_BUTTON, self.onOpenFile) OpenFamBtn.Bind(wx.EVT_BUTTON, self.onOpenFile) OpenPheBtn.Bind(wx.EVT_BUTTON, self.onOpenFile) AcceptBtn.Bind(wx.EVT_BUTTON, self.onAcceptFile) ExitBtn.Bind(wx.EVT_BUTTON, self.Quit) self.tc1 = wx.TextCtrl(panel) self.tc2 = wx.TextCtrl(panel) self.tc3 = wx.TextCtrl(panel) fgs.AddMany([(OpenFileBtn), (self.tc1, 1, wx.EXPAND), (OpenFamBtn), (self.tc2, 1, wx.EXPAND), (OpenPheBtn, 1, wx.EXPAND), (self.tc3, 1, wx.EXPAND), (ColumnLabel, 1, wx.EXPAND), (self.combo, 1, wx.EXPAND), (AcceptBtn), (ExitBtn)]) fgsWhole.AddMany([(self.m_textCtrl1, 1, wx.EXPAND), (fgs, 1, wx.EXPAND)]) #fgs.AddGrowableRow(1, 2) fgsWhole.AddGrowableCol(0, 2) #fgs.AddGrowableRow(2, 3) fgs.AddGrowableCol(1, 0) hbox.Add(fgsWhole, proportion=2, flag=wx.ALL | wx.EXPAND, border=15) panel.SetSizer(hbox) def Quit(self, event): ''' Exits frame.''' pub.sendMessage('panelListener', message=self._FI) self.Destroy() def AppearFrame(self, event): '''Opens appearence settings.''' self.child = PCAAppearFrame(self, title='Appearance') #self.child.ShowModal() self.child.Show() def OnCombo(self, event): '''Gets values from combobox.''' print(self.combo.GetValue()) # self.label.SetLabel("selected "+ self.combo.GetValue() +" from Combobox") def onAcceptFile(self, event): '''Accepts input data''' #get coloumn no. by spliting name name = self.m_textCtrl1.Value col = self.combo.Value.split(' ') #check for phen data and making sure that data has been inputted if (self.tc1.Value != "" and self.tc2.Value != ""): try: if (self.tc3.Value != ""): self._FI.CreateAdmix(self._FI, self.tc1.Value, self.tc2.Value, self.tc3.Value, name, int(col[1]), self._panel) else: self._FI.CreateAdmix(self._FI, self.tc1.Value, self.tc2.Value, None, name, 3, self._panel) except IndexError: print("Index Error") else: print("No Fam and Data File") plt.show() self.Destroy() def onOpenFile(self, event): '''Opens file dialog to get input data.''' button = event.GetEventObject() if button.parameterVal == 'Data': wildcard = admixWildcard if button.parameterVal == 'Fam': wildcard = famWildcard if button.parameterVal == 'Phe': wildcard = pheWildcard self.CountColumns() dlg = wx.FileDialog(self, message="Choose a file", defaultDir=self.currentDirectory, defaultFile="", wildcard=wildcard, style=wx.FD_OPEN | wx.FD_CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: self.DataFilePath = dlg.GetPath() print('You chose the following file:') print(self.DataFilePath) # windowClass.AdmixPath = DataFilePath if button.parameterVal == 'Data': if (VC.CheckAdmixValid(self.DataFilePath)): self.tc1.SetValue(self.DataFilePath) #self.CountColumns() else: dlg = wx.MessageDialog(None, "Invalid Admix File", "ERROR", wx.OK | wx.ICON_ERROR) dlg.ShowModal() if button.parameterVal == 'Fam': if (VC.CheckFamValid(self.DataFilePath)): self.tc2.SetValue(self.DataFilePath) # self.CountColumns() else: dlg = wx.MessageDialog(None, "Invalid Fam File", "ERROR", wx.OK | wx.ICON_ERROR) dlg.ShowModal() if button.parameterVal == 'Phe': if (VC.CheckPhenValid(self.DataFilePath)): self.tc3.SetValue(self.DataFilePath) self.CountColumns() else: dlg = wx.MessageDialog(None, "Invalid Phe File", "ERROR", wx.OK | wx.ICON_ERROR) dlg.ShowModal() print(button.parameterVal) dlg.Destroy() def CountColumns(self): '''Counts number of columns in input file.''' with open(self.DataFilePath) as myFile: reader = csv.reader(myFile, delimiter=' ', skipinitialspace=True) first_row = next(reader) num_cols = len(first_row) print(num_cols) for index in range(0, num_cols): self.Columns.insert(index, 'Column ' + str(index + 1)) print(self.Columns) self.combo.Clear() self.combo.AppendItems(self.Columns) self.combo.Value = self.Columns[2] #self.Columns = ['none'] def GetPanel(self, message, arg2=None): print("HI") self._panel = message