How to use the bioframe.coverage function in bioframe

To help you get started, we’ve selected a few bioframe 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 mirnylab / bioframe / tests / test_ops.py View on Github external
def test_coverage():

    #### coverage does not exceed length of original interval
    df1 = pd.DataFrame([["chr1", 3, 8]], columns=["chrom", "start", "end"])
    df2 = pd.DataFrame([["chr1", 2, 10]], columns=["chrom", "start", "end"])
    d = """chrom    start   end coverage
         0  chr1    3   8   5"""
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    print(df)
    print(bioframe.coverage(df1, df2))
    pd.testing.assert_frame_equal(df, bioframe.coverage(df1, df2))

    ### coverage of interval on different chrom returns zero for coverage and n_overlaps
    df1 = pd.DataFrame([["chr1", 3, 8]], columns=["chrom", "start", "end"])
    df2 = pd.DataFrame([["chrX", 3, 8]], columns=["chrom", "start", "end"])
    d = """chrom    start   end coverage
        0  chr1      3       8     0   """
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.coverage(df1, df2))

    ### when a second overlap starts within the first
    df1 = pd.DataFrame([["chr1", 3, 8]], columns=["chrom", "start", "end"])
    df2 = pd.DataFrame(
        [["chr1", 3, 6], ["chr1", 5, 8]], columns=["chrom", "start", "end"]
    )
github mirnylab / bioframe / tests / test_ops.py View on Github external
df1 = pd.DataFrame([["chr1", 3, 8]], columns=["chrom", "start", "end"])
    df2 = pd.DataFrame([["chr1", 2, 10]], columns=["chrom", "start", "end"])
    d = """chrom    start   end coverage
         0  chr1    3   8   5"""
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    print(df)
    print(bioframe.coverage(df1, df2))
    pd.testing.assert_frame_equal(df, bioframe.coverage(df1, df2))

    ### coverage of interval on different chrom returns zero for coverage and n_overlaps
    df1 = pd.DataFrame([["chr1", 3, 8]], columns=["chrom", "start", "end"])
    df2 = pd.DataFrame([["chrX", 3, 8]], columns=["chrom", "start", "end"])
    d = """chrom    start   end coverage
        0  chr1      3       8     0   """
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.coverage(df1, df2))

    ### when a second overlap starts within the first
    df1 = pd.DataFrame([["chr1", 3, 8]], columns=["chrom", "start", "end"])
    df2 = pd.DataFrame(
        [["chr1", 3, 6], ["chr1", 5, 8]], columns=["chrom", "start", "end"]
    )

    d = """chrom    start   end coverage
         0  chr1     3       8     5"""
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.coverage(df1, df2))