def test_take(self): """take returns subset with correct attributes""" input = dict(counts=[[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]], info={'abcd': 'efg'}, labels=['0', '1', '2', '3', '4']) coll = RegionCollection(**input) sub = coll.take([0, 1, 2]) self.assertEqual(sub.info, input['info']) self.assertEqual(sub.counts.tolist(), [[0, 1], [2, 3], [4, 5]]) self.assertEqual(sub.labels.tolist(), ['0', '1', '2'])
def main(): option_parser, opts, args =\ parse_command_line_parameters(**script_info) if ',' not in opts.ylim: raise RuntimeError('ylim must be comma separated') ylim = map(float, opts.ylim.strip().split(',')) print 'Loading counts data' data_collection1 = RegionCollection(filename=opts.collection1) window_size = data_collection1.info['args']['window_size'] data_collection2 = RegionCollection(filename=opts.collection2) # filter both if opts.cutoff < 0 or opts.cutoff > 1: raise RuntimeError('The cutoff must be between 0 and 1') data_collection1 = data_collection1.filteredChebyshevUpper(opts.cutoff) data_collection2 = data_collection2.filteredChebyshevUpper(opts.cutoff) # make sure each collection consists ot the same genes shared_labels = set(data_collection1.labels) & \ set(data_collection2.labels) data_collection1 = data_collection1.filteredByLabel(shared_labels) data_collection2 = data_collection2.filteredByLabel(shared_labels) assert set(data_collection1.labels) == set(data_collection2.labels) if opts.sample_top is None: sample_top = data_collection1.N else: sample_top = opts.sample_top indices = range(sample_top) data_collection1 = data_collection1.take(indices) data_collection2 = data_collection2.take(indices) print 'Starting to plot' if opts.bgcolor == 'black': grid = {'color': 'w'} bgcolor = '0.1' vline_color = 'w' else: grid = {'color': 'k'} vline_color = 'k' bgcolor = '1.0' vline = dict(x=0, linewidth=opts.vline_width, linestyle=opts.vline_style, color=vline_color) plot = PlottableSingle(height=opts.fig_height / 2.5, width=opts.fig_width / 2.5, bgcolor=bgcolor, grid=grid, ylim=ylim, xlim=(-window_size, window_size), xtick_space=opts.xgrid_lines, ytick_space=opts.ygrid_lines, xtick_interval=opts.xlabel_interval, ytick_interval=opts.ylabel_interval, xlabel_fontsize=opts.xfontsize, ylabel_fontsize=opts.yfontsize, vline=vline, ioff=True) x = numpy.arange(-window_size, window_size) if opts.metric == 'Mean counts': stat = averaged else: data_collection1 = data_collection1.asfreqs() data_collection2 = data_collection2.asfreqs() stat = summed plot_sample(plot, data_collection1, stat_maker(stat, data_collection1), x, opts.title, opts.xlabel, opts.ylabel, 'b', opts.legend1, opts.plot_stderr) plot_sample(plot, data_collection2, stat_maker(stat, data_collection2), x, opts.title, opts.xlabel, opts.ylabel, 'r', opts.legend2, opts.plot_stderr) plot.legend() plot.show() if opts.plot_filename and not opts.test_run: plot.savefig(opts.plot_filename) else: print opts.plot_filename