Esempio n. 1
0
def cwrap(beta_path, blocks_df, is_nice, min_cov, verbose):
    # if verbose:
    # eprint('[wt table]', op.splitext(op.basename(beta_path))[0])
    if beta_path.endswith('.beta'):
        r = collapse_process(beta_path, blocks_df, is_nice)
        if r is None:
            return
        name = op.splitext(op.basename(beta_path))[0]
        return {name: beta2vec(r, min_cov)}
    else:
        return {
            op.basename(beta_path)[:-4]:
            load_uxm(beta_path, blocks_df, 'U', min_cov)
        }
Esempio n. 2
0
    def plot_all(self):
        import matplotlib.pyplot as plt

        fname_len = min(NR_CHARS_PER_FNAME, max([len(op.basename(op.splitext(f)[0])) for f in self.files]))
        ticks = [op.splitext(op.basename(f))[0][:fname_len].ljust(fname_len) for f in self.files]

        r = np.concatenate([beta2vec(d).reshape((1, -1)) for d in self.dsets])

        plt.imshow(1 - r, cmap='RdYlGn')
        # insert borders:
        if self.borders is not None:
            plt.vlines(self.borders - .5, -.5, len(self.files) - .5)

        plt.yticks(np.arange(len(self.files)), ticks)
        if self.args.title:
            plt.title(self.args.title)
        if self.args.output is not None:
            plt.savefig(self.args.output)
        plt.show()
Esempio n. 3
0
    def run_beta_to_bw(self, beta_path):
        eprint('{}'.format(op.basename(beta_path)))

        prefix = self.set_prefix(beta_path)
        out_bigwig = prefix + BW_EXT
        out_bed_graph = prefix + BG_EXT
        cov_bigwig = prefix + COV_BW_EXT
        cov_bed_graph = prefix + COV_BG_EXT

        # Check if the current file should be skipped:
        if not delete_or_skip(out_bigwig, self.args.force):
            return

        # load beta file
        barr = self.load_beta(beta_path)

        # dump coverage:
        if self.args.dump_cov:
            eprint('Dumping cov...')
            self.ref_dict['cov'] = barr[:, 1]
            sort_and_dump_df(
                self.ref_dict[self.ref_dict['cov'] >= self.args.min_cov],
                cov_bed_graph)
            del self.ref_dict['cov']
            # convert bedGraph to bigWig:
            self.bed_graph_to_bigwig(cov_bed_graph, cov_bigwig)

        # dump beta values to bedGraph
        eprint('Dumping beta vals...')
        self.ref_dict['beta'] = np.round(beta2vec(barr, na=-1), 3)
        if self.args.remove_nan:
            self.ref_dict = self.ref_dict[self.ref_dict['beta'] != -1]
        sort_and_dump_df(self.ref_dict, out_bed_graph)
        del self.ref_dict['beta']

        # convert bedGraphs to bigWigs:
        self.bed_graph_to_bigwig(out_bed_graph, out_bigwig)
Esempio n. 4
0
def single_beta(beta_path, indices, cov_thresh):
    return op.splitext(op.basename(beta_path))[0], \
           beta2vec(load_beta_data(beta_path)[indices - 1], min_cov=cov_thresh).astype(np.float16)