| 1 |
import numpy as np |
| 2 |
|
| 3 |
try: |
| 4 |
from importlib.metadata import version as _ver |
| 5 |
except ImportError: |
| 6 |
try: |
| 7 |
from importlib_metadata import version as _ver |
| 8 |
except ImportError: |
| 9 |
import pkg_resources |
| 10 |
_ver = lambda name: pkg_resources.get_distribution(name).version |
| 11 |
|
| 12 |
from ncls.src.ncls import NCLS64 # type: ignore |
| 13 |
from ncls.src.ncls32 import NCLS32 # type: ignore |
| 14 |
|
| 15 |
|
| 16 |
def NCLS(starts, ends, ids): |
| 17 |
if isinstance(starts, list) or "pandas" in str(type(starts)): |
| 18 |
starts, ends, ids = [np.array(s) for s in [starts, ends, ids]] |
| 19 |
|
| 20 |
ids = ids.astype(np.int64) |
| 21 |
if starts.dtype == np.int64: |
| 22 |
return NCLS64(starts.astype(np.int64), ends.astype(np.int64), ids) |
| 23 |
elif starts.dtype == np.int32: |
| 24 |
return NCLS32(starts.astype(np.int32), ends.astype(np.int32), ids) |
| 25 |
else: |
| 26 |
raise Exception("Starts/Ends not int64 or int32: " + str(starts.dtype)) |
| 27 |
|
| 28 |
|
| 29 |
def FNCLS(starts, ends, ids): |
| 30 |
from ncls.src.fncls import FNCLS # type: ignore |
| 31 |
|
| 32 |
if isinstance(starts, list) or "pandas" in str(type(starts)): |
| 33 |
starts, ends, ids = [np.array(s) for s in [starts, ends, ids]] |
| 34 |
|
| 35 |
if starts.dtype == np.double: |
| 36 |
return FNCLS(starts, ends.astype(np.double), ids) |
| 37 |
else: |
| 38 |
raise Exception("Starts/Ends not double: " + str(starts.dtype)) |