Commit 96b6e2ce authored by Martin Larralde's avatar Martin Larralde
Browse files

Add some magic methods to `Mask`

parent e6836a83
......@@ -23,6 +23,7 @@ cdef public set TRANSLATION_TABLES
# --- Sequence mask ----------------------------------------------------------
cdef class Mask:
cdef _mask _data
cdef Masks owner
cdef _mask* mask
......
import threading
import typing
from typing import Iterable, Iterator, List, Dict, Optional, Set, TextIO, Tuple, Union
from typing import FrozenSet, Iterable, Iterator, List, Dict, Optional, TextIO, Tuple, Union
# --- Globals ----------------------------------------------------------------
......@@ -12,13 +12,16 @@ _AVX2_BUILD_SUPPORT : bool
_NEON_BUILD_SUPPORT : bool
_SSE2_BUILD_SUPPORT : bool
_TRANSLATION_TABLES : Set[int]
_TRANSLATION_TABLES : FrozenSet[int]
METAGENOMIC_BINS : Tuple[MetagenomicBin]
# --- Sequence mask ----------------------------------------------------------
class Mask:
def __init__(self, begin: int, end: int) -> None: ...
def __repr__(self) -> str: ...
def __eq__(self, other: Mask) -> bool: ...
@property
def begin(self) -> int: ...
@property
......
......@@ -120,7 +120,7 @@ cdef size_t MIN_GENES_ALLOC = 8
cdef size_t MIN_NODES_ALLOC = 8 * MIN_GENES_ALLOC
cdef set TRANSLATION_TABLES = set(range(1, 7)) | set(range(9, 17)) | set(range(21, 26))
_TRANSLATION_TABLES = TRANSLATION_TABLES
_TRANSLATION_TABLES = frozenset(TRANSLATION_TABLES)
# --- Sequence mask ----------------------------------------------------------
......@@ -130,6 +130,26 @@ cdef class Mask:
"""
# --- Magic methods ------------------------------------------------------
def __init__(self, int begin, int end):
self.owner = None
self.mask = &self._data
self.mask.begin = begin
self.mask.end = end
def __repr__(self):
ty = type(self)
return "<{}.{} begin={!r} end={!r}>".format(
ty.__module__,
ty.__name__,
self.mask.begin,
self.mask.end,
)
def __eq__(self, other):
if isinstance(other, Mask):
return self.mask.begin == other.begin and self.mask.end == other.end
return False
# --- Properties ---------------------------------------------------------
@property
......
......@@ -2,6 +2,7 @@ from . import (
test_connection_scorer,
test_gene,
test_genes,
test_mask,
test_nodes,
test_orf_finder,
test_sequence,
......@@ -12,6 +13,7 @@ def load_tests(loader, suite, pattern):
suite.addTests(loader.loadTestsFromModule(test_connection_scorer))
suite.addTests(loader.loadTestsFromModule(test_gene))
suite.addTests(loader.loadTestsFromModule(test_genes))
suite.addTests(loader.loadTestsFromModule(test_mask))
suite.addTests(loader.loadTestsFromModule(test_nodes))
suite.addTests(loader.loadTestsFromModule(test_orf_finder))
suite.addTests(loader.loadTestsFromModule(test_sequence))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment