diff --git a/micall/core/contig_stitcher.py b/micall/core/contig_stitcher.py index bcbfa81ea..f7d87529a 100644 --- a/micall/core/contig_stitcher.py +++ b/micall/core/contig_stitcher.py @@ -212,7 +212,7 @@ def align_to_reference(contig) -> Iterable[GenotypedContig]: yield contig return - hits_array = [CigarHit(x.cigar, x.r_st, x.r_en - 1, x.q_st, x.q_en - 1) for x in alignments] + hits_array = [CigarHit(Cigar.coerce(x.cigar), x.r_st, x.r_en - 1, x.q_st, x.q_en - 1) for x in alignments] connected = connect_cigar_hits(hits_array) logger.info("Contig %r aligned in %s parts.", contig.name, len(connected), diff --git a/micall/utils/cigar_tools.py b/micall/utils/cigar_tools.py index 46dff9046..6aa516ffb 100644 --- a/micall/utils/cigar_tools.py +++ b/micall/utils/cigar_tools.py @@ -4,7 +4,7 @@ from math import ceil, floor import re -from typing import Container, Tuple, Iterable, Optional, Set, Dict, List +from typing import Container, Tuple, Iterable, Optional, Set, Dict, List, Union from dataclasses import dataclass from functools import cached_property, reduce from itertools import chain, dropwhile @@ -152,7 +152,7 @@ def __init__(self, data) -> None: @staticmethod - def coerce(obj): + def coerce(obj: Union['Cigar', str, Iterable[Tuple[int, CigarActions]]]): if isinstance(obj, Cigar): return obj @@ -437,7 +437,7 @@ def __str__(self): return ''.join('{}{}'.format(num, Cigar.operation_to_str(op)) for num, op in self._data) -@dataclass +@dataclass(frozen=True) class CigarHit: """ This class provides an abstraction over the complex details involved in working with sequence alignments @@ -461,8 +461,6 @@ class CigarHit: def __post_init__(self): - self.cigar = Cigar.coerce(self.cigar) - if self.ref_length != self.cigar.ref_length: raise ValueError(f"CIGAR string maps {self.cigar.ref_length}" f" reference positions, but CIGAR hit range is {self.ref_length}")