Beispiel #1
0
def test_split_by_strands():
    genset = GenCoorSet(name="Test_set")
    bedfile = os.path.join(os.getenv("HOME"),
                           "gencoor_data/hg38/genes_hg38.bed")
    genset.load(filename=bedfile, filetype="BED")
    res = genset.split_by_strands()
    assert set([g.strand for g in res["+"]]) == set(["+"])
    assert set([g.strand for g in res["-"]]) == set(["-"])
Beispiel #2
0
def test_GenCoorSet_load():
    genset = GenCoorSet(name="Test_set")
    bedfile = os.path.join(os.getenv("HOME"),
                           "gencoor_data/hg38/genes_hg38.bed")
    bedfile2 = os.path.join(os.getenv("HOME"),
                            "gencoor_data/hg38/genes_hg38_test.bed")
    genset.load(filename=bedfile, filetype="BED")
    genset.save(filename=bedfile2, filetype="BED")
    os.remove(bedfile2)
Beispiel #3
0
def bed_sig2arr(bedname, sig_names, exp, arg):
    regions = GenCoorSet(name=bedname)
    regions.load(filename=exp.get_file(bedname))
    if arg["--test"]:
        regions.list = regions.list[0:50]
    regions.relocate(mode='center as center', width=2*int(arg["--ext"]))
    sig = SignalProfile(regions, genome=arg["--genome"],
                        bin=int(arg["--bin"]), step=int(arg["--step"]),
                        cores=int(arg["--cores"]))
    for signal in sig_names:
        if exp.get_file(signal).endswith(".bw") or exp.get_file(signal).endswith(".bigwig"):
            sig.load_bigwig(filename=exp.get_file(signal), label=signal,
                            disable_progressbar=False, verbal=False)
        elif exp.get_file(signal).endswith(".bam"):
            sig.load_bam(filename=exp.get_file(signal), label=signal,
                            disable_progressbar=False, verbal=False)
    res = sig.cov2array()

    return res
Beispiel #4
0
                if len(signals) > 1:
                    print("There are more than one BED files sharing the same tags, only the first one will be used.")

                arrs = bed_sig2arr(beds[0], [signals[0]], exp, arg)
                a = arrs[signals[0]]
                hm = axes[i, j].imshow(a, cmap='hot', interpolation='None')
                # Y ticks
                axes[i, j].get_yaxis().set_ticks([])
                # X ticks
                x_label_list = ['-'+arg["--ext"], '0', arg["--ext"]]
                xmin, xmax = axes[i, j].get_xlim()
                axes[i, j].set_xticks([xmin, int(0.5 * (xmax - xmin)), xmax])
                axes[i, j].set_xticklabels(x_label_list)

                # labels
                if j == 0:
                    axes[i, j].set_ylabel(row)
                if i == 0:
                    regions = GenCoorSet(name=beds[0])
                    regions.load(filename=exp.get_file(beds[0]))
                    axes[i, j].set_title(col+" ("+str(len(regions))+")")


        cbar_ax = fig.add_axes([0.9, 0.15, 0.02, 0.7])
        fig.colorbar(hm, cax=cbar_ax)

        set_yaxis(n_row, n_col, axes, arg)
        fig.savefig(arg["<output_file>"], bbox_inches='tight')

    # elif arg["boxplot"]:
Beispiel #5
0
    Blablabla

Options:

"""

from docopt import docopt
from gencoor.coordinates import GenCoorSet
import os

if __name__ == '__main__':
    arg = docopt(__doc__)
    if arg["resize"]:
        gc = GenCoorSet(name="input")
        gc.load(arg["<input_BED_file_path>"], filetype="BED")
        gc.relocate(mode='center as center', width=int(arg["<length>"]))
        gc.save(arg["<output_BED_file_path>"], filetype="BED")

    elif arg["split_strand"]:
        name = os.path.basename(arg["<input_BED_file_path>"]).split(".")[0]
        print(
            os.path.join(arg["<output_BED_directory_path>"],
                         name + "_" + "+" + ".bed"))
        gc = GenCoorSet(name="input")
        gc.load(arg["<input_BED_file_path>"], filetype="BED")
        res = gc.split_by_strands()
        for k, g in res.items():
            g.save(os.path.join(arg["<output_BED_directory_path>"],
                                name + "_" + k + ".bed"),
                   filetype="BED")