""" A very, very basic genome browser. usage : ./basic_browser.py forward.track \ reverse.track \ peak.bookmark \ genes.bed """ import numpy import pique import pylab import sys # read track data pique.msg( 'reading track data...' ) data_ff = pique.readtrack( sys.argv[1] ) data_rr = pique.readtrack( sys.argv[2] ) # read peak data pique.msg( 'reading peak bookmarks...' ) peaks = pique.readbookmarks( sys.argv[3] ) # draw peaks pique.msg( 'drawing peak bookmarks...' ) for peak in peaks : axvspan( peak['start'], peak['stop'], color='green', alpha=0.3 ) # read BED formatted gene annotations pique.msg( 'reading gene annotations...' ) genes = {} for line in open( sys.argv[4] ) :
'peak_bookmarks', \ 'weed_bookmarks', \ 'overlap_track', \ 'binding_track' ] opt_dict = yaml.load( open( sys.argv[1] ).read() ) for opt in num_opts + str_opts : if not opt_dict.has_key( opt ) : print 'config file missing option : ' + opt quit() setattr( sys.modules[__name__], opt, opt_dict[opt] ) # read the track data pique.msg( 'reading track data...' ) data_ff = pique.readtrack( forward_ChIP_track ) data_rr = pique.readtrack( reverse_ChIP_track ) b_ff = pique.readtrack( forward_bgnd_track ) b_rr = pique.readtrack( reverse_bgnd_track ) # apply mask pique.msg( 'applying mask...' ) is_elements = [] for line in open( masking_loci ) : if line.__contains__('#') : continue start, stop = map( int, line.split()[:2] ) is_elements.append( { 'start':start, 'stop':stop } ) data_ff = pique.mask( data_ff, is_elements ) data_rr = pique.mask( data_rr, is_elements )
'reverse_ChIP_track', \ 'reverse_bgnd_track', \ 'masking_loci', \ 'annotated_bookmarks' ] opt_dict = yaml.load(open(sys.argv[1]).read()) for opt in str_opts: if not opt_dict.has_key(opt): print 'config file missing option : ' + opt quit() setattr(sys.modules[__name__], opt, opt_dict[opt]) # read track data pique.msg('reading track data...') data_ff = pique.readtrack(forward_ChIP_track) data_rr = pique.readtrack(reverse_ChIP_track) b_ff = pique.readtrack(forward_bgnd_track) b_rr = pique.readtrack(reverse_bgnd_track) # read bookmarks file peaks = pique.readbookmarks(peak_bookmarks) # calculate enrichment ratios for n, peak in enumerate(peaks): a = sum(data_ff[peak['start']:peak['stop']]) a = a + sum(data_rr[peak['start']:peak['stop']]) b = sum(b_ff[peak['start']:peak['stop']]) b = b + sum(b_rr[peak['start']:peak['stop']]) peaks[n]['annotations']['enrichment_ratio'] = float(a) / float(b)
""" A very, very basic genome browser. usage : ./basic_browser.py forward.track \ reverse.track \ peak.bookmark \ genes.bed """ import numpy import pique import pylab import sys # read track data pique.msg('reading track data...') data_ff = pique.readtrack(sys.argv[1]) data_rr = pique.readtrack(sys.argv[2]) # read peak data pique.msg('reading peak bookmarks...') peaks = pique.readbookmarks(sys.argv[3]) # draw peaks pique.msg('drawing peak bookmarks...') for peak in peaks: axvspan(peak['start'], peak['stop'], color='green', alpha=0.3) # read BED formatted gene annotations pique.msg('reading gene annotations...') genes = {} for line in open(sys.argv[4]):