<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import re <EOL> from optparse import OptionParser <EOL> from glob import glob <EOL> import Cistrome <EOL> from Cistrome . TabIO import TabFile <EOL> GENOME_SIZE = { "<STR_LIT>" : <NUM_LIT> L , <EOL> "<STR_LIT>" : <NUM_LIT> L } <EOL> def log ( msg ) : <EOL> sys . stderr . write ( msg ) <EOL> def fact ( n ) : <EOL> return reduce ( lambda a , b : a * ( b + <NUM_LIT:1> ) , range ( n ) , <NUM_LIT:1> ) <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>" , type = "<STR_LIT:int>" , <EOL> default = <NUM_LIT:1000> , help = "<STR_LIT>" ) <EOL> optparser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:int>" , <EOL> default = <NUM_LIT:0> , help = "<STR_LIT>" ) <EOL> optparser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> ( options , args ) = optparser . parse_args ( ) <EOL> if not options . ifile or not options . ofile : <EOL> optparser . print_help ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> ofhd = open ( options . ofile , "<STR_LIT:w>" ) <EOL> if options . species == "<STR_LIT>" : <EOL> chromosomes_len = { <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> <EOL> } <EOL> genome_len = <NUM_LIT> L <EOL> elif options . species == "<STR_LIT>" : <EOL> chromosomes_len = { <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> <EOL> } <EOL> genome_len = <NUM_LIT> L <EOL> else : <EOL> log ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> log ( "<STR_LIT>" % ( options . ifile ) ) <EOL> f = TabFile ( options . ifile ) <EOL> track = f . build_fwtrack ( ) <EOL> track_chrs = track . get_chr_names ( ) <EOL> log ( "<STR_LIT>" ) <EOL> total_num = <NUM_LIT:0> <EOL> range_num = <NUM_LIT:0> <EOL> for k in chromosomes_len . keys ( ) : <EOL> log ( "<STR_LIT>" % ( k ) ) <EOL> if not track_chrs . count ( k ) : <EOL> log ( "<STR_LIT>" ) <EOL> continue <EOL> else : <EOL> log ( "<STR_LIT>" ) <EOL> chr_end = chromosomes_len [ k ] <EOL> cs = <NUM_LIT:0> <EOL> ce = cs + options . window <EOL> track_k = track . generate_rangeI_by_chr ( k ) <EOL> track_k_range = track_k . next ( ) <EOL> while ce <= chr_end : <EOL> range_num += <NUM_LIT:1> <EOL> num = <NUM_LIT:0> <EOL> while True : <EOL> try : <EOL> if ce < track_k_range . end : <EOL> ofhd . write ( "<STR_LIT>" % ( num ) ) <EOL> cs = options . gap + ce <EOL> ce = cs + options . window <EOL> break <EOL> else : <EOL> if cs < track_k_range . start : <EOL> num += <NUM_LIT:1> <EOL> total_num += <NUM_LIT:1> <EOL> track_k_range = track_k . next ( ) <EOL> except StopIteration : <EOL> ofhd . write ( "<STR_LIT>" % ( num ) ) <EOL> cs = options . gap + ce <EOL> ce = cs + options . window <EOL> break <EOL> ofhd . close ( ) <EOL> sys . stdout . write ( "<STR_LIT>" % ( total_num , range_num , float ( total_num ) / range_num ) ) <EOL> log ( "<STR_LIT>" ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> try : <EOL> main ( ) <EOL> except KeyboardInterrupt : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:0> ) </s>
