示例#1
0
 def commitFunction(self):
     if unicode(self.RFunctionParam_object) == '': return
     injection = []
     inj = ','.join(injection)
     self.R(self.Rvariables['na.omit'] + '<-na.omit(object=' +
            unicode(self.RFunctionParam_object) + ',' + inj + ')',
            wantType='NoConversion')
     thisdataclass = self.R('class(' + self.Rvariables['na.omit'] + ')')
     if type(thisdataclass
             ) == list:  #this is a special R type so just send as generic
         self.rSend("id3", self.data)
     elif type(thisdataclass) == str:
         if thisdataclass == 'numeric':  # we have a numeric vector as the object
             newData = redRRVector(data=self.Rvariables['na.omit'])
             newData.dictAttrs = self.data.dictAttrs.copy()
             self.rSend("id2", newData)
             self.status.setText(
                 _('Data  sent through the R Vector channel'))
         elif thisdataclass == 'character':  #we have a character vector as the object
             newData = redRRVector(data=self.Rvariables['na.omit'])
             newData.dictAttrs = self.data.dictAttrs.copy()
             self.rSend("id2", newData)
             self.status.setText(
                 _('Data  sent through the R Vector channel'))
         elif thisdataclass == 'data.frame':  # the object is a data.frame
             newData = redRRDataFrame(data=self.Rvariables['na.omit'])
             newData.dictAttrs = self.data.dictAttrs.copy()
             self.rSend("id0", newData)
             self.status.setText(
                 _('Data  sent through the R Data Frame channel'))
         elif thisdataclass == 'matrix':  # the object is a matrix
             newData = rmat.RMatrix(data=self.Rvariables['na.omit'])
             newData.dictAttrs = self.data.dictAttrs.copy()
             self.rSend("id0", newData)
             self.status.setText(
                 _('Data  sent through the R Data Frame channel'))
         elif thisdataclass == 'list':  # the object is a list
             newData = redRRList(data=self.Rvariables['na.omit'])
             newData.dictAttrs = self.data.dictAttrs.copy()
             self.rSend("id1", newData)
             self.status.setText(_('Data  sent through the R List channel'))
         else:  # the data is of a non-normal type send anyway as generic
             newData = redRRVariable(data=self.Rvariables['na.omit'])
             newData.dictAttrs = self.data.dictAttrs.copy()
             self.rSend("id3", newData)
             self.status.setText(
                 _('Data  sent through the R Object channel'))
     else:
         newData = redRRVariable(data=self.Rvariables['na.omit'])
         newData.dictAttrs = self.data.dictAttrs.copy()
         self.rSend("id3", newData)
         self.status.setText(_('Data  sent through the R Object channel'))
示例#2
0
    def commitFunction(self, userClick=True):
        if not userClick and _(
                'Commit on Input') not in self.autoCommit.getChecked():
            return
        if unicode(self.RFunctionParam_x) == '':
            self.status.setText(_('No data'))
            return

        injection = []
        if self.function.getChecked() == _('Row Names'):
            function = 'rownames'
        else:
            function = 'colnames'

        if unicode(self.RFunctionParamprefix_lineEdit.text()) != '':
            string = 'prefix="' + unicode(
                self.RFunctionParamprefix_lineEdit.text()) + '"'
            injection.append(string)
        if unicode(self.doNullButton.getChecked()):
            string = 'do.NULL=' + unicode(self.doNullButton.getChecked())
            injection.append(string)
        inj = ','.join(injection)
        self.R(self.Rvariables['rownames'] + '<-' + function + '(x=' +
               unicode(self.RFunctionParam_x) + ',' + inj + ')',
               wantType='NoConversion')

        newData = redRRVector(data=self.Rvariables["rownames"])

        self.rSend("id0", newData)
示例#3
0
    def identify(self, kill=True):
        if self.plotdata == '': return
        ## needs to be rewritten for Red-R 1.85 which uses rpy3.  no interactivity with graphics.

        self.R(self.Rvariables['hclust'] + '<-hclust(dist(t(' + self.plotdata +
               ')))')

        ## now there is a plot the user must select the number of groups or the height at which to make the slices.
        print unicode(self.groupOrHeight.getChecked())
        if unicode(self.groupOrHeight.getChecked()) == 'Groups':
            inj = 'k = ' + unicode(self.groupOrHeightSpin.value())
        else:
            inj = 'h = ' + unicode(self.groupOrHeightSpin.value())
        self.R(self.Rvariables['heatsubset'] + '<-cutree(' +
               self.Rvariables['hclust'] + ', ' + inj + ')')
        self.gview1.plotMultiple(
            query=self.Rvariables['hclust'] +
            ',col = %s' % self.Rvariables['heatsubset'],
            layers=[
                'rect.hclust(%s, %s, cluster = %s, which = 1:%s, border = 2:(%s + 1))'
                %
                (self.Rvariables['hclust'], inj, self.Rvariables['heatsubset'],
                 self.groupOrHeightSpin.value(),
                 self.groupOrHeightSpin.value())
            ])
        newData = redRRVector(data='as.vector(' +
                              self.Rvariables['heatsubset'] + ')',
                              parent=self.Rvariables['heatsubset'])
        self.rSend("id1", newData)
示例#4
0
 def sendThis(self):
     if unicode(self.command.textCursor().selectedText()) != '':
         text = unicode(self.command.textCursor().selectedText())
     else:
         self.sendStatus.setText(_('No object Selected'))
         return
     thisdataclass = self.R('class(' + unicode(text) + ')')
     thisdata = unicode(text)
     # use upclassing to convert to signals class
     if thisdataclass.__class__.__name__ == 'list':  #this is a special R type so just send as generic
         newData = redRRVariable(data=unicode(text))
         self.rSend("id3", newData)
     elif thisdataclass.__class__.__name__ == 'str':
         if thisdataclass in ['numeric', 'character', 'logical'
                              ]:  # we have a numeric vector as the object
             newData = redRRVector(data=unicode(text))
             self.rSend("id2", newData)
             self.sendStatus.setText(
                 thisdata + _(' sent through the R Vector channel'))
         elif thisdataclass in ['data.frame']:
             newData = redRRDataFrame(data=unicode(text))
             self.rSend("id0", newData)
             self.sendStatus.setText(
                 thisdata + _(' sent through the R Data Frame channel'))
         elif thisdataclass in ['matrix']:
             newData = redRRMatrix(data=unicode(text))
             self.rSend("id4", newData)
             self.sendStatus.setText(thisdata +
                                     _(' sent through the Matrix channel'))
         elif thisdataclass == 'list':  # the object is a list
             for i in range(self.R('length(' + text + ')')):
                 if self.R('class(%s[[%s]])' % (text, i),
                           silent=True) not in [
                               'numeric', 'character', 'real', 'complex',
                               'factor'
                           ]:
                     newData = ral.RArbitraryList(data=self.sendThis)
                     self.status.setText(
                         _('Data sent through the R Arbitrary List channel')
                     )
                     self.rSend('ral', newData)
                     return
             newData = redRRList(data=unicode(text))
             self.rSend("id1", newData)
             self.sendStatus.setText(thisdata +
                                     _(' sent through the R List channel'))
         else:  # the data is of a non-normal type send anyway as generic
             newData = redRRVariable(data=unicode(text))
             self.rSend("id3", newData)
             self.sendStatus.setText(
                 thisdata + _(' sent through the R Object channel'))
     else:
         newData = redRRVariable(data=unicode(text))
         self.rSend("id3", newData)
         self.sendStatus.setText(thisdata +
                                 ' sent through the R Object channel')
示例#5
0
    def commitFunction(self):
        if self.dataA and self.dataB:
            h = self.R('intersect(names(' + self.dataA + '), names(' +
                       self.dataB + '))',
                       wantType='list')
        else:
            return

        if self.colA.selectedItems():
            nameA = self.colA.selectedItems()[0].text()
        else:
            nameA = None
        if self.colB.selectedItems():
            nameB = self.colB.selectedItems()[0].text()
        else:
            nameB = None

        if self.type.getChecked() == _('Intersect'):
            func = 'intersect'
        elif self.type.getChecked() == _('Union'):
            func = 'union'
        elif self.type.getChecked() == _('Set Difference'):
            func = 'setdiff'
        elif self.type.getChecked() == _('Set Equal'):
            func = 'setequal'
        else:
            return

        if nameA and nameB:
            self.R(self.Rvariables['intersect'] +
                   '<-%s(y=%s[["%s"]],x=%s[["%s"]])' %
                   (func, self.dataA, nameA, self.dataB, nameB),
                   wantType='NoConversion')
        elif len(h) == 1:
            self.R(self.Rvariables['intersect'] +
                   '<-%s(y=%s[["%s"]],x=%s[["%s"]])' %
                   (func, self.dataA, h[0], self.dataB, h[0]),
                   wantType='NoConversion')
        else:
            return

        if self.type.getChecked() == _('Set Equal'):
            eq = self.R(self.Rvariables['intersect'])
            if eq:
                self.resultInfo.setPlainText('%s is equal to %s' %
                                             (nameA, nameB))
            else:
                self.resultInfo.setPlainText('%s is not equal to %s' %
                                             (nameA, nameB))
        else:
            newData = redRRVector(data=self.Rvariables["intersect"])
            self.rSend("id0", newData)
示例#6
0
    def commitFunction(self):        
        # START COLLECTION THE R PARAMETERS THAT WILL CREATE THE R CODE TO EXECUTE
        dist = unicode(self.methodButtons.currentId())
        self.injection = self.collectParameters()
        

        # combine all the parameters in the a string    
        inj = ','.join(self.injection)
        
        # make the R call. The results will be saved in the 'cor' variable we declared earlier
        self.R('%s <- %s(%s,%s)' % (self.Rvariables['distri'], dist, self.count.value(),inj), wantType = 'NoConversion')
        
        # create a new signal of type RMatrix and load the results 
        newData = redRRVector(data = '%s' % self.Rvariables["distri"]) 
        # send the signal forward
        self.rSend("id0", newData)
示例#7
0
    def sendSelection(self):
        #print self.names.selectedItems()[0]
        if self.data == None:
            self.status.setText('No data to process')
            return
        name = unicode(self.names.row(self.names.currentItem()) + 1)
        self.Rvariables['listelement'] = self.data + '[[' + name + ']]'
        # use signals converter in OWWidget to convert to the signals class
        myclass = self.R('class(' + self.Rvariables['listelement'] + ')')
        print myclass
        if myclass == 'data.frame':

            newData = redRRDataFrame(data=self.Rvariables['listelement'],
                                     parent=self.Rvariables['listelement'])
            self.rSend("id0", newData)
            #self.infoa.setText('Sent Data Frame')
            slot = 'Data Frame'
        elif myclass == 'list':
            newData = redRRList(data=self.Rvariables['listelement'])
            self.rSend("id2", newData)
            #self.infoa.setText('Sent List')
            slot = 'List'
        elif myclass in [
                'vector', 'character', 'factor', 'logical', 'numeric',
                'integer', ['POSIXt', 'POSIXct']
        ]:
            newData = redRRVector(data=self.Rvariables['listelement'])
            self.rSend("id1", newData)
            #self.infoa.setText('Sent Vector')
            slot = 'Vector'
        elif myclass in ['matrix']:
            newData = redRRMatrix(data=self.Rvariables['listelement'])
            self.rSend("id4", newData)
            #self.infoa.setText('Sent Matrix')
            slot = 'Matrix'
        else:
            newData = redRRVariable(data=self.Rvariables['listelement'])
            self.rSend("id3", newData)
            slot = 'R Variable'

        self.infoa.setText(
            _('Sent %(NAME)s as %(SLOT)s') % {
                'NAME': name,
                'SLOT': slot
            })
示例#8
0
    def commitFunction(self):
        if unicode(self.RFunctionParam_y) == '':
            self.status.setText(_('No Y data exists'))
            return
        if unicode(self.RFunctionParam_x) == '':
            self.status.setText(_('No X data exists'))
            return
        self.R(self.Rvariables['intersect'] + '<-intersect(y=' +
               unicode(self.RFunctionParam_y) + ',x=' +
               unicode(self.RFunctionParam_x) + ')',
               wantType='NoConversion')
        self.R('txt<-capture.output(' + self.Rvariables['intersect'] + ')',
               wantType='NoConversion')

        self.RoutputWindow.clear()
        tmp = self.R('paste(txt, collapse =" \n")')
        self.RoutputWindow.insertHtml(
            _('<br><br><pre>Shared elements between your inputs:\n') +
            unicode(tmp) + '</pre>')
        newData = redRRVector(data=self.Rvariables["intersect"])

        self.rSend("id0", newData)
示例#9
0
    def commitFunction(self):
        if unicode(self.RFunctionParam_x) == '':
            self.status.setText(_('No Data to Split'))
            return
        if unicode(self.RFunctionParamsplit_lineEdit.text()) == '':
            self.status.setText(_('No string to split on'))
            return
        injection = []
        if unicode(self.RFunctionParamfixed_radioButtons.getChecked()) == _(
                'Yes'):
            string = 'fixed=TRUE'
            injection.append(string)
        else:
            string = 'fixed=FALSE'
            injection.append(string)
        if unicode(self.RFunctionParamextended_radiButtons.getChecked()) == _(
                'Yes'):
            string = 'extended=TRUE'
            injection.append(string)
        else:
            string = 'extended=FALSE'
            injection.append(string)
        if unicode(self.RFunctionParamsplit_lineEdit.text()) != '':
            string = 'split=' + unicode(
                self.RFunctionParamsplit_lineEdit.text()) + ''
            injection.append(string)
        if unicode(
                self.RFunctionParamperl_radioButtons.getChecked()) == _('Yes'):
            string = 'perl=TRUE'
            injection.append(string)
        else:
            string = 'perl=FALSE'
            injection.append(string)
        inj = ','.join(injection)
        self.R(self.Rvariables['strsplit'] + '<-strsplit(x= as.character(' +
               unicode(self.RFunctionParam_x) + ') ,' + inj + ')',
               wantType='NoConversion')
        newData = redRRList(
            data=self.Rvariables["strsplit"]
        )  # moment of variable creation, no preexisting data set.  To pass forward the data that was received in the input uncomment the next line.
        #newData.copyAllOptinoalData(self.data)  ## note, if you plan to uncomment this please uncomment the call to set self.data in the process statemtn of the data whose attributes you plan to send forward.
        self.rSend("id0", newData)

        if unicode(self.RFunctionParamunlist_radioButtons.getChecked()) == _(
                'Send list and vector'):
            newData = redRRVector(data='unlist(' +
                                  self.Rvariables['strsplit'] + ')')
            self.rSend("id1", newData)

        ## convert to a data frame
        self.R("""
        for(i in 1:length(%s)){
            if(length(%s[[i]]) == 0){
                %s[[i]] = c('','')
            }
        }
        """ % (self.Rvariables['strsplit'], self.Rvariables['strsplit'],
               self.Rvariables['strsplit']),
               wantType='NoConversion',
               silent=True)
        self.R(self.Rvariables['dataframe'] + '<-t(data.frame(' +
               self.Rvariables['strsplit'] + '))',
               wantType='NoConversion')
        newDataFrame = redRDataFrame(data=self.Rvariables['dataframe'],
                                     parent=self.Rvariables['dataframe'],
                                     checkVal=False)
        self.rSend('dataframe', newDataFrame)