# Path: bioframe/core/stringops.py
# def to_ucsc_string(triplet):
# def _parse_humanized(s):
# def parse_region_string(s):
#     def _tokenize(s):
#     def _check_token(typ, token, expected):
#     def _expect(tokens):
# def is_complete_ucsc_string(mystring):
# def parse_region(reg, chromsizes=None):
#     _NUMERIC_RE = re.compile("([0-9,.]+)")
# 
# Path: bioframe/core/stringops.py
# def parse_region(reg, chromsizes=None):
#     """
#     Coerce a genomic region string or sequence into a triple (chrom, start, end).
# 
#     Genomic regions are represented as half-open intervals (0-based starts,
#     1-based ends) along the length coordinate of a contig/scaffold/chromosome.
#     Start must be >= 0, and end coordinate must be >= start.
# 
#     Parameters
#     ----------
#     reg : str or tuple
#         UCSC-style genomic region string, or
#         Triple (chrom, start, end), where ``start`` or ``end`` may be ``None``.
#         Quadriple (chrom, start, end, name) (name is ignored).
#     chromsizes : mapping, optional
#         Lookup table of scaffold lengths to check against ``chrom`` and the
#         ``end`` coordinate. Required if ``end`` is not supplied.
# 
#     Returns
#     -------
#     triple : (str, int, int)
#         A well-formed genomic region triple (str, int, int)
# 
#     """
#     if isinstance(reg, str):
#         chrom, start, end = parse_region_string(reg)
#     else:
#         if len(reg) not in [3, 4]:
#             raise ValueError("length of a region should be 3 or 4")
#         chrom, start, end = reg[:3]
#         start = int(start) if start is not None else start
#         end = int(end) if end is not None else end
# 
#     try:
#         clen = chromsizes[chrom] if chromsizes is not None else None
#     except KeyError:
#         raise ValueError("Unknown sequence label: {}".format(chrom))
# 
#     start = 0 if start is None else start
#     if end is None:
#         end = clen  # if clen is None, end is None too!
# 
#     if (end is not None) and (end < start):
#         raise ValueError("End cannot be less than start")
# 
#     if start < 0 or (clen is not None and end > clen):
#         raise ValueError("Genomic region out of bounds: [{}, {})".format(start, end))
# 
#     return chrom, start, end


import pandas as pd
import numpy as np
import pytest
from bioframe.core import stringops
from bioframe.core.stringops import parse_region



def test_to_ucsc_string():
    assert stringops.to_ucsc_string(("chr21", 1, 4)) == "chr21:1-4"


def test_parse_region():
    # UCSC-style names

# Path: bioframe/core/stringops.py
# def to_ucsc_string(triplet):
# def _parse_humanized(s):
# def parse_region_string(s):
#     def _tokenize(s):
#     def _check_token(typ, token, expected):
#     def _expect(tokens):
# def is_complete_ucsc_string(mystring):
# def parse_region(reg, chromsizes=None):
#     _NUMERIC_RE = re.compile("([0-9,.]+)")
# 
# Path: bioframe/core/stringops.py
# def parse_region(reg, chromsizes=None):
#     """
#     Coerce a genomic region string or sequence into a triple (chrom, start, end).
# 
#     Genomic regions are represented as half-open intervals (0-based starts,
#     1-based ends) along the length coordinate of a contig/scaffold/chromosome.
#     Start must be >= 0, and end coordinate must be >= start.
# 
#     Parameters
#     ----------
#     reg : str or tuple
#         UCSC-style genomic region string, or
#         Triple (chrom, start, end), where ``start`` or ``end`` may be ``None``.
#         Quadriple (chrom, start, end, name) (name is ignored).
#     chromsizes : mapping, optional
#         Lookup table of scaffold lengths to check against ``chrom`` and the
#         ``end`` coordinate. Required if ``end`` is not supplied.
# 
#     Returns
#     -------
#     triple : (str, int, int)
#         A well-formed genomic region triple (str, int, int)
# 
#     """
#     if isinstance(reg, str):
#         chrom, start, end = parse_region_string(reg)
#     else:
#         if len(reg) not in [3, 4]:
#             raise ValueError("length of a region should be 3 or 4")
#         chrom, start, end = reg[:3]
#         start = int(start) if start is not None else start
#         end = int(end) if end is not None else end
# 
#     try:
#         clen = chromsizes[chrom] if chromsizes is not None else None
#     except KeyError:
#         raise ValueError("Unknown sequence label: {}".format(chrom))
# 
#     start = 0 if start is None else start
#     if end is None:
#         end = clen  # if clen is None, end is None too!
# 
#     if (end is not None) and (end < start):
#         raise ValueError("End cannot be less than start")
# 
#     if start < 0 or (clen is not None and end > clen):
#         raise ValueError("Genomic region out of bounds: [{}, {})".format(start, end))
# 
#     return chrom, start, end


# Path: tests/test_core_stringops.py
import pandas as pd
import numpy as np
import pytest
from bioframe.core import stringops
from bioframe.core.stringops import parse_region




def test_to_ucsc_string():
    assert stringops.to_ucsc_string(("chr21", 1, 4)) == "chr21:1-4"


def test_parse_region():
    # UCSC-style names

    assert parse_region("chr21") == ("chr21", 0, None)