#NEWLINE# def write_localdups( tandems , bed , dups_fh = None ) : #NEWLINE# #INDENT# tandem_groups = [ ] #NEWLINE# for group in tandems : #NEWLINE# #INDENT# rows = [ bed [ i ] for i in group ] #NEWLINE# rows . sort ( key = ( lambda a : ( ( - abs ( ( a . end - a . start ) ) ) , a . accn ) ) ) #NEWLINE# tandem_groups . append ( [ x . accn for x in rows ] ) #NEWLINE# #UNINDENT# dups_to_mother = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# n = 1 #NEWLINE# for accns in sorted ( tandem_groups ) : #NEWLINE# #INDENT# if dups_fh : #NEWLINE# #INDENT# ( ( print >> dups_fh ) , '\t' . join ( accns ) ) #NEWLINE# if n : #NEWLINE# #INDENT# n -= 1 #NEWLINE# logging . debug ( ( 'write local dups to file %s' % dups_fh . name ) ) #NEWLINE# #UNINDENT# #UNINDENT# for dup in accns [ 1 : ] : #NEWLINE# #INDENT# dups_to_mother [ dup ] = dups_to_mother [ 0 ] #NEWLINE# #UNINDENT# #UNINDENT# return dups_to_mother