⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wxexportdialog.py

📁 PyChem是用Python语言编写的多元变量分析软件。它包括一个前端图形界面用于管理和保存试验数据
💻 PY
字号:
#Boa:Dialog:wxExportDialog

"""
A dialog for exporting results from PyChem

$Id: wxExportDialog.py Copyright (C) 2005  Roger Jarvis

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

"""

import scipy,Pycluster
from wxPython.wx import *
from fileIO import save
from string import join

def create(parent):
    return wxExportDialog(parent)

[wxID_WXEXPORTDIALOG, wxID_WXEXPORTDIALOGBTNBROWSE, 
 wxID_WXEXPORTDIALOGBTNCANCEL, wxID_WXEXPORTDIALOGBTNOK, 
 wxID_WXEXPORTDIALOGCBEXPEIGS, wxID_WXEXPORTDIALOGCBEXPPCLOADS, 
 wxID_WXEXPORTDIALOGCBEXPPERVAR, wxID_WXEXPORTDIALOGCBEXPSCORES, 
 wxID_WXEXPORTDIALOGSTHCLUSTER, wxID_WXEXPORTDIALOGTCSAVEPCABROWSE, 
 wxID_WXEXPORTDIALOGWDPCAEXPORT, 
] = map(lambda _init_ctrls: wxNewId(), range(11))

class wxExportDialog(wxDialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wxDialog.__init__(self, id=wxID_WXEXPORTDIALOG, name='wxExportDialog',
              parent=prnt, pos=wxPoint(376, 224), size=wxSize(228, 254),
              style=wxDEFAULT_DIALOG_STYLE | wxSIMPLE_BORDER | wxCAPTION | wxDIALOG_MODAL,
              title='Export Results')
        self.SetClientSize(wxSize(220, 220))
        
        self.wdPcaExport = wxWindow(id=wxID_WXEXPORTDIALOGWDPCAEXPORT,
              name='wdPcaExport', parent=self, pos=wxPoint(0, 0),
              size=wxSize(228, 254), style=wxTAB_TRAVERSAL)
        self.wdPcaExport.SetToolTipString('')

        self.cbExpScores = wxCheckBox(id=wxID_WXEXPORTDIALOGCBEXPSCORES,
              label='Export principal component scores', name='cbExpScores',
              parent=self.wdPcaExport, pos=wxPoint(16, 56), size=wxSize(184,
              13), style=0)
        self.cbExpScores.SetValue(False)
        self.cbExpScores.SetToolTipString('')

        self.tcSavePcaBrowse = wxTextCtrl(id=wxID_WXEXPORTDIALOGTCSAVEPCABROWSE,
              name='tcSavePcaBrowse', parent=self.wdPcaExport, pos=wxPoint(16,
              16), size=wxSize(112, 21), style=0, value='')
        self.tcSavePcaBrowse.SetToolTipString('')

        self.btnBrowse = wxButton(id=wxID_WXEXPORTDIALOGBTNBROWSE,
              label='Browse...', name='btnBrowse', parent=self.wdPcaExport,
              pos=wxPoint(136, 16), size=wxSize(75, 23), style=0)
        self.btnBrowse.SetToolTipString('')
        EVT_BUTTON(self.btnBrowse, wxID_WXEXPORTDIALOGBTNBROWSE,
              self.OnBtnBrowseButton)

        self.cbExpEigs = wxCheckBox(id=wxID_WXEXPORTDIALOGCBEXPEIGS,
              label='Export eigenvalues', name='cbExpEigs',
              parent=self.wdPcaExport, pos=wxPoint(16, 120), size=wxSize(192,
              13), style=0)
        self.cbExpEigs.SetValue(False)
        self.cbExpEigs.SetToolTipString('')

        self.cbExpPerVar = wxCheckBox(id=wxID_WXEXPORTDIALOGCBEXPPERVAR,
              label='Export cumulative % variance', name='cbExpPerVar',
              parent=self.wdPcaExport, pos=wxPoint(16, 152), size=wxSize(192,
              13), style=0)
        self.cbExpPerVar.SetValue(False)
        self.cbExpPerVar.SetToolTipString('')

        self.cbExpPcLoads = wxCheckBox(id=wxID_WXEXPORTDIALOGCBEXPPCLOADS,
              label='Export principal component loadings', name='cbExpPcLoads',
              parent=self.wdPcaExport, pos=wxPoint(16, 88), size=wxSize(200,
              13), style=0)
        self.cbExpPcLoads.SetValue(False)
        self.cbExpPcLoads.SetToolTipString('')

        self.btnOK = wxButton(id=wxID_WXEXPORTDIALOGBTNOK, label='OK',
              name='btnOK', parent=self.wdPcaExport, pos=wxPoint(16, 184),
              size=wxSize(75, 23), style=0)
        self.btnOK.SetToolTipString('')
        EVT_BUTTON(self.btnOK, wxID_WXEXPORTDIALOGBTNOK, self.OnBtnOKButton)

        self.btnCancel = wxButton(id=wxID_WXEXPORTDIALOGBTNCANCEL,
              label='Cancel', name='btnCancel', parent=self.wdPcaExport,
              pos=wxPoint(128, 184), size=wxSize(75, 23), style=0)
        self.btnCancel.SetToolTipString('')
        EVT_BUTTON(self.btnCancel, wxID_WXEXPORTDIALOGBTNCANCEL,
              self.OnBtnCancelButton)

        self.stHcluster = wxStaticText(id=wxID_WXEXPORTDIALOGSTHCLUSTER,
              label='The dendrogram will be saved as Hcluster.cdt & Hcluster.gtr in a format suitable for display using Alok Saldanha\x92s Java TreeView program (http://genome-www.stanford.edu)',
              name='stHcluster', parent=self.wdPcaExport, pos=wxPoint(16, 80),
              size=wxSize(183, 72), style=wxST_NO_AUTORESIZE)
        self.stHcluster.Show(False)

    def __init__(self, parent, type='PCA'):
        self._init_ctrls(parent)
        self.Path = None
        
        if type == 'PCA':
            self.cbExpScores.SetLabel('Export principal component scores')
            self.cbExpPcLoads.SetLabel('Export principal component loadings')
            self.cbExpEigs.SetLabel('Export eigenvalues')
            self.cbExpPerVar.SetLabel('Export cumulative % variance')
            self.stHcluster.Show(0)
            self.scoresave = '//PCscores.txt'
            self.loadsave = '//PCloadings.txt'
            self.eigsave = '//PCeigenvalues.txt'
            self.explvar = '//PCexplvar.txt'
        if type == 'DFA':
            self.cbExpScores.SetLabel('Export discriminant function scores')
            self.cbExpPcLoads.SetLabel('Export discriminant function loadings')
            self.cbExpEigs.SetLabel('Export eigenvalues')
            self.cbExpPerVar.Show(0)
            self.stHcluster.Show(0)
            self.scoresave = '//DFscores.txt'
            self.loadsave = '//DFloadings.txt'
            self.eigsave = '//DFeigenvalues.txt'
        if type == 'PLS':
            self.cbExpScores.SetLabel('Export PLS model')
            self.cbExpPcLoads.SetLabel('Export PLS loadings')
            self.cbExpEigs.SetLabel('Export PLS error')
            self.cbExpPerVar.Show(0)
            self.stHcluster.Show(0)
            self.scoresave = '//PLSmodel.txt'
            self.loadsave = '//PLSloadings.txt'
            self.eigsave = '//PLSerror.txt'
        if type == 'HCLUSTER':
            self.stHcluster.Show(1)
            self.cbExpScores.SetLabel('Save HCA outputs')
            self.cbExpScores.SetValue(1)
            self.cbExpPcLoads.Show(0)
            self.cbExpEigs.Show(0)
            self.cbExpPerVar.Show(0)
        if type == 'GA':
            self.cbExpScores.SetLabel('Export chromosomes')
            self.cbExpPcLoads.SetLabel('Export fitness scores')
            self.cbExpEigs.SetLabel('Export opt. curves')
            self.cbExpPerVar.Show(0)
            self.stHcluster.Show(0)
            self.scoresave = '//chroms.txt'
            self.loadsave = '//scores.txt'
            self.eigsave = '//curves.txt'
        
    def OnBtnBrowseButton(self, event):
        dlg = wxDirDialog(self)
        try:
            if dlg.ShowModal() == wxID_OK:
                dir = dlg.GetPath()
                self.tcSavePcaBrowse.SetValue(dir)
                self.Path = dir
        finally:
            dlg.Destroy()

    def OnBtnOKButton(self, event):
        self.OK = 1
        self.Close()

    def OnBtnCancelButton(self, event):
        self.OK = 0
        self.Close()

    def GetButtonEvent(self):
        return self.OK
    
    def SaveScores(self,scores):
        if self.cbExpScores.GetValue() == 1:
            save(scores,join((self.Path ,self.scoresave),''))
    
    def SaveLoadings(self,loadings):
        if self.cbExpPcLoads.GetValue() == 1:
            save(loadings,join((self.Path ,self.loadsave),''))
            
    def SaveEigs(self,eigs):
        if self.cbExpEigs.GetValue() == 1:
            save(eigs,join((self.Path ,self.eigsave),''))
            
    def SavePerVar(self,pervar):
        if self.cbExpPerVar.GetValue() == 1:
            save(pervar,join((self.Path ,self.explvar),''))
            
    def GetPath(self):
        return self.Path
    
    def CreateVarList(self,num):
        list = []
        for i in range(num):
            list.append(str(i+1))
        return list

    def SaveHcluster(self,path,xdata,names,expid,clusters,linkdist):
        Pycluster.data.writeclusterfiles(join((path ,'//Hcluster'),''), 
        scipy.transpose(xdata), self.CreateVarList(xdata.shape[1]), expid, 
        mask=None, geneclusters=scipy.zeros((xdata.shape[1],2),'l'), 
        genelinkdist=scipy.zeros((xdata.shape[1],),'d'),
        expclusters=scipy.array(clusters,'l'), explinkdist=linkdist)
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -