Skip to content
Snippets Groups Projects
Commit f74fa347 authored by Martin Larralde's avatar Martin Larralde
Browse files

Implement `__getstate__` and `__setstate__` for `Hit` and `MinimizerInfo`

parent 2642ca11
No related branches found
No related tags found
No related merge requests found
import typing import typing
from typing import Generic, List, Union, Iterable, TypeVar from typing import Generic, List, Union, Iterable, Tuple, TypeVar
N = TypeVar("N") N = TypeVar("N")
Seq = Union[str, bytes, bytearray, memoryview] Seq = Union[str, bytes, bytearray, memoryview]
...@@ -54,6 +54,8 @@ class Hit(Generic[N]): ...@@ -54,6 +54,8 @@ class Hit(Generic[N]):
def __init__(self, name: N, identity: float, matches: int, fragments: int): ... def __init__(self, name: N, identity: float, matches: int, fragments: int): ...
def __repr__(self) -> str: ... def __repr__(self) -> str: ...
def __eq__(self, other: object) -> bool: ... def __eq__(self, other: object) -> bool: ...
def __getstate__(self) -> Tuple[N, float, int, int]: ...
def __setstate__(self, state: Tuple[N, float, int, int]) -> None: ...
@property @property
def name(self) -> N: ... def name(self) -> N: ...
@property @property
...@@ -68,6 +70,8 @@ class MinimizerInfo: ...@@ -68,6 +70,8 @@ class MinimizerInfo:
def __init__(self, hash: int, sequence_id: int, window_position: int): ... def __init__(self, hash: int, sequence_id: int, window_position: int): ...
def __repr__(self) -> str: ... def __repr__(self) -> str: ...
def __eq__(self, other: object) -> bool: ... def __eq__(self, other: object) -> bool: ...
def __getstate__(self) -> Tuple[int, int, int]: ...
def __setstate__(self, state: Tuple[int, int, int]) -> None: ...
@property @property
def hash(self) -> int: ... def hash(self) -> int: ...
@property @property
......
...@@ -900,6 +900,12 @@ cdef class Hit: ...@@ -900,6 +900,12 @@ cdef class Hit:
and self.identity == other.identity and self.identity == other.identity
) )
def __getstate__(self):
return self.name, self.matches, self.fragments, self.identity
def __setstate__(self, state):
self.name, self.matches, self.fragments, self.identity = state
cdef class MinimizerInfo: cdef class MinimizerInfo:
"""The information about a single minimizer. """The information about a single minimizer.
...@@ -936,6 +942,12 @@ cdef class MinimizerInfo: ...@@ -936,6 +942,12 @@ cdef class MinimizerInfo:
and self.window_position == other.window_position and self.window_position == other.window_position
) )
def __getstate__(self):
return self.hash, self.sequence_id, self.window_position
def __setstate__(self, state):
self.hash, self.sequence_id, self.window_position = state
# --- Methods ------------------------------------------------------------ # --- Methods ------------------------------------------------------------
@staticmethod @staticmethod
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment