def chipdata(self, data):
     """Input data: [(dirname0, [et0, et1, ...]), ...]
     """
     self.numRowsMissingChipData = 0
     self._chipdataMA = []
     if data != None:
         self._chipdata = data
         numValsAll = 0
         numValsNonMasked = 0
         numFiles = 0
         numExamplesList = []
         attribDict = {}
         numColMissing = 0
         for (name, etList) in data:
             numFiles += len(etList)
             self._chipdataMA.append((name, []))
             for et in etList:
                 attribDict.update(
                     dict(
                         zip(map(lambda x: x.name, et.domain.attributes),
                             et.domain.attributes)))
                 numExamplesList.append(len(et))
                 etm = et.toNumpyMA("a")[0]
                 colNonMissingInd = Numeric.compress(
                     Numeric.not_equal(MA.count(etm, 0), 0),
                     Numeric.arange(etm.shape[1])
                 )  # indices of columns that are not completely missing
                 numColMissing += etm.shape[1] - colNonMissingInd.shape[0]
                 self.numRowsMissingChipData += int(
                     Numeric.add.reduce(
                         Numeric.less(
                             MA.count(etm.take(colNonMissingInd, 1), 1),
                             etm.shape[1])))
                 numValsAll += int(Numeric.multiply.reduce(etm.shape))
                 numValsNonMasked += int(MA.count(etm))
                 self._chipdataMA[-1][1].append(etm)
         # info text
         self.infoc.setText(
             "Structured Data: %i data files with %i profiles on %i points"
             % (numFiles, numExamplesList[0], len(attribDict)))
         numTotalMissing = numValsAll - numValsNonMasked
         if numTotalMissing > 0:
             print numTotalMissing, numColMissing, self.numRowsMissingChipData
             print type(numTotalMissing), type(numColMissing), type(
                 self.numRowsMissingChipData)
             self.infod.setText(
                 "missing %i values, %i column%s completely, %i row%s partially"
                 % (numTotalMissing, numColMissing, [
                     "", "s"
                 ][numColMissing != 1], self.numRowsMissingChipData,
                    ["", "s"][self.numRowsMissingChipData != 1]))
         else:
             self.infod.setText("")
     else:
         self._chipdata = None
         self.infoc.setText("No structured data on input")
         self.infod.setText("")
     self.setGuiCommonExpChip()
     if self.commitOnChange:
         self.senddata(2)
Exemple #2
0
 def filter(self, dlg):
     fptr = open(dlg)
     dlg_lines = fptr.readlines()
     fptr.close()
     #STEP 1:accumulate lines of various poses
     model_lines = []
     #keep all of them
     all_models = []
     in_model = False
     for ll in dlg_lines:
         if ll.find("DOCKED:") == 0:
             #check for a new model
             if ll.find("DOCKED: MODEL") == 0:
                 model_lines = []
             in_model = True
             model_lines.append(ll)
         if ll.find("_") == 0 and in_model:
             all_models.append(model_lines)
             model_lines = []
             in_model = False
     #initialize this ligand
     # loop over the models:
     for model_lines in all_models:
         self.setup_ligand(model_lines)
         bigR = self.bigRC[:self.lenK]
         bigM = self.bigC[:self.lenK]
         cutoff = bigR + self.keyRadii
         d = bigM - self.smallM
         dSQ = d * d
         dSQMAT = Numeric.sum(dSQ, 2)
         cutoffSQMAT = cutoff * cutoff
         ansMat = Numeric.logical_and(Numeric.less(dSQMAT, cutoffSQMAT),
                                      Numeric.not_equal(dSQMAT, 0.))
         rowIndices = Numeric.nonzero(Numeric.sum(ansMat, 1))
         num_contacts = 0
         for ind in rowIndices:
             for j in ansMat[ind]:
                 if j: num_contacts += 1
         if num_contacts > 0:
             break
     return num_contacts
Exemple #3
0
 def filter(self, dlg):
     fptr = open(dlg)
     dlg_lines = fptr.readlines()
     fptr.close()
     #STEP 1:accumulate lines of various poses
     model_lines = []
     #keep all of them
     all_models = []
     in_model = False
     for ll in dlg_lines:
         if ll.find("DOCKED:")==0:
             #check for a new model
             if ll.find("DOCKED: MODEL")==0:
                 model_lines = []
             in_model = True
             model_lines.append(ll)
         if ll.find("_")==0 and in_model:
             all_models.append(model_lines)
             model_lines = []
             in_model = False
     #initialize this ligand 
     # loop over the models:
     for model_lines in all_models:
         self.setup_ligand(model_lines)
         bigR = self.bigRC[:self.lenK]
         bigM = self.bigC[:self.lenK]
         cutoff = bigR + self.keyRadii
         d = bigM - self.smallM
         dSQ = d*d
         dSQMAT = Numeric.sum(dSQ,2)
         cutoffSQMAT = cutoff*cutoff
         ansMat = Numeric.logical_and(Numeric.less(dSQMAT, cutoffSQMAT),Numeric.not_equal(dSQMAT, 0.))
         rowIndices = Numeric.nonzero(Numeric.sum(ansMat,1))
         num_contacts = 0
         for ind in rowIndices:
             for j in ansMat[ind]: 
                 if j: num_contacts+=1
         if num_contacts > 0:
             break 
     return num_contacts
Exemple #4
0
    def select(self, keyAts, checkAts, cutoff=3.0, percentCutoff=1.0, 
                keyMat=None, checkMat=None):
        """ keyAts, checkAts, cutoff, percentCutoff
            keyAts: first set of atoms
            checkAts: a second set of atoms which is checked vs. keyAts
            cutoff: 
                either a single float by default 3.0 
                or a matrix with shape:
            (max(len(keyAts),len(checkAts)), min(len(keyAts),len(checkAts)))
            percentCutoff: by default 1.0 (cutoff is multiplied by this value)
            keyMat: transformation of keyAts
            checkMat: transformation of checkAts

        returns 'pairDict' whose keys are atoms used as reference points and whose 
        values are atoms within cutoff distance of corresponding key. 

        If 'return_dist' flag is set, 
        'distDict' is returned also, whose keys are 
        the same atoms which are used as reference points and whose values are 
        lists of distances to atoms  within cutoff distance of corresponding key

        """
        lenK = len(keyAts)
        lenC = len(checkAts)

        #data arrays are used to find atoms with given indices quickly
        atar = Numeric.array(checkAts.data)
        keyAtar = Numeric.array(keyAts.data)

        #basic arrays of coords used to build others
        c = Numeric.array(checkAts.coords, 'f')
        if checkMat:
            c = self.mul(c, checkMat)
        k = Numeric.array(keyAts.coords, 'f')
        if keyMat:
            k = self.mul(k, keyMat)

        # first build matrix of distances between all pairs of ats
        # rows correspond to ats in larger set, columns to those in smaller
        # first build square matrix
        if lenC >= lenK:
            bigC = Numeric.resize(c, (lenC, lenC, 3))
            k.shape = (lenK,1,3)
            bigM = bigC[:lenK]
            smallM = k

            cutoff = self.setupCutoff(checkAts, keyAts, cutoff)
            #print "0a:cutoff[0][0]=", cutoff[0][0]
            cutoff.shape = (lenK, -1)

        else:
            bigK = Numeric.resize(k, (lenK, lenK, 3))
            c.shape = (lenC,1,3)
            bigM = bigK[:lenC]
            smallM = c
            cutoff = self.setupCutoff(keyAts, checkAts, cutoff)
            #print "0b:cutoff[0][0]=", cutoff[0][0]
            cutoff.shape = (lenC, -1)

        # distance matrix
        d = bigM - smallM
        # distance squared matrix
        dSQ = d * d
        # next step sums deltaX**2, deltaY**2, deltaZ**2
        dSQMAT = Numeric.sum(dSQ,2)

        #percentCutoff lets user relax sum of radii
        #the smaller the percentCutoff the smaller the key 
        #dSQ has to be less than
        cutoff = cutoff * percentCutoff
        cutoffSQMAT = cutoff * cutoff
        #cutoffSQMAT = cutoffSQMAT * percentCutoff

        # ansMat has 1 where sq dist. is smaller than cutoff
        ansMat = Numeric.logical_and(self.func(dSQMAT, cutoffSQMAT) , \
                    Numeric.not_equal(dSQMAT, 0.))
        if lenK > lenC:
            # in this case need to rearrange matrix
            # which got shuffled in if-else above
            ansMat = Numeric.swapaxes(ansMat, 0, 1)
            dSQMAT = Numeric.swapaxes(dSQMAT, 0, 1)

        # finally, build result dictionaries which have atom keys:
        #   pairDict has values which are lists of close atoms
        #   distDict has values which are lists of distances
        pairDict = {}
        distDict = {}
        # get a list of rows which have non-zero entries 
        # to loop over in next section
        rowIndices = Numeric.nonzero(Numeric.sum(ansMat,1))
        # rows correspond to ats in keyAts
        # columns correspond to ats in checkAts
        for i in rowIndices:
            # atindex is a list [7 8 9] indexing into checkAts 
            atindex = Numeric.nonzero(ansMat[i])
            # keyAtar[i] is ith atom in keyAts
            keyAt = keyAtar[i]
            pairDict[keyAt] = Numeric.take(atar, atindex)
            if self.return_dist:
                distDict[keyAt] = []
                for ind in atindex:
                    distDict[keyAt].append(math.sqrt(dSQMAT[i][ind]))
        
        #getting distDict back is optional
        if self.return_dist: return pairDict, distDict
        else: return pairDict