Skip to content

Commit

Permalink
Improve implementation of Alignment class
Browse files Browse the repository at this point in the history
  • Loading branch information
Donaim committed Oct 28, 2024
1 parent b512b96 commit 82260b1
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions micall/utils/alignment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Tuple, List, Sequence
from typing import Tuple, Sequence, Union, NoReturn
from dataclasses import dataclass

from aligntools import CigarActions, Cigar, CigarHit
Expand All @@ -23,14 +23,12 @@ class Alignment:
cigar_str: str

@staticmethod
def coerce(obj: object) -> 'Alignment':
def coerce(obj: Union['Alignment', mappy.Alignment]) -> 'Alignment':
if isinstance(obj, Alignment):
return obj
elif isinstance(obj, mappy.Alignment):
cigar: List[Tuple[int, CigarActions]] = []
for (size, action) in obj.cigar:
cigar.append((size, CigarActions(action)))

cigar = [(size, CigarActions(action))
for (size, action) in obj.cigar]
return Alignment(ctg=obj.ctg,
ctg_len=obj.ctg_len,
r_st=obj.r_st, r_en=obj.r_en,
Expand All @@ -41,6 +39,7 @@ def coerce(obj: object) -> 'Alignment':
cigar_str=obj.cigar_str,
)
else:
_: NoReturn = obj
raise TypeError(f"Cannot coerce from {obj!r}.")

def to_cigar_hit(self) -> CigarHit:
Expand Down

0 comments on commit 82260b1

Please sign in to comment.