How to use the pyranges.pyranges.PyRanges function in pyranges

To help you get started, we’ve selected a few pyranges examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github biocore-ntnu / pyranges / tests / test_nearest_previous_nonoverlapping.py View on Github external
def hyp14():

    c = """chr1      0    1      +"""

    return PyRanges(pd.read_table(StringIO(c), sep="\s+", header=None, names="Chromosome Start End Strand".split()))
github biocore-ntnu / pyranges / tests / test_nearest_previous_nonoverlapping.py View on Github external
def hyp8():

    c = """chr1      0    1      +"""

    return PyRanges(pd.read_table(StringIO(c), sep="\s+", header=None, names="Chromosome Start End Strand".split()))
github biocore-ntnu / pyranges / tests / test_nearest_next.py View on Github external
def expected_result_unstranded():

 c = """Chromosome Start End Name Score Strand Start_b End_b Name_b Score_b Strand_b Distance
0 chr1 3 6 h 0 + 6 7 f 0 - 1
1 chr1 5 7 h 0 - 6 7 f 0 - 0"""

 return PyRanges(pd.read_table(StringIO(c), sep=" "))
github biocore-ntnu / pyranges / tests / test_advanced_overlap_keep_both.py View on Github external
def expected_result_overlap_opposite_strand_suffixes():

    c = """Chromosome Start End Name Score Strand Start_b End_b Name_b Score_b Strand_b
chr8	38747226	38747251	U0	0	-	38747236	38747261	U0	0	+
chr1	226987592	226987617	U0	0	+	226987603	226987628	U0	0	-"""

    return PyRanges(pd.read_table(StringIO(c), sep="\s+"))
github biocore-ntnu / pyranges / tests / test_overlap_simple.py View on Github external
def background():
    c = """Chromosome Start End Name Score Strand
chr1	226987603	226987628	U0	0	-
chr8	38747236	38747261	U0	0	+
chr15	26105493	26105518	U0	0	+"""


    df = pd.read_table(StringIO(c), sep="\s+", header=0)
    print(df)
    return PyRanges(df)
github biocore-ntnu / pyranges / pyranges / pyranges.py View on Github external
def count_overlaps(self, other, **kwargs):

        kwargs = fill_kwargs(kwargs)

        from pyranges.methods.coverage import _number_overlapping
        counts = pyrange_apply(_number_overlapping, self, other, **kwargs)

        return pr.PyRanges(counts)
github biocore-ntnu / pyranges / pyranges / pyranges.py View on Github external
def subset(self, function, strand=None, **kwargs):

        kwargs = fill_kwargs(kwargs)

        if strand is None:
            strand = self.stranded

        if self.stranded and not strand:
            self = self.unstrand()

        result = pyrange_apply_single(function, self, strand, kwargs)

        if not result:
            return pr.PyRanges()

        first_result = next(iter(result.values()))

        assert first_result.dtype == bool, "result of subset function must be bool, but is {}".format(
            first_result.dtype)

        return self[result]
github biocore-ntnu / pyranges / pyranges / pyranges.py View on Github external
def slack(self, slack):

        if isinstance(slack, dict):
            assert self.stranded, "PyRanges must be stranded to add 5/3-end specific slack."

        kwargs = fill_kwargs({"slack": slack})

        prg = PyRanges(
            pyrange_apply_single(_slack, self, self.stranded, kwargs))

        return prg
github biocore-ntnu / pyranges / pyranges / pyranges.py View on Github external
try: # if k is an array
            k = k.values
        except:
            pass

        self.__k__ = k
        self.__IX__ = np.arange(len(self))


        # from time import time
        # start = time()
        dfs = pyrange_apply(_nearest, self, other, **kwargs)
        # end = time()
        # print("nearest", end - start)

        nearest = PyRanges(dfs)
        # nearest.msp()
        # raise
        # print("nearest len", len(nearest))

        if not overlap:
            # self = self.drop(like="__k__|__IX__")
            result = nearest#.drop(like="__k__|__IX__")
        else:
            from collections import defaultdict
            overlap_kwargs = {k: v for k, v in kwargs.items()}
            # print("kwargs ties:", kwargs.get("ties"))
            overlap_kwargs["how"] = defaultdict(lambda: None, {"first": "first", "last": "last"})[kwargs.get("ties")]
            # start = time()
            overlaps = self.join(other, **overlap_kwargs)
            # end = time()
            # print("overlaps", end - start)