From 85946eb110dbad295bc9ea43c2063fa335f13238 Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Thu, 6 Feb 2025 17:12:31 +0000 Subject: [PATCH] Fixed match metric difference between remote and local --- src/autobigs/engine/analysis/aligners.py | 4 ++-- src/autobigs/engine/analysis/bigsdb.py | 8 ++++---- src/autobigs/engine/structures/alignment.py | 2 +- tests/autobigs/engine/analysis/test_aligners.py | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/autobigs/engine/analysis/aligners.py b/src/autobigs/engine/analysis/aligners.py index 062be2b..85b9b9f 100644 --- a/src/autobigs/engine/analysis/aligners.py +++ b/src/autobigs/engine/analysis/aligners.py @@ -8,7 +8,7 @@ from queue import Queue from autobigs.engine.structures.alignment import AlignmentStats, PairwiseAlignment -class AsyncPairwiseAlignmentEngine(AbstractContextManager): +class AsyncBiopythonPairwiseAlignmentEngine(AbstractContextManager): def __enter__(self): self._thread_pool = ThreadPoolExecutor(self._max_threads, thread_name_prefix="async-pairwise-alignment") return self @@ -46,7 +46,7 @@ class AsyncPairwiseAlignmentEngine(AbstractContextManager): percent_identity=top_alignment_identities/top_alignment.length, mismatches=top_alignment_mismatches, gaps=top_alignment_gaps, - score=top_alignment_score + match_metric=top_alignment_score )), associated_data async def next_completed(self) -> Union[tuple[PairwiseAlignment, dict[str, Any]], None]: diff --git a/src/autobigs/engine/analysis/bigsdb.py b/src/autobigs/engine/analysis/bigsdb.py index 1f7954d..0685da2 100644 --- a/src/autobigs/engine/analysis/bigsdb.py +++ b/src/autobigs/engine/analysis/bigsdb.py @@ -11,7 +11,7 @@ from typing import Any, AsyncGenerator, AsyncIterable, Iterable, Mapping, Sequen from aiohttp import ClientSession, ClientTimeout -from autobigs.engine.analysis.aligners import AsyncPairwiseAlignmentEngine +from autobigs.engine.analysis.aligners import AsyncBiopythonPairwiseAlignmentEngine from autobigs.engine.reading import read_fasta from autobigs.engine.structures.alignment import PairwiseAlignment from autobigs.engine.structures.genomics import NamedString @@ -82,7 +82,7 @@ class RemoteBIGSdbMLSTProfiler(BIGSdbMLSTProfiler): percent_identity=float(partial_match["identity"]), mismatches=int(partial_match["mismatches"]), gaps=int(partial_match["gaps"]), - score=int(partial_match["score"]) + match_metric=int(partial_match["bitscore"]) ) yield Allele( allele_locus=allele_loci, @@ -209,7 +209,7 @@ class LocalBIGSdbMLSTProfiler(BIGSdbMLSTProfiler): async def determine_mlst_allele_variants(self, query_sequence_strings: Iterable[str]) -> AsyncGenerator[Allele, Any]: aligner = PairwiseAligner("blastn") aligner.mode = "local" - with AsyncPairwiseAlignmentEngine(aligner, max_threads=2) as aligner_engine: + with AsyncBiopythonPairwiseAlignmentEngine(aligner, max_threads=4) as aligner_engine: for query_sequence_string in query_sequence_strings: for locus in self._loci: async for allele_variant in read_fasta(self.get_locus_cache_path(locus)): @@ -235,7 +235,7 @@ class LocalBIGSdbMLSTProfiler(BIGSdbMLSTProfiler): else: alignment_rankings[result_locus].add((alignment_result, variant_id)) for final_locus, alignments in alignment_rankings.items(): - closest_alignment, closest_variant_id = sorted(alignments, key=lambda index: index[0].alignment_stats.score)[0] + closest_alignment, closest_variant_id = sorted(alignments, key=lambda index: index[0].alignment_stats.match_metric)[0] yield Allele(final_locus, closest_variant_id, closest_alignment.alignment_stats) async def determine_mlst_st(self, alleles): diff --git a/src/autobigs/engine/structures/alignment.py b/src/autobigs/engine/structures/alignment.py index c40b857..d42e63c 100644 --- a/src/autobigs/engine/structures/alignment.py +++ b/src/autobigs/engine/structures/alignment.py @@ -7,7 +7,7 @@ class AlignmentStats: percent_identity: float mismatches: int gaps: int - score: int + match_metric: int @dataclass(frozen=True) class PairwiseAlignment: diff --git a/tests/autobigs/engine/analysis/test_aligners.py b/tests/autobigs/engine/analysis/test_aligners.py index 1450814..159dfa5 100644 --- a/tests/autobigs/engine/analysis/test_aligners.py +++ b/tests/autobigs/engine/analysis/test_aligners.py @@ -2,7 +2,7 @@ from Bio import SeqIO from Bio.Align import PairwiseAligner from pytest import mark from pytest import fixture -from autobigs.engine.analysis.aligners import AsyncPairwiseAlignmentEngine +from autobigs.engine.analysis.aligners import AsyncBiopythonPairwiseAlignmentEngine from autobigs.engine.structures.alignment import PairwiseAlignment @fixture @@ -17,11 +17,11 @@ def tohamaI_bpertussis_genome(): def dummy_engine(request): aligner = PairwiseAligner("blastn") aligner.mode = "local" - with AsyncPairwiseAlignmentEngine(aligner, request.param) as engine: + with AsyncBiopythonPairwiseAlignmentEngine(aligner, request.param) as engine: yield engine class TestAsyncPairwiseAlignmentEngine: - async def test_single_alignment_no_errors(self, tohamaI_bpertussis_genome, tohamaI_bpertussis_adk: str, dummy_engine: AsyncPairwiseAlignmentEngine): + async def test_single_alignment_no_errors(self, tohamaI_bpertussis_genome, tohamaI_bpertussis_adk: str, dummy_engine: AsyncBiopythonPairwiseAlignmentEngine): dummy_engine.align(tohamaI_bpertussis_genome, tohamaI_bpertussis_adk) async for alignment, additional_information in dummy_engine: assert isinstance(alignment, PairwiseAlignment) \ No newline at end of file