/compositions/widgets/isoTransformInv.py
http://redr-grrr.googlecode.com/ · Python · 127 lines · 95 code · 17 blank · 15 comment · 18 complexity · 840d2145dc2f89ef6e4349891dc5ff9f MD5 · raw file
- from OWRpy import *
- import redRi18n
- _ = redRi18n.get_(package = 'base')
-
- import signals
- import redRGUI
-
- class isoTransformInv(OWRpy):
- settingsList = []
- def __init__(self, **kwargs):
- OWRpy.__init__(self, **kwargs)
-
- # Unique R variables
- self.setRvariableNames(["invIsometric", "defaultILRbase"])
-
- # Python variables
- self.data = {}
- self.RFunctionParam_x = ''
- self.SBP = ''
- self.isoOpCommand = ''
-
- # Inputs
- self.inputs.addInput("x", "Iso transformed data", signals.base.RMatrix, self.processx)
- self.inputs.addInput("SBP", "Sequential binary partition", signals.base.RMatrix, self.processSBP)
-
- # Output
- self.outputs.addOutput("Inv. isoTransform Output","Inv. isoTransform Output", signals.base.RMatrix)
-
- # GUI
- area = redRGUI.base.widgetBox(self.controlArea,orientation='vertical')
- compType = redRGUI.base.groupBox(area, label='Select composition type to go back to:')
- self.size = redRGUI.base.radioButtons(compType, label = "Size signifiance",
- buttons = ['Yes','No'], setChecked='No',orientation='horizontal', callback = self.onTestChange)
- self.scale = redRGUI.base.radioButtons(compType, label = "Natural scale",
- buttons = [('real','Difference (real)'),('log','Quotient (log)')], setChecked='log',orientation='horizontal', callback = self.onTestChange)
- self.total = redRGUI.base.lineEdit(compType, label = "total:", text = '1')
- self.method = redRGUI.base.lineEdit(compType, label = "Method:", text = 'acomp')
- self.method.setDisabled(True)
- self.invCentOpLabel = redRGUI.base.lineEdit(compType, label = "Inverse operation:", text = 'Inverse Isometric log ratio')
- self.invCentOpLabel.setDisabled(True)
- self.invCentOpCommand = 'ilrInv'
-
- # GUI - SBP
- if self.SBP == '':
- self.status.setText('SBP is missing. Default will be used.')
- self.sbpOrigin = redRGUI.base.lineEdit(area, label = "SBP origin:", text = 'Default')
- self.sbpOrigin.setDisabled(True)
-
- # GUI - Commit
- self.commit = redRGUI.base.commitButton(self.bottomAreaRight, _("Commit"), alignment=Qt.AlignRight,
- callback = self.commitFunction, processOnInput=True)
-
- def onTestChange(self):
- if self.size.getChecked() =='Yes' and self.scale.getChecked() =='Difference (real)' :
- self.method.setText('rplus')
- self.invCentOpLabel.setText('Inverse Isometric identity transform')
- self.invCentOpCommand = 'iitInv'
- self.total.setDisabled(True)
- elif self.size.getChecked() =='Yes' and self.scale.getChecked() =='Quotient (log)' :
- self.method.setText('aplus')
- self.invCentOpLabel.setText('Inverse Isometric log transform')
- self.invCentOpCommand = 'iltInv'
- self.total.setDisabled(True)
- elif self.size.getChecked() =='No' and self.scale.getChecked() =='Difference (real)' :
- self.method.setText('rcomp')
- self.invCentOpLabel.setText('Inverse Isometric planar transform')
- self.invCentOpCommand = 'iptInv'
- self.total.setEnabled(True)
- elif self.size.getChecked() =='No' and self.scale.getChecked() =='Quotient (log)' :
- self.method.setText('acomp')
- self.invCentOpLabel.setText('Inverse Isometric log-ratio transform')
- self.invCentOpCommand = 'ilrInv'
- self.total.setEnabled(True)
-
- def processx(self, data):
- if not self.require_librarys(["compositions"]):
- self.status.setText('R Libraries Not Loaded.')
- return
- if data:
- self.RFunctionParam_x=data.getData()
- #self.data = data
- self.commitFunction()
- else:
- self.RFunctionParam_x=''
-
- def processSBP(self, data):
- if not self.require_librarys(["compositions"]):
- self.status.setText('R Libraries Not Loaded.')
- return
- if data:
- self.status.setText('Custom SBP will be used.')
- self.SBP=data.getData()
- #self.data = data
- self.sbpOrigin.setText('Custom')
- self.commitFunction()
- else:
- self.SBP=''
- self.sbpOrigin.setText('Default')
- self.commitFunction()
-
- def commitFunction(self):
- if str(self.RFunctionParam_x) == '':
- self.status.setText('Compositionnal data is missing.')
- return
-
- # SBP: if no SBP, create default, else import from Input
- if self.SBP == '':
- self.R(self.Rvariables['defaultILRbase']+'<-ilrBase(z='+str(self.RFunctionParam_x)+')')
- else:
- self.R(self.Rvariables['defaultILRbase']+'<-gsi.buildilrBase(t(as.data.frame('+str(self.SBP)+')))')
- ncolX=self.R('ncol('+str(self.RFunctionParam_x)+')')
- ncolSBP=self.R('ncol('+str(self.SBP)+')')
- #if ncolX != ncolSBP:
- # self.status.setText('SBP has wrong dimensions.')
- # return
-
- injection = []
- string = 'V='+self.Rvariables['defaultILRbase']+''
- injection.append(string)
- inj = ','.join(injection)
-
- # Compute isometric transformation
- self.R(self.Rvariables['invIsometric']+'<-'+self.invCentOpCommand+'(z='+str(self.RFunctionParam_x)+','+inj+')')
-
- # Send data
- newData = signals.base.RMatrix(self, data = self.Rvariables['invIsometric'], checkVal = False)
- self.rSend("Inv. isoTransform Output", newData)