#NEWLINE# def makeIntervalCorrelation( infiles , outfile , field ) : #NEWLINE# #INDENT# 'compute correlation of interval properties between sets\n    ' #NEWLINE# dbhandle = sqlite3 . connect ( PARAMS [ 'database' ] ) #NEWLINE# ( tracks , idx ) = ( [ ] , [ ] ) #NEWLINE# for infile in infiles : #NEWLINE# #INDENT# track = infile [ : ( - len ( '.bed' ) ) ] #NEWLINE# cc = dbhandle . cursor ( ) #NEWLINE# statement = ( 'SELECT contig, start, end, %(field)s FROM %(track)s_intervals' % locals ( ) ) #NEWLINE# cc . execute ( statement ) #NEWLINE# ix = IndexedGenome . IndexedGenome ( ) #NEWLINE# for ( contig , start , end , peakval ) in cc : #NEWLINE# #INDENT# ix . add ( contig , start , end , peakval ) #NEWLINE# #UNINDENT# idx . append ( ix ) #NEWLINE# tracks . append ( track ) #NEWLINE# #UNINDENT# outs = open ( outfile , 'w' ) #NEWLINE# outs . write ( ( ( 'id\tcontig\tstart\tend\t' + '\t' . join ( tracks ) ) + '\n' ) ) #NEWLINE# for bed in Bed . iterator ( infile = open ( 'merged.bed' , 'r' ) ) : #NEWLINE# #INDENT# row = [ ] #NEWLINE# for ix in idx : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# intervals = list ( ix . get ( bed . contig , bed . start , bed . end ) ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# row . append ( '' ) #NEWLINE# continue #NEWLINE# #UNINDENT# if ( len ( intervals ) == 0 ) : #NEWLINE# #INDENT# peakval = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# peakval = str ( max ( [ x [ 2 ] for x in intervals ] ) ) #NEWLINE# #UNINDENT# row . append ( peakval ) #NEWLINE# #UNINDENT# outs . write ( ( ( ( str ( bed ) + '\t' ) + '\t' . join ( bed ) ) + '\n' ) ) #NEWLINE# #UNINDENT# outs . close ( )