Skip to content

Commit

Permalink
Fix scoring in referenceless
Browse files Browse the repository at this point in the history
  • Loading branch information
Donaim committed Jan 10, 2025
1 parent 4ea1fd5 commit a159da1
Showing 1 changed file with 17 additions and 32 deletions.
49 changes: 17 additions & 32 deletions micall/utils/referenceless_contig_stitcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,46 +56,28 @@ def combine(self, prob: Fraction) -> 'Score':
)

@staticmethod
def initial() -> 'Score':
return Score(pessimisstic_probability=ACCEPTABLE_STITCHING_PROB,
def lowest() -> 'Score':
return Score(pessimisstic_probability=Fraction(1),
overall_probability=Fraction(1),
path_lenth=0)

@property
def characteristic(self) -> Tuple[Fraction, Fraction, int]:
return ((1 - self.pessimisstic_probability),
(1 - self.overall_probability),
self.path_lenth)

def __lt__(self, other: 'Score') -> bool:
if (1 - self.pessimisstic_probability) < (1 - other.pessimisstic_probability):
return True
if (1 - self.overall_probability) < (1 - other.overall_probability):
return True
if self.path_lenth < other.path_lenth:
return True
return False
return self.characteristic < other.characteristic

def __le__(self, other: 'Score') -> bool:
if (1 - self.pessimisstic_probability) <= (1 - other.pessimisstic_probability):
return True
if (1 - self.overall_probability) <= (1 - other.overall_probability):
return True
if self.path_lenth <= other.path_lenth:
return True
return False
return self.characteristic <= other.characteristic

def __gt__(self, other: 'Score') -> bool:
if (1 - self.pessimisstic_probability) > (1 - other.pessimisstic_probability):
return True
if (1 - self.overall_probability) > (1 - other.overall_probability):
return True
if self.path_lenth > other.path_lenth:
return True
return False
return self.characteristic > other.characteristic

def __ge__(self, other: 'Score') -> bool:
if (1 - self.pessimisstic_probability) >= (1 - other.pessimisstic_probability):
return True
if (1 - self.overall_probability) >= (1 - other.overall_probability):
return True
if self.path_lenth >= other.path_lenth:
return True
return False
return self.characteristic >= other.characteristic


@dataclass(frozen=True)
Expand All @@ -115,7 +97,7 @@ def is_empty(self) -> bool:

@staticmethod
def empty() -> 'ContigsPath':
return ContigsPath(ContigWithAligner.empty(), frozenset(), Score.initial())
return ContigsPath(ContigWithAligner.empty(), frozenset(), Score.lowest())


@dataclass
Expand Down Expand Up @@ -320,7 +302,10 @@ def filter_extensions(existing: MutableMapping[str, ContigsPath],


def calculate_all_paths(contigs: Sequence[ContigWithAligner]) -> Iterator[ContigsPath]:
min_acceptable_score = MinimumAcceptableScore(Score.initial())
min_acceptable_score = MinimumAcceptableScore(Score(pessimisstic_probability=ACCEPTABLE_STITCHING_PROB,
overall_probability=ACCEPTABLE_STITCHING_PROB,
path_lenth=1,
))
existing: MutableMapping[str, ContigsPath] = {}
finder = OverlapFinder.make('ACTG')
extensions = calc_extension(finder, min_acceptable_score, contigs, ContigsPath.empty())
Expand Down

0 comments on commit a159da1

Please sign in to comment.