<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import re <EOL> from optparse import OptionParser <EOL> MIN_DIST = <NUM_LIT:50> <EOL> MAX_DIST = <NUM_LIT> <EOL> class Pos : <EOL> def __init__ ( self , chr , s ) : <EOL> self . chr = chr <EOL> self . start = s <EOL> class Pair : <EOL> def __init__ ( self , n ) : <EOL> self . n = n <EOL> self . left = [ ] <EOL> self . right = [ ] <EOL> def addleft ( self , pos ) : <EOL> self . left . append ( pos ) <EOL> def addright ( self , pos ) : <EOL> self . right . append ( pos ) <EOL> def pair ( self ) : <EOL> n = <NUM_LIT:0> <EOL> for rp in self . right : <EOL> for lp in self . left : <EOL> if lp . chr == rp . chr : <EOL> dist = rp . start - lp . start <EOL> if dist < MAX_DIST and dist > MIN_DIST : <EOL> n += <NUM_LIT:1> <EOL> return n <EOL> def main ( ) : <EOL> usage = "<STR_LIT>" <EOL> description = "<STR_LIT>" <EOL> optparser = OptionParser ( version = "<STR_LIT>" , description = description , usage = usage , add_help_option = False ) <EOL> optparser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> optparser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:string>" , <EOL> help = "<STR_LIT>" ) <EOL> optparser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:string>" , <EOL> help = "<STR_LIT>" ) <EOL> optparser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> ( options , args ) = optparser . parse_args ( ) <EOL> if not options . ifile or not optiions . ofile : <EOL> optparser . print_help ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> ifhd = open ( options . ifile , "<STR_LIT:r>" ) <EOL> ofhd = open ( options . ofile , "<STR_LIT:w>" ) <EOL> col_tagno = <NUM_LIT:4> <EOL> col_chr = <NUM_LIT:2> <EOL> col_start = <NUM_LIT:3> <EOL> pairs = { } <EOL> for l in ifhd . readlines ( ) : <EOL> if l . startswith ( "<STR_LIT:#>" ) : continue <EOL> fields = l . split ( "<STR_LIT:\t>" ) <EOL> chr = fields [ col_chr ] <EOL> start = int ( fields [ col_start ] ) <EOL> tagno = int ( fields [ col_tagno ] ) <EOL> right = False <EOL> if tagno % <NUM_LIT:2> == <NUM_LIT:0> : <EOL> tagno -= <NUM_LIT:1> <EOL> right = True <EOL> if not pairs . has_key ( tagno ) : <EOL> pairs [ tagno ] = Pair ( tagno ) <EOL> if chr == "<STR_LIT>" : <EOL> continue <EOL> if right : <EOL> pairs [ tagno ] . addright ( Pos ( chr , start ) ) <EOL> else : <EOL> pairs [ tagno ] . addleft ( Pos ( chr , start ) ) <EOL> ns = pairs . keys ( ) <EOL> ns . sort ( ) <EOL> total_unique_pairs = <NUM_LIT:0> <EOL> total_pairs = len ( ns ) <EOL> for n in ns : <EOL> p = pairs [ n ] . pair ( ) <EOL> ofhd . write ( "<STR_LIT>" % ( n , p ) ) <EOL> if p == <NUM_LIT:1> : <EOL> total_unique_pairs += <NUM_LIT:1> <EOL> ofhd . write ( "<STR_LIT>" % ( total_pairs , total_unique_pairs , float ( total_unique_pairs ) / total_pairs * <NUM_LIT:100> ) ) <EOL> ofhd . close ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> try : <EOL> main ( ) <EOL> except KeyboardInterrupt : <EOL> msgl ( _ ( "<STR_LIT>" ) ) <EOL> sys . exit ( <NUM_LIT:0> ) </s>
