<s> '''<STR_LIT>''' <EOL> import sys <EOL> import re <EOL> import string <EOL> import os <EOL> import time <EOL> from Pairsdb import * <EOL> import alignlib <EOL> import pairsdblib <EOL> from MessagePairsdb import MessagePairsdb <EOL> from TableDomainsScopTest import TableDomainsScopTest <EOL> from TablePairsdbNeighbours import TablePairsdbNeighbours <EOL> from Pairsdb import * <EOL> import Tools <EOL> class ScopTester : <EOL> def __init__ ( self , dbhandle , alignator , table_scop_test ) : <EOL> self . mLogLevel = <NUM_LIT:1> <EOL> self . dbhandle = dbhandle <EOL> self . mDatabaseNamePairsdb = dbhandle . GetDatabase ( ) <EOL> self . mConnectionPairsdb = pairsdblib . Connection ( dbhandle . GetHost ( ) , <EOL> dbhandle . GetUser ( ) , <EOL> dbhandle . GetPassword ( ) , <EOL> dbhandle . GetPort ( ) ) <EOL> self . mConnectionPairsdb . Connect ( self . mDatabaseNamePairsdb ) <EOL> self . mTableScopTest = table_scop_test <EOL> self . mAlignanda = [ ] <EOL> self . mInformation = [ ] <EOL> self . mAlignator = alignator <EOL> self . startAt = <NUM_LIT:0> <EOL> def CalculateMatches ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . mAlignanda : <EOL> self . GetAlignanda ( ) <EOL> if self . mLogLevel >= <NUM_LIT:1> : <EOL> print "<STR_LIT>" % len ( self . mAlignanda ) <EOL> print "<STR_LIT>" , Tools . GetTimeStamp ( ) <EOL> nalignanda = len ( self . mAlignanda ) <EOL> for a1 in range ( self . startAt , nalignanda - <NUM_LIT:1> ) : <EOL> if self . mLogLevel >= <NUM_LIT:1> : <EOL> print "<STR_LIT>" % ( a1 , nalignanda , Tools . GetTimeStamp ( ) ) <EOL> sys . stdout . flush ( ) <EOL> for a2 in range ( a1 + <NUM_LIT:1> , nalignanda ) : <EOL> if self . mLogLevel >= <NUM_LIT:3> : <EOL> print "<STR_LIT>" % ( a2 ) , self . mInformation [ a2 ] <EOL> sys . stdout . flush ( ) <EOL> result = alignlib . makeAlignataVector ( ) <EOL> self . mAlignator . Align ( self . mAlignanda [ a1 ] , self . mAlignanda [ a2 ] , result ) <EOL> info = self . mAlignator . CheckResult ( result , self . mInformation [ a1 ] , self . mInformation [ a2 ] ) <EOL> if info : <EOL> r = tuple ( self . mInformation [ a1 ] ) + tuple ( self . mInformation [ a2 ] ) + tuple ( info ) <EOL> print string . join ( r , "<STR_LIT:\t>" ) <EOL> sys . stdout . flush ( ) <EOL> self . mAlignanda [ a1 ] . Release ( ) <EOL> self . mAlignanda [ a1 ] = None <EOL> if self . mLogLevel >= <NUM_LIT:1> : <EOL> print "<STR_LIT>" , Tools . GetTimeStamp ( ) <EOL> def SetAlignator ( self , alignator ) : <EOL> self . mAlignator = alignator <EOL> def GetAlignanda ( self ) : <EOL> """<STR_LIT>""" <EOL> domains = self . mTableScopTest . GetAllDomains ( all = <NUM_LIT:0> ) <EOL> if self . mLogLevel >= <NUM_LIT:1> : <EOL> print "<STR_LIT>" % ( len ( domains ) , Tools . GetTimeStamp ( ) ) <EOL> sys . stdout . flush ( ) <EOL> for domain in domains : <EOL> if self . mLogLevel >= <NUM_LIT:2> : <EOL> print "<STR_LIT>" , domain <EOL> sys . stdout . flush ( ) <EOL> ( nid , nrdb_from , nrdb_to , scop_class ) = domain <EOL> pdb_id = "<STR_LIT:test>" <EOL> region_nr = <NUM_LIT:0> <EOL> if scop_class [ <NUM_LIT:0> : <NUM_LIT:3> ] not in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> if self . mLogLevel >= <NUM_LIT:2> : <EOL> print "<STR_LIT>" <EOL> sys . stdout . flush ( ) <EOL> continue <EOL> alignandum , info = self . GetAlignandum ( nid , nrdb_from , nrdb_to ) <EOL> if alignandum : <EOL> if info : <EOL> self . mInformation . append ( ( "<STR_LIT>" % ( nid , nrdb_from , nrdb_to ) , <EOL> scop_class , pdb_id , str ( region_nr ) ) + tuple ( info ) ) <EOL> else : <EOL> self . mInformation . append ( ( "<STR_LIT>" % ( nid , nrdb_from , nrdb_to ) , <EOL> scop_class , pdb_id , str ( region_nr ) ) ) <EOL> self . mAlignanda . append ( alignandum ) <EOL> else : <EOL> if self . mLogLevel >= <NUM_LIT:2> : <EOL> print "<STR_LIT>" <EOL> sys . stdout . flush ( ) <EOL> if self . mLogLevel >= <NUM_LIT:1> : <EOL> print "<STR_LIT>" % ( len ( self . mAlignanda ) , Tools . GetTimeStamp ( ) ) <EOL> sys . stdout . flush ( ) <EOL> class ScopTesterSequences ( ScopTester ) : <EOL> def GetAlignandum ( self , nid , nrdb_from , nrdb_to ) : <EOL> alignandum = pairsdblib . makeSequenceFromPairsdb ( self . mConnectionPairsdb , nid ) <EOL> alignandum . useSegment ( nrdb_from , nrdb_to ) <EOL> return alignandum , None <EOL> class ScopTesterProfiles ( ScopTester ) : <EOL> def __init__ ( self , <EOL> dbhandle , <EOL> alignator , <EOL> table_scop_test , <EOL> min_profile_size = <NUM_LIT:20> , <EOL> min_level = <NUM_LIT:30> , <EOL> max_level = <NUM_LIT> , <EOL> neighbours = "<STR_LIT>" ) : <EOL> self . mMinProfileSize = min_profile_size <EOL> self . mMinLevel = min_level <EOL> self . mMaxLevel = max_level <EOL> self . mTableNameNeighbours = neighbours <EOL> ScopTester . __init__ ( self , dbhandle , alignator , table_scop_test ) <EOL> self . mTableNeighbours = TablePairsdbNeighbours ( self . dbhandle ) <EOL> self . mTableNeighbours . SetName ( self . mTableNameNeighbours ) <EOL> self . mBlastL = <NUM_LIT> <EOL> self . mLogOddorScaleFactor = self . mBlastL <EOL> self . mLogOddor = alignlib . makeLogOddorDirichlet ( self . mLogOddorScaleFactor ) <EOL> self . mMaxLinesMali = <NUM_LIT:1000> <EOL> self . mRegularizor = alignlib . makeRegularizorDirichletPrecomputed ( ) <EOL> def GetAlignandum ( self , nid , nrdb_from , nrdb_to ) : <EOL> n = self . mTableNeighbours . GetNumNeighbours ( nid ) <EOL> if n >= self . mMinProfileSize : <EOL> profile = alignlib . makeEmptyProfile ( self . mRegularizor , self . mLogOddor ) <EOL> pairsdblib . fillProfileNeighbours ( profile , <EOL> self . mConnectionPairsdb , <EOL> nid , <EOL> self . mTableNameNeighbours , <EOL> self . mMaxLinesMali , <EOL> <NUM_LIT:0> , <EOL> self . mMaxLevel , <EOL> self . mMinLevel ) <EOL> if self . mLogLevel >= <NUM_LIT:3> : <EOL> print "<STR_LIT>" % nid <EOL> else : <EOL> profile = pairsdblib . makeSequenceFromPicasso ( self . mConnectionPairsdb , nid ) <EOL> if self . mLogLevel >= <NUM_LIT:3> : <EOL> print "<STR_LIT>" % nid <EOL> profile . useSegment ( nrdb_from , nrdb_to ) <EOL> return profile , ( str ( n ) , ) <EOL> class ScopTesterFullProfiles ( ScopTesterProfiles ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> dbhandle , <EOL> alignator , <EOL> table_scop_test , <EOL> min_profile_size = <NUM_LIT:20> , <EOL> min_level = <NUM_LIT:30> , <EOL> max_level = <NUM_LIT> , <EOL> neighbours = "<STR_LIT>" ) : <EOL> ScopTesterProfiles . __init__ ( self , dbhandle , alignator , table_scop_test , <EOL> min_profile_size , min_level , max_level , neighbours ) <EOL> self . mAddLength = <NUM_LIT> <EOL> self . mMaxLength = <NUM_LIT> <EOL> def GetAlignandum ( self , nid , nrdb_from , nrdb_to ) : <EOL> profile , x = ScopTesterProfiles . GetAlignandum ( self , nid , nrdb_from , nrdb_to ) <EOL> profile . useFullLength ( ) <EOL> xfrom = max ( <NUM_LIT:1> , nrdb_from - self . mAddLength ) <EOL> xto = min ( profile . getLength ( ) , nrdb_to + self . mAddLength ) <EOL> if self . mLogLevel >= <NUM_LIT:3> : <EOL> print "<STR_LIT>" % ( xfrom , xto ) <EOL> sys . stdout . flush ( ) <EOL> profile . useSegment ( xfrom , xto ) <EOL> return profile , x <EOL> class Alignator : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , alignator ) : <EOL> self . mAlignator = alignator <EOL> def Align ( self , a1 , a2 , result ) : <EOL> self . mAlignator . Align ( a1 , a2 , result ) <EOL> def CheckResult ( self , <EOL> result , <EOL> info1 = None , <EOL> info2 = None ) : <EOL> """<STR_LIT>""" <EOL> if ( result . getLength ( ) > <NUM_LIT:0> ) : <EOL> row_ali , col_ali = alignlib . writeAlignataCompressed ( result ) <EOL> return map ( str , ( result . getScore ( ) , <EOL> result . getLength ( ) , <EOL> result . getNumGaps ( ) , <EOL> alignlib . calculatePercentSimilarity ( result ) , <EOL> result . getRowFrom ( ) , result . getRowTo ( ) , row_ali , <EOL> result . getColFrom ( ) , result . getColTo ( ) , col_ali ) ) <EOL> else : <EOL> return ( "<STR_LIT:0>" , ) * <NUM_LIT:12> <EOL> class AlignatorIterative ( Alignator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , alignator , min_score , min_overlap , gop , gep ) : <EOL> self . mAlignator = alignator <EOL> self . mMinScore = float ( min_score ) <EOL> self . mMinOverlap = min_overlap <EOL> self . mGop = gop <EOL> self . mGep = gep <EOL> def Align ( self , a1 , a2 , result ) : <EOL> """<STR_LIT>""" <EOL> fragmentor = alignlib . makeFragmentorRepetitive ( self . mAlignator , self . mMinScore ) <EOL> val = fragmentor . Fragment ( a1 , a2 , result ) <EOL> self . mFragments = map ( lambda x : alignlib . AlignataPtr ( x ) , val ) <EOL> for fragment in self . mFragments : <EOL> fragment . thisown = <NUM_LIT:1> <EOL> def CheckResult ( self , <EOL> result , <EOL> info1 , info2 ) : <EOL> """<STR_LIT>""" <EOL> row_from , row_to = map ( string . atoi , info1 [ <NUM_LIT:1> : <NUM_LIT:3> ] ) <EOL> col_from , col_to = map ( string . atoi , info2 [ <NUM_LIT:1> : <NUM_LIT:3> ] ) <EOL> for fragment in self . mFragments : <EOL> xcol_from = Tools . MapRight ( fragment , row_from ) <EOL> xcol_to = Tools . MapLeft ( fragment , row_to ) <EOL> overlap = min ( col_to , xcol_to ) - max ( col_from , xcol_from ) <EOL> if overlap > self . mMinOverlap : <EOL> return map ( str , ( fragment . getScore ( ) , <EOL> fragment . getLength ( ) , <EOL> fragment . getNumGaps ( ) , <EOL> alignlib . calculatePercentSimilarity ( fragment ) , <EOL> fragment . getRowFrom ( ) , fragment . getRowTo ( ) , <EOL> fragment . getColFrom ( ) , fragment . getColTo ( ) , <EOL> overlap , xcol_from , xcol_to , <EOL> ( xcol_to - xcol_from ) - ( col_to - col_from ) ) ) <EOL> return ( "<STR_LIT:0>" , ) * <NUM_LIT:12> <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> dbhandle = Pairsdb ( ) <EOL> if not dbhandle . Connect ( ) : <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> a = alignlib . makeFullDP ( - <NUM_LIT> , - <NUM_LIT> ) <EOL> alignator = Alignator ( a ) <EOL> x = ScopTesterSequences ( dbhandle , alignator ) <EOL> x . Process ( ) <EOL> if param_alignator == <NUM_LIT:0> : <EOL> a = alignlib . makeFullDP ( param_gop , param_gep ) <EOL> alignator = Alignator ( a ) <EOL> if param_entities == <NUM_LIT:0> : <EOL> tester = ScopTesterSequences ( dbhandle , alignator ) <EOL> tester . mLogLevel = param_loglevel <EOL> matches = a . CalculateMatches ( ) </s>
