/compositions/widgets/isoTransformInv.py

http://redr-grrr.googlecode.com/ · Python · 127 lines · 95 code · 17 blank · 15 comment · 18 complexity · 840d2145dc2f89ef6e4349891dc5ff9f MD5 · raw file

  1. from OWRpy import *
  2. import redRi18n
  3. _ = redRi18n.get_(package = 'base')
  4. import signals
  5. import redRGUI
  6. class isoTransformInv(OWRpy):
  7. settingsList = []
  8. def __init__(self, **kwargs):
  9. OWRpy.__init__(self, **kwargs)
  10. # Unique R variables
  11. self.setRvariableNames(["invIsometric", "defaultILRbase"])
  12. # Python variables
  13. self.data = {}
  14. self.RFunctionParam_x = ''
  15. self.SBP = ''
  16. self.isoOpCommand = ''
  17. # Inputs
  18. self.inputs.addInput("x", "Iso transformed data", signals.base.RMatrix, self.processx)
  19. self.inputs.addInput("SBP", "Sequential binary partition", signals.base.RMatrix, self.processSBP)
  20. # Output
  21. self.outputs.addOutput("Inv. isoTransform Output","Inv. isoTransform Output", signals.base.RMatrix)
  22. # GUI
  23. area = redRGUI.base.widgetBox(self.controlArea,orientation='vertical')
  24. compType = redRGUI.base.groupBox(area, label='Select composition type to go back to:')
  25. self.size = redRGUI.base.radioButtons(compType, label = "Size signifiance",
  26. buttons = ['Yes','No'], setChecked='No',orientation='horizontal', callback = self.onTestChange)
  27. self.scale = redRGUI.base.radioButtons(compType, label = "Natural scale",
  28. buttons = [('real','Difference (real)'),('log','Quotient (log)')], setChecked='log',orientation='horizontal', callback = self.onTestChange)
  29. self.total = redRGUI.base.lineEdit(compType, label = "total:", text = '1')
  30. self.method = redRGUI.base.lineEdit(compType, label = "Method:", text = 'acomp')
  31. self.method.setDisabled(True)
  32. self.invCentOpLabel = redRGUI.base.lineEdit(compType, label = "Inverse operation:", text = 'Inverse Isometric log ratio')
  33. self.invCentOpLabel.setDisabled(True)
  34. self.invCentOpCommand = 'ilrInv'
  35. # GUI - SBP
  36. if self.SBP == '':
  37. self.status.setText('SBP is missing. Default will be used.')
  38. self.sbpOrigin = redRGUI.base.lineEdit(area, label = "SBP origin:", text = 'Default')
  39. self.sbpOrigin.setDisabled(True)
  40. # GUI - Commit
  41. self.commit = redRGUI.base.commitButton(self.bottomAreaRight, _("Commit"), alignment=Qt.AlignRight,
  42. callback = self.commitFunction, processOnInput=True)
  43. def onTestChange(self):
  44. if self.size.getChecked() =='Yes' and self.scale.getChecked() =='Difference (real)' :
  45. self.method.setText('rplus')
  46. self.invCentOpLabel.setText('Inverse Isometric identity transform')
  47. self.invCentOpCommand = 'iitInv'
  48. self.total.setDisabled(True)
  49. elif self.size.getChecked() =='Yes' and self.scale.getChecked() =='Quotient (log)' :
  50. self.method.setText('aplus')
  51. self.invCentOpLabel.setText('Inverse Isometric log transform')
  52. self.invCentOpCommand = 'iltInv'
  53. self.total.setDisabled(True)
  54. elif self.size.getChecked() =='No' and self.scale.getChecked() =='Difference (real)' :
  55. self.method.setText('rcomp')
  56. self.invCentOpLabel.setText('Inverse Isometric planar transform')
  57. self.invCentOpCommand = 'iptInv'
  58. self.total.setEnabled(True)
  59. elif self.size.getChecked() =='No' and self.scale.getChecked() =='Quotient (log)' :
  60. self.method.setText('acomp')
  61. self.invCentOpLabel.setText('Inverse Isometric log-ratio transform')
  62. self.invCentOpCommand = 'ilrInv'
  63. self.total.setEnabled(True)
  64. def processx(self, data):
  65. if not self.require_librarys(["compositions"]):
  66. self.status.setText('R Libraries Not Loaded.')
  67. return
  68. if data:
  69. self.RFunctionParam_x=data.getData()
  70. #self.data = data
  71. self.commitFunction()
  72. else:
  73. self.RFunctionParam_x=''
  74. def processSBP(self, data):
  75. if not self.require_librarys(["compositions"]):
  76. self.status.setText('R Libraries Not Loaded.')
  77. return
  78. if data:
  79. self.status.setText('Custom SBP will be used.')
  80. self.SBP=data.getData()
  81. #self.data = data
  82. self.sbpOrigin.setText('Custom')
  83. self.commitFunction()
  84. else:
  85. self.SBP=''
  86. self.sbpOrigin.setText('Default')
  87. self.commitFunction()
  88. def commitFunction(self):
  89. if str(self.RFunctionParam_x) == '':
  90. self.status.setText('Compositionnal data is missing.')
  91. return
  92. # SBP: if no SBP, create default, else import from Input
  93. if self.SBP == '':
  94. self.R(self.Rvariables['defaultILRbase']+'<-ilrBase(z='+str(self.RFunctionParam_x)+')')
  95. else:
  96. self.R(self.Rvariables['defaultILRbase']+'<-gsi.buildilrBase(t(as.data.frame('+str(self.SBP)+')))')
  97. ncolX=self.R('ncol('+str(self.RFunctionParam_x)+')')
  98. ncolSBP=self.R('ncol('+str(self.SBP)+')')
  99. #if ncolX != ncolSBP:
  100. # self.status.setText('SBP has wrong dimensions.')
  101. # return
  102. injection = []
  103. string = 'V='+self.Rvariables['defaultILRbase']+''
  104. injection.append(string)
  105. inj = ','.join(injection)
  106. # Compute isometric transformation
  107. self.R(self.Rvariables['invIsometric']+'<-'+self.invCentOpCommand+'(z='+str(self.RFunctionParam_x)+','+inj+')')
  108. # Send data
  109. newData = signals.base.RMatrix(self, data = self.Rvariables['invIsometric'], checkVal = False)
  110. self.rSend("Inv. isoTransform Output", newData)