<s> '''<STR_LIT>''' <EOL> import sys <EOL> import re <EOL> import string <EOL> import optparse <EOL> import time <EOL> import os <EOL> import glob <EOL> import CGAT . Experiment as E <EOL> import CGAT . Stats as Stats <EOL> import CGAT . GTF as GTF <EOL> import CGAT . Wiggle as Wiggle <EOL> import alignlib <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> parser = E . OptionParser ( version = "<STR_LIT>" , usage = globals ( ) [ "<STR_LIT>" ] ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:string>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:string>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:string>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT:test>" , type = "<STR_LIT:int>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . set_defaults ( wiggle_files = "<STR_LIT>" , <EOL> prefix = "<STR_LIT>" , <EOL> with_values = False , <EOL> test = None ) <EOL> ( options , args ) = E . Start ( parser , add_pipe_options = True ) <EOL> wiggle_files = glob . glob ( options . wiggle_files ) <EOL> if not wiggle_files : <EOL> raise IOError ( "<STR_LIT>" % options . wiggle_files ) <EOL> index = Wiggle . WiggleMultiIndexedAccess ( wiggle_files , <EOL> keep_open = True , <EOL> use_cache = False ) <EOL> if options . as_gtf : <EOL> iterator = GTF . flat_gene_iterator ( GTF . iterator ( sys . stdin ) ) <EOL> id = "<STR_LIT>" <EOL> else : <EOL> iterator = GTF . chunk_iterator ( GTF . iterator ( sys . stdin ) ) <EOL> id = "<STR_LIT>" <EOL> ninput , noutput , nskipped = <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> <EOL> options . stdout . write ( "<STR_LIT>" % ( id , "<STR_LIT:\t>" . join ( Stats . DistributionalParameters ( ) . getHeaders ( ) ) ) ) <EOL> if options . with_values : <EOL> options . stdout . write ( "<STR_LIT>" ) <EOL> options . stdout . write ( "<STR_LIT:\n>" ) <EOL> for gffs in iterator : <EOL> if options . test and ninput >= options . test : <EOL> break <EOL> ninput += <NUM_LIT:1> <EOL> if options . loglevel >= <NUM_LIT:2> : <EOL> for gff in gffs : <EOL> options . stdlog . write ( str ( gff ) + "<STR_LIT:\n>" ) <EOL> map_genome2query = alignlib . makeAlignmentBlocks ( ) <EOL> for gff in gffs : <EOL> map_genome2query . addDiagonal ( gff . start , gff . end , <NUM_LIT:0> ) <EOL> data = index . get ( options . prefix + gff . contig , <EOL> map_genome2query . getRowFrom ( ) , <EOL> map_genome2query . getRowTo ( ) ) <EOL> values = [ ] <EOL> for x , vv in data : <EOL> for v in vv : <EOL> if map_genome2query . mapRowToCol ( x ) >= <NUM_LIT:0> : <EOL> values . append ( v ) <EOL> x += <NUM_LIT:1> <EOL> if len ( values ) == <NUM_LIT:0> : <EOL> nskipped += <NUM_LIT:1> <EOL> continue <EOL> noutput += <NUM_LIT:1> <EOL> if options . loglevel >= <NUM_LIT:2> : <EOL> options . stdlog . write ( "<STR_LIT>" % "<STR_LIT:U+002C>" . join ( [ "<STR_LIT>" % v for v in values ] ) ) <EOL> s = Stats . DistributionalParameters ( values ) <EOL> if options . as_gtf : <EOL> id = gff . gene_id <EOL> else : <EOL> id = gff . mAttributes <EOL> options . stdout . write ( "<STR_LIT>" % ( id , <EOL> map_genome2query . getNumAligned ( ) , <EOL> str ( s ) ) ) <EOL> if options . with_values : <EOL> options . stdout . write ( "<STR_LIT>" % "<STR_LIT:U+002C>" . join ( [ "<STR_LIT>" % v for v in values ] ) ) <EOL> options . stdout . write ( "<STR_LIT:\n>" ) <EOL> if options . loglevel >= <NUM_LIT:1> : <EOL> options . stdlog . write ( "<STR_LIT>" % ( ninput , noutput , nskipped ) ) <EOL> E . Stop ( ) </s>
