File: __init__.py

package info (click to toggle)
python-ncls 0.0.70%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 412 kB
  • sloc: ansic: 2,246; python: 197; sh: 18; makefile: 8
file content (38 lines) | stat: -rw-r--r-- 1,293 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import numpy as np

try:
    from importlib.metadata import version as _ver
except ImportError:
    try:
        from importlib_metadata import version as _ver
    except ImportError:
        import pkg_resources
        _ver = lambda name: pkg_resources.get_distribution(name).version

from ncls.src.ncls import NCLS64  # type: ignore
from ncls.src.ncls32 import NCLS32  # type: ignore


def NCLS(starts, ends, ids):
    if isinstance(starts, list) or "pandas" in str(type(starts)):
        starts, ends, ids = [np.array(s) for s in [starts, ends, ids]]

    ids = ids.astype(np.int64)
    if starts.dtype == np.int64:
        return NCLS64(starts.astype(np.int64), ends.astype(np.int64), ids)
    elif starts.dtype == np.int32:
        return NCLS32(starts.astype(np.int32), ends.astype(np.int32), ids)
    else:
        raise Exception("Starts/Ends not int64 or int32: " + str(starts.dtype))


def FNCLS(starts, ends, ids):
    from ncls.src.fncls import FNCLS  # type: ignore

    if isinstance(starts, list) or "pandas" in str(type(starts)):
        starts, ends, ids = [np.array(s) for s in [starts, ends, ids]]

    if starts.dtype == np.double:
        return FNCLS(starts, ends.astype(np.double), ids)
    else:
        raise Exception("Starts/Ends not double: " + str(starts.dtype))