# Path: bioframe/core/construction.py
# def from_any(regions, fill_null=False, name_col="name", cols=None):
#     """
#     Attempts to make a genomic interval dataframe with columns [chr, start, end, name_col] from a variety of input types.
# 
#     Parameters
#     ----------
#     regions : supported input
#         Currently supported inputs:
# 
#             - dataframe
#             - series of UCSC strings
#             - dictionary of {str:int} key value pairs
#             - pandas series where the index is interpreted as chromosomes and values are interpreted as end
#             - list of tuples or lists, either [(chrom,start,end)] or [(chrom,start,end,name)]
#             - tuple of tuples or lists, either [(chrom,start,end)] or [(chrom,start,end,name)]
# 
#     fill_null : False or dictionary
#         Accepts a dictionary of {str:int} pairs, interpreted as chromosome sizes.
#         Kept or backwards compatibility. Default False.
# 
#     name_col : str
#         Column name. Only used if 4 column list is provided. Default "name".
# 
#     cols : (str,str,str)
#         Names for dataframe columns.
#         Default None sets them with get_default_colnames().
# 
#     Returns
#     -------
#     out_df:dataframe
# 
#     """
#     ck1, sk1, ek1 = _get_default_colnames() if cols is None else cols
# 
#     if type(regions) is pd.core.frame.DataFrame:
#         if set([ck1, sk1, ek1]).issubset(regions.columns):
#             out_df = regions.copy()
#         elif (len(regions[name_col].values.shape) == 1) and is_complete_ucsc_string(
#             regions[name_col].values[0]
#         ):
#             out_df = from_ucsc_string_list(
#                 regions[name_col].values, cols=[ck1, sk1, ek1]
#             )
#         else:
#             raise ValueError("Unknown dataFrame format: check column names")
# 
#     elif type(regions) is dict:
#         out_df = from_dict(regions, cols=[ck1, sk1, ek1])
# 
#     elif type(regions) is pd.core.series.Series:
#         out_df = from_series(regions, cols=[ck1, sk1, ek1])
# 
#     elif type(regions) is tuple:
#         if np.shape(regions) == (3,):
#             out_df = from_list([regions], name_col=name_col, cols=[ck1, sk1, ek1])
# 
#         elif len(np.shape(regions)) == 1 and type(regions[0]) is str:
#             out_df = from_ucsc_string_list(regions, cols=[ck1, sk1, ek1])
#         else:
#             out_df = from_list(list(regions), name_col=name_col, cols=[ck1, sk1, ek1])
# 
#     elif type(regions) is list:
#         if np.shape(regions) == (3,):
#             out_df = from_list([regions], name_col=name_col, cols=[ck1, sk1, ek1])
#         elif len(np.shape(regions)) == 1 and type(regions[0]) is str:
#             out_df = from_ucsc_string_list(regions, cols=[ck1, sk1, ek1])
#         else:
#             out_df = from_list(regions, name_col=name_col, cols=[ck1, sk1, ek1])
#     else:
#         raise ValueError(f"Unknown input format: {type(regions)}")
# 
#     if fill_null:
#         try:
#             out_df[sk1].fillna(0, inplace=True)
#             ends = []
#             for i in range(len(out_df)):
#                 if out_df[ek1].values[i] is None:
#                     ends.append(fill_null[out_df[ck1].values[i]])
#                 else:
#                     ends.append(out_df[ek1].values[i])
#             out_df[ek1] = ends
#         except:
#             raise ValueError("could not fill ends with provided chromsizes")
# 
#     return out_df
# 
# Path: bioframe/core/construction.py
# def from_dict(regions, cols=None):
# def from_series(regions, cols=None):
# def from_list(regions, name_col="name", cols=None):
# def from_ucsc_string_list(region_list, cols=None):
# def from_any(regions, fill_null=False, name_col="name", cols=None):
# def add_ucsc_name_column(reg_df, name_col="name", cols=None):
# def make_viewframe(
#     regions,
#     check_bounds=None,
#     name_style=None,
#     view_name_col="name",
#     cols=None,
# ):
# def sanitize_bedframe(
#     df1,
#     recast_dtypes=True,
#     drop_null=False,
#     start_exceed_end_action=None,
#     cols=None,
# ):


from io import StringIO
from bioframe.core.construction import from_any
from bioframe.core import construction
import pandas as pd
import numpy as np
import pytest




def test_add_ucsc_name_column():
    df = pd.DataFrame(
        {"chrom": [f"chr{i}" for i in range(3)], "start": [1, 2, 3], "end": [4, 5, 6]}
    )

    pd.testing.assert_series_equal(
        construction.add_ucsc_name_column(df)["name"],
        pd.Series(
            data=["chr0:1-4", "chr1:2-5", "chr2:3-6"], index=[0, 1, 2], name="name"
        ),
    )


def test_any():

    ### tests copied from old parse_regions
    # main functionality: convert to dataframe and create name
    df = pd.DataFrame(
        {"chrom": [f"chr{i}" for i in range(3)], "start": [1, 2, 3], "end": [4, 5, 6]}
    )

# Path: bioframe/core/construction.py
# def from_any(regions, fill_null=False, name_col="name", cols=None):
#     """
#     Attempts to make a genomic interval dataframe with columns [chr, start, end, name_col] from a variety of input types.
# 
#     Parameters
#     ----------
#     regions : supported input
#         Currently supported inputs:
# 
#             - dataframe
#             - series of UCSC strings
#             - dictionary of {str:int} key value pairs
#             - pandas series where the index is interpreted as chromosomes and values are interpreted as end
#             - list of tuples or lists, either [(chrom,start,end)] or [(chrom,start,end,name)]
#             - tuple of tuples or lists, either [(chrom,start,end)] or [(chrom,start,end,name)]
# 
#     fill_null : False or dictionary
#         Accepts a dictionary of {str:int} pairs, interpreted as chromosome sizes.
#         Kept or backwards compatibility. Default False.
# 
#     name_col : str
#         Column name. Only used if 4 column list is provided. Default "name".
# 
#     cols : (str,str,str)
#         Names for dataframe columns.
#         Default None sets them with get_default_colnames().
# 
#     Returns
#     -------
#     out_df:dataframe
# 
#     """
#     ck1, sk1, ek1 = _get_default_colnames() if cols is None else cols
# 
#     if type(regions) is pd.core.frame.DataFrame:
#         if set([ck1, sk1, ek1]).issubset(regions.columns):
#             out_df = regions.copy()
#         elif (len(regions[name_col].values.shape) == 1) and is_complete_ucsc_string(
#             regions[name_col].values[0]
#         ):
#             out_df = from_ucsc_string_list(
#                 regions[name_col].values, cols=[ck1, sk1, ek1]
#             )
#         else:
#             raise ValueError("Unknown dataFrame format: check column names")
# 
#     elif type(regions) is dict:
#         out_df = from_dict(regions, cols=[ck1, sk1, ek1])
# 
#     elif type(regions) is pd.core.series.Series:
#         out_df = from_series(regions, cols=[ck1, sk1, ek1])
# 
#     elif type(regions) is tuple:
#         if np.shape(regions) == (3,):
#             out_df = from_list([regions], name_col=name_col, cols=[ck1, sk1, ek1])
# 
#         elif len(np.shape(regions)) == 1 and type(regions[0]) is str:
#             out_df = from_ucsc_string_list(regions, cols=[ck1, sk1, ek1])
#         else:
#             out_df = from_list(list(regions), name_col=name_col, cols=[ck1, sk1, ek1])
# 
#     elif type(regions) is list:
#         if np.shape(regions) == (3,):
#             out_df = from_list([regions], name_col=name_col, cols=[ck1, sk1, ek1])
#         elif len(np.shape(regions)) == 1 and type(regions[0]) is str:
#             out_df = from_ucsc_string_list(regions, cols=[ck1, sk1, ek1])
#         else:
#             out_df = from_list(regions, name_col=name_col, cols=[ck1, sk1, ek1])
#     else:
#         raise ValueError(f"Unknown input format: {type(regions)}")
# 
#     if fill_null:
#         try:
#             out_df[sk1].fillna(0, inplace=True)
#             ends = []
#             for i in range(len(out_df)):
#                 if out_df[ek1].values[i] is None:
#                     ends.append(fill_null[out_df[ck1].values[i]])
#                 else:
#                     ends.append(out_df[ek1].values[i])
#             out_df[ek1] = ends
#         except:
#             raise ValueError("could not fill ends with provided chromsizes")
# 
#     return out_df
# 
# Path: bioframe/core/construction.py
# def from_dict(regions, cols=None):
# def from_series(regions, cols=None):
# def from_list(regions, name_col="name", cols=None):
# def from_ucsc_string_list(region_list, cols=None):
# def from_any(regions, fill_null=False, name_col="name", cols=None):
# def add_ucsc_name_column(reg_df, name_col="name", cols=None):
# def make_viewframe(
#     regions,
#     check_bounds=None,
#     name_style=None,
#     view_name_col="name",
#     cols=None,
# ):
# def sanitize_bedframe(
#     df1,
#     recast_dtypes=True,
#     drop_null=False,
#     start_exceed_end_action=None,
#     cols=None,
# ):


# Path: tests/test_core_construction.py
from io import StringIO
from bioframe.core.construction import from_any
from bioframe.core import construction
import pandas as pd
import numpy as np
import pytest





def test_add_ucsc_name_column():
    df = pd.DataFrame(
        {"chrom": [f"chr{i}" for i in range(3)], "start": [1, 2, 3], "end": [4, 5, 6]}
    )

    pd.testing.assert_series_equal(
        construction.add_ucsc_name_column(df)["name"],
        pd.Series(
            data=["chr0:1-4", "chr1:2-5", "chr2:3-6"], index=[0, 1, 2], name="name"
        ),
    )


def test_any():

    ### tests copied from old parse_regions
    # main functionality: convert to dataframe and create name
    df = pd.DataFrame(
        {"chrom": [f"chr{i}" for i in range(3)], "start": [1, 2, 3], "end": [4, 5, 6]}
    )

    parsed = from_any(df)