How to use the bioframe.closest 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
d = """chrom_1 start_1 end_1   chrom_2 start_2 end_2   distance
              0   chr1    1   5   chr1    10  11  5"""
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df1, df2, k=1))

    ### test other return arguments ###
    df2.iloc[0, 0] = "chr1"
    d = """
        index_1 index_2 have_overlap    overlap_start   overlap_end distance
        0   0   0   True    4   5   0
        1   0   1   False           5
        """
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(
        df,
        bioframe.closest(
            df1,
            df2,
            k=2,
            return_overlap=True,
            return_index=True,
            return_input=False,
            return_distance=True,
        ),
        check_dtype=False,
    )
github mirnylab / bioframe / tests / test_ops.py View on Github external
df2 = pd.DataFrame(
        [["chr1", 4, 8], ["chr1", 10, 11]], columns=["chrom", "start", "end"]
    )

    ### closest(df1,df2,k=1) ###
    d = """chrom_1  start_1  end_1 chrom_2  start_2  end_2  distance
        0    chr1        1      5    chr1        4      8         0"""
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df1, df2, k=1))

    ### closest(df1,df2, ignore_overlaps=True)) ###
    d = """chrom_1 start_1 end_1   chrom_2 start_2 end_2   distance
        0   chr1    1   5   chr1    10  11  5"""
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df1, df2, ignore_overlaps=True))

    ### closest(df1,df2,k=2) ###
    d = """chrom_1 start_1 end_1   chrom_2 start_2 end_2   distance
            0   chr1    1   5   chr1    4   8   0
            1   chr1    1   5   chr1    10  11  5"""
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df1, df2, k=2))

    ### closest(df2,df1) ###
    d = """chrom_1  start_1 end_1   chrom_2 start_2 end_2   distance
            0   chr1    4   8   chr1    1   5   0
            1   chr1    10  11  chr1    1   5   5 """
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df2, df1))

    ### change first interval to new chrom ###
github mirnylab / bioframe / tests / test_ops.py View on Github external
0    chr1        1      5    chr1        4      8         0"""
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df1, df2, k=1))

    ### closest(df1,df2, ignore_overlaps=True)) ###
    d = """chrom_1 start_1 end_1   chrom_2 start_2 end_2   distance
        0   chr1    1   5   chr1    10  11  5"""
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df1, df2, ignore_overlaps=True))

    ### closest(df1,df2,k=2) ###
    d = """chrom_1 start_1 end_1   chrom_2 start_2 end_2   distance
            0   chr1    1   5   chr1    4   8   0
            1   chr1    1   5   chr1    10  11  5"""
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df1, df2, k=2))

    ### closest(df2,df1) ###
    d = """chrom_1  start_1 end_1   chrom_2 start_2 end_2   distance
            0   chr1    4   8   chr1    1   5   0
            1   chr1    10  11  chr1    1   5   5 """
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df2, df1))

    ### change first interval to new chrom ###
    df2.iloc[0, 0] = "chrA"
    d = """chrom_1 start_1 end_1   chrom_2 start_2 end_2   distance
              0   chr1    1   5   chr1    10  11  5"""
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df1, df2, k=1))

    ### test other return arguments ###
github mirnylab / bioframe / tests / test_ops.py View on Github external
df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df1, df2, k=2))

    ### closest(df2,df1) ###
    d = """chrom_1  start_1 end_1   chrom_2 start_2 end_2   distance
            0   chr1    4   8   chr1    1   5   0
            1   chr1    10  11  chr1    1   5   5 """
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df2, df1))

    ### change first interval to new chrom ###
    df2.iloc[0, 0] = "chrA"
    d = """chrom_1 start_1 end_1   chrom_2 start_2 end_2   distance
              0   chr1    1   5   chr1    10  11  5"""
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df1, df2, k=1))

    ### test other return arguments ###
    df2.iloc[0, 0] = "chr1"
    d = """
        index_1 index_2 have_overlap    overlap_start   overlap_end distance
        0   0   0   True    4   5   0
        1   0   1   False           5
        """
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(
        df,
        bioframe.closest(
            df1,
            df2,
            k=2,
            return_overlap=True,
github mirnylab / bioframe / tests / test_ops.py View on Github external
df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df1, df2, ignore_overlaps=True))

    ### closest(df1,df2,k=2) ###
    d = """chrom_1 start_1 end_1   chrom_2 start_2 end_2   distance
            0   chr1    1   5   chr1    4   8   0
            1   chr1    1   5   chr1    10  11  5"""
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df1, df2, k=2))

    ### closest(df2,df1) ###
    d = """chrom_1  start_1 end_1   chrom_2 start_2 end_2   distance
            0   chr1    4   8   chr1    1   5   0
            1   chr1    10  11  chr1    1   5   5 """
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df2, df1))

    ### change first interval to new chrom ###
    df2.iloc[0, 0] = "chrA"
    d = """chrom_1 start_1 end_1   chrom_2 start_2 end_2   distance
              0   chr1    1   5   chr1    10  11  5"""
    df = pd.read_csv(StringIO(d), sep=r"\s+")
    pd.testing.assert_frame_equal(df, bioframe.closest(df1, df2, k=1))

    ### test other return arguments ###
    df2.iloc[0, 0] = "chr1"
    d = """
        index_1 index_2 have_overlap    overlap_start   overlap_end distance
        0   0   0   True    4   5   0
        1   0   1   False           5
        """
    df = pd.read_csv(StringIO(d), sep=r"\s+")