def CheckLink(self, query_nid, query_from, query_to, sbjct_nid, sbjct_from,
                  sbjct_to):
        """check, whether link is faithfull.
        """

        query_profile = self.GetProfile(query_nid)
        query_profile.useSegment(query_from, query_to)

        sbjct_profile = self.GetProfile(sbjct_nid)
        sbjct_profile.useSegment(sbjct_from, sbjct_to)

        alignator = alignlib.makeFullDP(self.mGop, self.mGep)
        result = alignlib.makeAlignataVector()

        alignator.Align(query_profile, sbjct_profile, result)

        if result.getLength() == 0:
            query_profile.useFullLength()
            sbjct_profile.useFullLength()
            return 0, result

        if self.mLogLevel >= 3:
            print "# --> %i vs %i: score=%5.2f, length=%i, numgaps=%i, row_from=%i, row_to=%i, col_from=%i, col_to=%i" %\
                  (query_nid, sbjct_nid,
                   result.getScore(),
                   result.getLength(),
                   result.getNumGaps(),
                   result.getRowFrom(), result.getRowTo(),
                   result.getColFrom(), result.getColTo())
            sys.stdout.flush()

        if result.getScore() < self.mMinAlignmentScore:
            query_profile.useFullLength()
            sbjct_profile.useFullLength()
            return 0, result

        if result.getScore() > self.mSafetyThreshold * self.mMinAlignmentScore:
            query_profile.useFullLength()
            sbjct_profile.useFullLength()
            return 1, result

        z_params = alignlib.makeNormalDistributionParameters()
        alignlib.calculateZScoreParameters(z_params, query_profile,
                                           sbjct_profile, alignator,
                                           self.mNumIterationsZScore)
        mean = z_params.getMean()
        stddev = z_params.getStandardDeviation()
        if stddev == 0: stddev = 1

        zscore = (result.getScore() - mean) / stddev

        if self.mLogLevel >= 3:
            print "# --> mean=%f, stdev=%f, zscore=%f" % (mean, stddev, zscore)
            sys.stdout.flush()

        query_profile.useFullLength()
        sbjct_profile.useFullLength()

        if zscore > self.mMinZScore:
            return 1, result
        else:
            return 0, result
Пример #2
0
    def checkLinkZScore( self,
                         query_nid, query_from, query_to,
                         sbjct_nid, sbjct_from, sbjct_to):
        """check, whether two domains are homologous.
        
        The check is done using a zscore calculation.
        """

        result = alignlib.makeAlignmentVector()
        
        query_profile = self.getAlignandum( query_nid )
        sbjct_profile = self.getAlignandum( sbjct_nid )

        if not query_profile or not sbjct_profile:
            self.warn( "could not compute link %s_%i_%i - %s_%i_%i\n" % \
                       (query_nid, query_from, query_to,
                        sbjct_nid, sbjct_from, sbjct_to) )
            self.mNNotFound += 1
            return False, result, ("na",)
        
        query_profile.useSegment( query_from, query_to )
        sbjct_profile.useSegment( sbjct_from, sbjct_to )        
        
        self.mAlignator.align( result, query_profile, sbjct_profile )
        
        self.debug( "# --> %s vs %s: score=%5.2f, length=%i, numgaps=%i, row_from=%i, row_to=%i, col_from=%i, col_to=%i" %\
                    (query_nid, sbjct_nid,
                     result.getScore(),
                     result.getLength(),
                     result.getNumGaps(),
                     result.getRowFrom(), result.getRowTo(),
                     result.getColFrom(), result.getColTo()))
        
        if result.getLength() == 0:
            query_profile.useSegment()
            sbjct_profile.useSegment()
            return False, result, ("na",)
        
        elif result.getScore() < self.mMinAlignmentScore:
            query_profile.useSegment()
            sbjct_profile.useSegment()
            return False, result, ("na",)

        elif result.getScore() > self.mSafetyThreshold * self.mMinAlignmentScore:
            query_profile.useSegment()
            sbjct_profile.useSegment()
            return True,result, ("na",)
        
        z_params = alignlib.makeNormalDistributionParameters()
        alignlib.calculateZScoreParameters( z_params,
                                            query_profile,
                                            sbjct_profile,
                                            self.mAlignator,
                                            self.mNumIterationsZScore)
        
        mean   = z_params.getMean()
        stddev = z_params.getStandardDeviation()
        if stddev == 0: stddev = 1
        
        zscore = (result.getScore() - mean) / stddev
        
        self.debug( "--> mean=%f, stdev=%f, zscore=%f" % (mean, stddev, zscore) )
        
        query_profile.useSegment()
        sbjct_profile.useSegment()
        
        if zscore > self.mMinZScore:
            return True, result, ( "%5.2f" % zscore,)
        else:
            return False, result, ( "%5.2f" % zscore,)
    def CheckLink( self,
                   query_nid, query_from, query_to,
                   sbjct_nid, sbjct_from, sbjct_to):
        """check, whether link is faithfull.
        """


        query_profile = self.GetProfile( query_nid )
        query_profile.useSegment( query_from, query_to)

        sbjct_profile = self.GetProfile( sbjct_nid )
        sbjct_profile.useSegment( sbjct_from, sbjct_to)        

        alignator = alignlib.makeFullDP( self.mGop, self.mGep )
        result = alignlib.makeAlignataVector()
        
        alignator.Align( query_profile, sbjct_profile, result)
        
        if result.getLength() == 0:
            query_profile.useFullLength()
            sbjct_profile.useFullLength()
            return 0, result
        
        if self.mLogLevel >= 3:
            print "# --> %i vs %i: score=%5.2f, length=%i, numgaps=%i, row_from=%i, row_to=%i, col_from=%i, col_to=%i" %\
                  (query_nid, sbjct_nid,
                   result.getScore(),
                   result.getLength(),
                   result.getNumGaps(),
                   result.getRowFrom(), result.getRowTo(),
                   result.getColFrom(), result.getColTo())
            sys.stdout.flush()

        if result.getScore() < self.mMinAlignmentScore:
            query_profile.useFullLength()
            sbjct_profile.useFullLength()
            return 0, result

        if result.getScore() > self.mSafetyThreshold * self.mMinAlignmentScore:
            query_profile.useFullLength()
            sbjct_profile.useFullLength()
            return 1,result
        
        z_params = alignlib.makeNormalDistributionParameters()
        alignlib.calculateZScoreParameters( z_params,
                                            query_profile,
                                            sbjct_profile,
                                            alignator,
                                            self.mNumIterationsZScore)
        mean   = z_params.getMean()
        stddev = z_params.getStandardDeviation()
        if stddev == 0: stddev = 1
        
        zscore = (result.getScore() - mean) / stddev
        
        if self.mLogLevel >= 3:
            print "# --> mean=%f, stdev=%f, zscore=%f" % (mean, stddev, zscore)
            sys.stdout.flush()
            
        query_profile.useFullLength()
        sbjct_profile.useFullLength()
        
        if zscore > self.mMinZScore:
            return 1,result
        else:
            return 0,result