<s> """<STR_LIT>""" <EOL> import sys <EOL> import re <EOL> from bisect import insort , bisect_left , bisect_right <EOL> from array import array <EOL> if array ( '<STR_LIT:H>' , [ <NUM_LIT:1> ] ) . itemsize == <NUM_LIT:2> : <EOL> BYTE2 = '<STR_LIT:H>' <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if array ( '<STR_LIT:I>' , [ <NUM_LIT:1> ] ) . itemsize == <NUM_LIT:4> : <EOL> BYTE4 = '<STR_LIT:I>' <EOL> elif array ( '<STR_LIT:L>' , [ <NUM_LIT:1> ] ) . itemsize == <NUM_LIT:4> : <EOL> BYTE4 = '<STR_LIT:L>' <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if array ( '<STR_LIT:f>' , [ <NUM_LIT:1> ] ) . itemsize == <NUM_LIT:4> : <EOL> FBYTE4 = '<STR_LIT:f>' <EOL> elif array ( '<STR_LIT:d>' , [ <NUM_LIT:1> ] ) . itemsize == <NUM_LIT:4> : <EOL> FBYTE4 = '<STR_LIT:d>' <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> class BinKeeperI : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , binsize = <NUM_LIT> , chromosomesize = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> self . binsize = binsize <EOL> self . binnumber = int ( chromosomesize / self . binsize ) + <NUM_LIT:1> <EOL> self . cage = [ ] <EOL> a = self . cage . append <EOL> for i in xrange ( self . binnumber ) : <EOL> a ( [ array ( BYTE4 , [ ] ) , array ( FBYTE4 , [ ] ) ] ) <EOL> def add ( self , p , value ) : <EOL> """<STR_LIT>""" <EOL> bin = p / self . binsize <EOL> self . cage [ bin ] [ <NUM_LIT:0> ] . append ( p ) <EOL> self . cage [ bin ] [ <NUM_LIT:1> ] . append ( value ) <EOL> def p2bin ( self , p ) : <EOL> """<STR_LIT>""" <EOL> return p / self . binsize <EOL> def p2cage ( self , p ) : <EOL> """<STR_LIT>""" <EOL> return self . cage [ p / self . binsize ] <EOL> def __pp2cages ( self , p1 , p2 ) : <EOL> assert p1 <= p2 <EOL> bin1 = self . p2bin ( p1 ) <EOL> bin2 = self . p2bin ( p2 ) + <NUM_LIT:1> <EOL> t = [ array ( BYTE4 , [ ] ) , array ( FBYTE4 , [ ] ) ] <EOL> for i in xrange ( bin1 , bin2 ) : <EOL> t [ <NUM_LIT:0> ] . extend ( self . cage [ i ] [ <NUM_LIT:0> ] ) <EOL> t [ <NUM_LIT:1> ] . extend ( self . cage [ i ] [ <NUM_LIT:1> ] ) <EOL> return t <EOL> def pp2p ( self , p1 , p2 ) : <EOL> """<STR_LIT>""" <EOL> ( ps , vs ) = self . __pp2cages ( p1 , p2 ) <EOL> p1_in_cages = bisect_left ( ps , p1 ) <EOL> p2_in_cages = bisect_right ( ps , p2 ) <EOL> return ps [ p1_in_cages : p2_in_cages ] <EOL> def pp2v ( self , p1 , p2 ) : <EOL> """<STR_LIT>""" <EOL> ( ps , vs ) = self . __pp2cages ( p1 , p2 ) <EOL> p1_in_cages = bisect_left ( ps , p1 ) <EOL> p2_in_cages = bisect_right ( ps , p2 ) <EOL> return vs [ p1_in_cages : p2_in_cages ] <EOL> def pp2pv ( self , p1 , p2 ) : <EOL> """<STR_LIT>""" <EOL> ( ps , vs ) = self . __pp2cages ( p1 , p2 ) <EOL> p1_in_cages = bisect_left ( ps , p1 ) <EOL> p2_in_cages = bisect_right ( ps , p2 ) <EOL> return zip ( ps [ p1_in_cages : p2_in_cages ] , vs [ p1_in_cages : p2_in_cages ] ) </s>
