#NEWLINE# def main( argv = sys . argv ) : #NEWLINE# #INDENT# parser = E . OptionParser ( version = '%prog version: $Id$' , usage = globals ( ) [ '__doc__' ] ) #NEWLINE# parser . add_option ( '-n' , '--new-instance' , dest = 'new_instance' , action = 'store_true' , help = 'create a new IGV instance [%default]' ) #NEWLINE# parser . add_option ( '-s' , '--session' , dest = 'session' , type = 'string' , help = 'load session before creating plots [%default]' ) #NEWLINE# parser . add_option ( '-d' , '--snapshot-dir' , dest = 'snapshotdir' , type = 'string' , help = 'directory to save snapshots in [%default]' ) #NEWLINE# parser . add_option ( '-f' , '--format' , dest = 'format' , type = 'choice' , choices = ( 'png' , 'eps' , 'svg' ) , help = 'output file format [%default]' ) #NEWLINE# parser . add_option ( '-o' , '--host' , dest = 'host' , type = 'string' , help = 'host that IGV is running on [%default]' ) #NEWLINE# parser . add_option ( '-p' , '--port' , dest = 'port' , type = 'int' , help = 'port that IGV listens at [%default]' ) #NEWLINE# parser . add_option ( '-e' , '--extend' , dest = 'extend' , type = 'int' , help = 'extend each interval by a number of bases [%default]' ) #NEWLINE# parser . add_option ( '-x' , '--expand' , dest = 'expand' , type = 'float' , help = 'expand each region by a certain factor [%default]' ) #NEWLINE# parser . add_option ( '--session-only' , dest = 'session_only' , action = 'store_true' , help = 'plot session after opening, ignore intervals [%default]' ) #NEWLINE# parser . add_option ( '--keep' , dest = 'keep_open' , action = 'store_true' , help = 'keep a newly created IGV session open [%default]' ) #NEWLINE# parser . set_defaults ( command = 'igv.sh' , host = '127.0.0.1' , port = 61111 , snapshotdir = os . getcwd ( ) , extend = 0 , format = 'png' , expand = 1.0 , session = None , session_only = False , keep_open = False ) #NEWLINE# ( options , args ) = E . Start ( parser , argv = argv , add_output_options = True ) #NEWLINE# igv_process = None #NEWLINE# if options . new_instance : #NEWLINE# #INDENT# E . info ( 'starting new IGV process' ) #NEWLINE# igv_process = IGV . startIGV ( command = options . command , port = options . port ) #NEWLINE# E . info ( 'new IGV process started' ) #NEWLINE# #UNINDENT# E . info ( ( 'connection to process on %s:%s' % ( options . host , options . port ) ) ) #NEWLINE# E . info ( ( 'saving images in %s' % options . snapshotdir ) ) #NEWLINE# igv = IGV . IGV ( host = options . host , port = options . port , snapshot_dir = os . path . abspath ( options . snapshotdir ) ) #NEWLINE# if options . session : #NEWLINE# #INDENT# E . info ( ( 'loading session from %s' % options . session ) ) #NEWLINE# igv . load ( options . session ) #NEWLINE# E . info ( 'loaded session' ) #NEWLINE# #UNINDENT# if options . session_only : #NEWLINE# #INDENT# E . info ( 'plotting session only ignoring any intervals' ) #NEWLINE# fn = ( '%s.%s' % ( os . path . basename ( options . session ) , options . format ) ) #NEWLINE# E . info ( ( "writing snapshot to '%s'" % os . path . join ( options . snapshotdir , fn ) ) ) #NEWLINE# igv . save ( fn ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# c = E . Counter ( ) #NEWLINE# for bed in Bed . iterator ( options . stdin ) : #NEWLINE# #INDENT# c . input += 1 #NEWLINE# name = re . sub ( '\\s' , '_' , bed . name ) #NEWLINE# E . info ( ( 'going to %s:%i-%i for %s' % ( bed . contig , bed . start , bed . end , name ) ) ) #NEWLINE# ( start , end ) = ( bed . start , bed . end ) #NEWLINE# extend = options . extend #NEWLINE# if options . expand : #NEWLINE# #INDENT# d = ( end - start ) #NEWLINE# extend = max ( extend , ( ( ( options . expand * d ) - d ) // 2 ) ) #NEWLINE# #UNINDENT# start -= extend #NEWLINE# end += extend #NEWLINE# igv . go ( ( '%s:%i-%i' % ( bed . contig , start , end ) ) ) #NEWLINE# fn = E . getOutputFile ( ( '%s.%s' % ( name , options . format ) ) ) #NEWLINE# E . info ( ( "writing snapshot to '%s'" % fn ) ) #NEWLINE# igv . save ( fn ) #NEWLINE# c . snapshots += 1 #NEWLINE# #UNINDENT# E . info ( c ) #NEWLINE# #UNINDENT# if ( ( igv_process is not None ) and ( not options . keep_open ) ) : #NEWLINE# #INDENT# E . info ( 'shutting down IGV' ) #NEWLINE# igv_process . send_signal ( signal . SIGKILL ) #NEWLINE# #UNINDENT# E . Stop ( )