Esempio n. 1
0
    def test_model(self):
        """PDBDope test final model"""
        from Biskit import PDBModel

        if self.local:
            print '\nData added to info record of model (key -- value):'
            for k in self.d.m.info.keys():
                print '%s -- %s' % (k, self.d.m.info[k])

            print '\nAdded atom profiles:'
            print self.M.atoms

            print '\nAdded residue  profiles:'
            print self.M.residues

            ## check that nothing has changed
            print '\nChecking that models are unchanged by doping ...'

        m_ref = PDBModel(self.f)
        m_ref = m_ref.compress(m_ref.maskProtein())
        for k in m_ref.atoms.keys():
            #ref = [ m_ref.atoms[i][k] for i in m_ref.atomRange() ]
            #mod = [ self.M.atoms[i][k] for i in self.M.atomRange() ]
            self.assert_(N.all(m_ref[k] == self.M[k]))

        ## display in Pymol
        if self.local:
            print "Starting PyMol..."
            from Biskit.Pymoler import Pymoler

            pm = Pymoler()
            pm.addPdb(self.M, 'm')
            pm.colorAtoms('m', N0.clip(self.M.profile('relAS'), 0.0, 100.0))
            pm.show()
Esempio n. 2
0
def logConfidence( x, R, clip=0 ):
    """
    Estimate the probability of x NOT beeing a random observation from a
    lognormal distribution that is described by a set of random values.

    @param x: observed value
    @type  x: float
    @param R: sample of random values
    @type  R: [float]
    @param clip: clip zeros at this value  0->don't clip (default: 0)
    @type  clip: float

    @return: confidence that x is not random, median of random distr.
    @rtype: (float, float)
    """
    if clip and 0 in R:
        R = N0.clip( R, clip, max( R ) )
    if clip and x == 0:
        x = clip

    ## remove 0 instead of clipping
    R = N0.compress( R, R )
    if x == 0:
        return 0, 0

    ## get mean and stdv of log-transformed random sample
    alpha = N0.average( N0.log( R ) )

    n = len( R )

    beta = N0.sqrt(N0.sum(N0.power(N0.log( R ) - alpha, 2)) / (n - 1.))

    return logArea( x, alpha, beta ), logMedian( alpha )
Esempio n. 3
0
    def test_conservation(self):
        """PDBDope.addConservation (Hmmer) test"""
        if self.local: print "Adding conservation data...",
        self.d.addConservation()
        if self.local: print 'Done.'

        ## display in Pymol
        if self.local:
            print "Starting PyMol..."
            from Biskit.Pymoler import Pymoler

            pm = Pymoler()
            pm.addPdb(self.M, 'm')
            pm.colorAtoms('m', N0.clip(self.M.profile('cons_ent'), 0.0, 100.0))
            pm.show()
Esempio n. 4
0
    def fractionNativeSurface(self, cont, contRef):
        """
        fraction of atoms/residues that are involved in B{any} contacts
        in both complexes.

        @param cont: contact matrix
        @type  cont: matrix
        @param contRef: reference contact matrix
        @type  contRef: matrix
        
        @return: (fractRec, fractLig), fraction of atoms/residues that
                  are involved in any contacts in both complexes
        @rtype: (float, float)
           
        """
        lig, ligRef = N0.clip(N0.sum(cont), 0,
                              1), N0.clip(N0.sum(contRef), 0, 1)
        rec = N0.clip(N0.sum(cont, 1), 0, 1)
        recRef = N0.clip(N0.sum(contRef, 1), 0, 1)

        fLig = N0.sum(N0.logical_and(lig, ligRef)) * 1. / N0.sum(ligRef)
        fRec = N0.sum(N0.logical_and(rec, recRef)) * 1. / N0.sum(recRef)

        return (fRec, fLig)
Esempio n. 5
0
def relExposure(model, absSurf, key='AS', clip=1):
    """
    Calculate how exposed an atom is relative to the same
    atom in a GLY-XXX-GLY tripeptide, an approximation of
    the unfolded state.

    @param absSurf: Absolute MS OR AS values
    @type  absSurf: [float]
    @param key: MS or AS
    @type  key: MS|AS
    @param clip: clip values above 100% (default: 1)
    @type  clip: 1|0
    
    @return: rel - list of relative accessible surfaces
    @rtype: [float]
    """
    if not key == 'MS' and not key == 'AS':
        raise Exception,\
              'Incorrect key for relative exposiure: %s '%key

    rel = []
    i = 0

    ## loop over chains
    for j in range(model.lenChains()):
        c = model.takeChains([j])

        k = 0
        cIdx = c.resIndex()
        ## and loop over atoms in chain
        for a in c.atoms.iterDicts():
            ## N-terminal residue
            if k < cIdx[1]:
                rel = __Nter(a, rel, absSurf, key, i)
            ## C-terminal residue
            if k >= cIdx[-1]:
                rel = __Cter(a, rel, absSurf, key, i)
            ## everything but N- and C termini
            if not k < cIdx[1] and not k >= cIdx[-1]:
                rel = __bulk(a, rel, absSurf, key, i)
            i += 1
            k += 1

    if clip:
        return N0.clip(N0.array(rel), 0.0, 100.0)
    else:
        return N0.array(rel)
Esempio n. 6
0
def logConfidence(x, R, clip=1e-32):
    """
    Estimate the probability of x NOT beeing a random observation from a
    lognormal distribution that is described by a set of random values.
    The exact solution to this problem is in L{Biskit.Statistics.lognormal}.

    @param x: observed value
    @type  x: float
    @param R: sample of random values; 0 -> don't clip (default: 1e-32)
    @type  R: [float]
    @param clip: clip zeros at this value
    @type  clip: float

    @return:  confidence that x is not random, mean of random distrib.
    @rtype: (float, float)
    """
    if clip and 0 in R:
        R = N0.clip(R, clip, max(R))
    ## get mean and stdv of log-transformed random sample
    mean = N0.average(N0.log(R))

    n = len(R)

    stdv = N0.sqrt(N0.sum(N0.power(N0.log(R) - mean, 2)) / (n - 1.))

    ## create dense lognormal distribution representing the random sample
    stop = max(R) * 50.0
    step = stop / 100000
    start = step / 10.0

    X = [(v, p_lognormal(v, mean, stdv)) for v in N0.arange(start, stop, step)]

    ## analyse distribution
    d = Density(X)

    return d.findConfidenceInterval(x * 1.0)[0], d.average()
Esempio n. 7
0
 def calc_membership_matrix(self, d2):
     ## remove 0s (if a cluster center is exactly on one item)
     d2 = N0.clip( d2, N0.power(1e200, 1-self.w), 1e300 )
     q = N0.power(d2, 1. / (1. - self.w))
     return q / N0.sum(q)