<s> '''<STR_LIT>''' <EOL> import sys <EOL> import re <EOL> import CGAT . Experiment as E <EOL> import CGAT . Blat as Blat <EOL> import CGAT . SequenceProperties as SequenceProperties <EOL> import CGAT . SequencePairProperties as SequencePairProperties <EOL> import CGAT . WrapperCodeML as WrapperCodeML <EOL> USAGE = """<STR_LIT>""" <EOL> class Counter : <EOL> def __init__ ( self , options ) : <EOL> pass <EOL> class CounterMatch ( Counter ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> Counter . __init__ ( self , * args , ** kwargs ) <EOL> def __call__ ( self , match ) : <EOL> self . mPid = <NUM_LIT> * match . mNMatches / ( match . mNMatches + match . mNMismatches ) <EOL> self . mQueryCoverage = <NUM_LIT> * ( match . mNMatches + match . mNMismatches ) / match . mQueryLength <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . mPid , self . mQueryCoverage ) <EOL> def getHeaders ( self ) : <EOL> return [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> class QueriesCounter ( SequenceProperties . SequencePropertiesNA ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> SequenceProperties . SequencePropertiesNA . __init__ ( self , * args , ** kwargs ) <EOL> def __call__ ( self , seq1 , seq2 ) : <EOL> SequenceProperties . SequencePropertiesNA . loadSequence ( self , seq1 ) <EOL> class SbjctsCounter ( SequenceProperties . SequencePropertiesNA ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> SequenceProperties . SequencePropertiesNA . __init__ ( self , * args , ** kwargs ) <EOL> def __call__ ( self , seq1 , seq2 ) : <EOL> SequenceProperties . SequencePropertiesNA . loadSequence ( self , seq2 ) <EOL> def main ( argv = None ) : <EOL> """<STR_LIT>""" <EOL> if argv is None : <EOL> argv = sys . argv <EOL> parser = E . OptionParser ( version = "<STR_LIT>" , <EOL> usage = globals ( ) [ "<STR_LIT>" ] ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT>" , action = "<STR_LIT>" , <EOL> choices = ( <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> help = "<STR_LIT>" ) <EOL> WrapperCodeML . BaseML ( ) . AddOptions ( parser ) <EOL> parser . set_defaults ( <EOL> methods = [ ] , <EOL> mask_lowercase = False , <EOL> is_pslx = True , <EOL> with_match = True , <EOL> ) <EOL> ( options , args ) = E . Start ( parser ) <EOL> counters_plain = [ ] <EOL> counters = [ ] <EOL> for method in options . methods : <EOL> if method == "<STR_LIT>" : <EOL> counters . append ( <EOL> SequencePairProperties . SequencePairPropertiesCountsNa ( ) ) <EOL> elif method == "<STR_LIT>" : <EOL> counters . append ( QueriesCounter ( ) ) <EOL> elif method == "<STR_LIT>" : <EOL> counters . append ( SbjctsCounter ( ) ) <EOL> elif method == "<STR_LIT>" : <EOL> counters . append ( <EOL> SequencePairProperties . SequencePairPropertiesBaseML ( options ) ) <EOL> elif method == "<STR_LIT>" : <EOL> counters_plain . append ( CounterMatch ( options ) ) <EOL> if counters : <EOL> iterator = Blat . iterator_pslx ( options . stdin ) <EOL> header = "<STR_LIT:\t>" . join ( Blat . MatchPSLX ( ) . getHeaders ( ) ) <EOL> else : <EOL> iterator = Blat . iterator ( options . stdin ) <EOL> header = "<STR_LIT:\t>" . join ( Blat . Match ( ) . getHeaders ( ) ) <EOL> if not options . with_match : <EOL> header = "<STR_LIT>" <EOL> options . stdout . write ( "<STR_LIT:\t>" . join ( <EOL> [ header , ] + <EOL> [ "<STR_LIT:\t>" . join ( x . getHeaders ( ) ) for x in counters ] + <EOL> [ "<STR_LIT:\t>" . join ( x . getHeaders ( ) ) for x in counters_plain ] ) + "<STR_LIT:\n>" ) <EOL> ninput , noutput , nskipped = <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> <EOL> for match in iterator : <EOL> ninput += <NUM_LIT:1> <EOL> if options . with_match : <EOL> options . stdout . write ( str ( match ) ) <EOL> else : <EOL> options . stdout . write ( match . mQueryId ) <EOL> if counters : <EOL> qseq = match . mQuerySequence <EOL> sseq = match . mSbjctSequence <EOL> qseq = [ re . sub ( "<STR_LIT>" , "<STR_LIT:N>" , x ) for x in qseq ] <EOL> sseq = [ re . sub ( "<STR_LIT>" , "<STR_LIT:N>" , x ) for x in sseq ] <EOL> if options . mask_lowercase : <EOL> qseq = [ re . sub ( "<STR_LIT>" , "<STR_LIT:N>" , x ) for x in qseq ] <EOL> sseq = [ re . sub ( "<STR_LIT>" , "<STR_LIT:N>" , x ) for x in sseq ] <EOL> match . mQuerySequence = qseq <EOL> match . mSbjctSequence = sseq <EOL> qseq = "<STR_LIT>" . join ( match . mQuerySequence ) . upper ( ) <EOL> sseq = "<STR_LIT>" . join ( match . mSbjctSequence ) . upper ( ) <EOL> if len ( qseq ) != len ( sseq ) : <EOL> if options . loglevel >= <NUM_LIT:1> : <EOL> options . stdlog . write ( <EOL> "<STR_LIT>" % str ( match ) ) <EOL> nskipped += <NUM_LIT:1> <EOL> continue <EOL> for counter in counters : <EOL> counter ( qseq , sseq ) <EOL> options . stdout . write ( "<STR_LIT:\t>" + <EOL> "<STR_LIT:\t>" . join ( <EOL> [ str ( counter ) for counter in counters ] ) ) <EOL> if counters_plain : <EOL> for counter in counters_plain : <EOL> counter ( match ) <EOL> options . stdout . write ( "<STR_LIT:\t>" + <EOL> "<STR_LIT:\t>" . join ( <EOL> [ str ( counter ) for counter in counters_plain ] ) ) <EOL> options . stdout . write ( "<STR_LIT:\n>" ) <EOL> noutput += <NUM_LIT:1> <EOL> if options . loglevel >= <NUM_LIT:1> : <EOL> options . stdlog . write ( <EOL> "<STR_LIT>" % ( ninput , noutput , nskipped ) ) <EOL> E . Stop ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> sys . exit ( main ( sys . argv ) ) </s>
