def block_generator(self): masking_plot = PlotParser(self.combined_mask_file) blocks = self.increased_insertions_blocks(masking_plot) + self.decreased_insertions_blocks(masking_plot) '''Filter out blocks which are less than the window size''' filtered_blocks = [b for b in blocks if b.block_length >= self.window_size] forward_masking_plot = PlotParser(self.forward_mask_file) reverse_masking_plot = PlotParser(self.reverse_mask_file) for b in filtered_blocks: b.direction = self.direction_for_block(b, forward_masking_plot, reverse_masking_plot) return filtered_blocks
def masking(self): masking_plot = PlotParser(self.masking_plot_file) output_plot_files = {} for insertion_filename in self.insertion_plot_files: insertion_plot = PlotParser(insertion_filename) for i, mask in enumerate(masking_plot.combined): if mask == 0 and self.strict_signal: insertion_plot.forward[i] = 0 insertion_plot.reverse[i] = 0 fd, output_filename = mkstemp() pg = PlotGenerator(insertion_plot.forward, insertion_plot.reverse, output_filename) pg.construct_file() output_plot_files[insertion_filename] = output_filename return output_plot_files
def get_plot_objs(self, files): plot_objs = {} for f in files: plot_objs[f] = PlotParser(f) self.genome_size = len(plot_objs[f].combined) if self.verbose: print(plot_objs[f]) return plot_objs
def test_valid_threshold(self): d = PlotParser(os.path.join(data_dir, 'valid'), 3) self.assertTrue( self.check_arrays_equal(d.forward, [0, 0, 0, 0, 0, 0, 0, 3])) self.assertTrue( self.check_arrays_equal(d.reverse, [0, 0, 4, 5, 0, 0, 0, 0])) self.assertTrue( self.check_arrays_equal(d.combined, [0, 0, 4, 5, 0, 0, 0, 3]))
def test_valid_ziped(self): d = PlotParser(os.path.join(data_dir, 'valid.gz'), 0) self.assertTrue( self.check_arrays_equal(d.forward, [0, 0, 0, 0, 0, 1, 1, 3])) self.assertTrue( self.check_arrays_equal(d.reverse, [0, 1, 4, 5, 0, 0, 0, 0])) self.assertTrue( self.check_arrays_equal(d.combined, [0, 1, 4, 5, 0, 1, 1, 3]))
def test_generate_and_read(self): filename = os.path.join(data_dir, 'plot.test') p = PlotGenerator([0,0,0,0,0,1,1,3], [9,9,0,9,9,1,1,3], filename) p.construct_file() d = PlotParser(filename,0) self.assertTrue(self.check_arrays_equal(d.forward, [0,0,0,0,0,1,1,3])) self.assertTrue(self.check_arrays_equal(d.reverse, [9,9,0,9,9,1,1,3])) self.assertTrue(self.check_arrays_equal(d.combined, [9,9,0,9,9,2,2,6])) os.remove(filename)
def plot_parser(self): return PlotParser(self.plotfile, self.minimum_threshold)
def read_plots(self): plot_objs = {} for p in self.plotfiles: pp = PlotParser(p) plot_objs[p] = pp return plot_objs
def test_large_file_zipped(self): d = PlotParser( os.path.join(data_dir, 'Control2.out.CP009273.insert_site_plot.gz'), 3) self.assertEqual(d.total_reads, 7684360)