Compare commits
No commits in common. "7384895578acc0a74e68b896978b70751ea2f827" and "2e8cdd8da917cede1dad1153f376f460d4fd98ef" have entirely different histories.
7384895578
...
2e8cdd8da9
@ -13,7 +13,6 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
description = "A library to rapidly fetch fetch MLST profiles given sequences for various diseases."
|
description = "A library to rapidly fetch fetch MLST profiles given sequences for various diseases."
|
||||||
license = {text = "GPL-3.0-or-later"}
|
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
Homepage = "https://github.com/Syph-and-VPD-Lab/autoBIGS.engine"
|
Homepage = "https://github.com/Syph-and-VPD-Lab/autoBIGS.engine"
|
||||||
|
@ -124,17 +124,13 @@ class RemoteBIGSdbMLSTProfiler(BIGSdbMLSTProfiler):
|
|||||||
|
|
||||||
async def profile_multiple_strings(self, query_named_string_groups: AsyncIterable[Iterable[NamedString]], stop_on_fail: bool = False) -> AsyncGenerator[NamedMLSTProfile, Any]:
|
async def profile_multiple_strings(self, query_named_string_groups: AsyncIterable[Iterable[NamedString]], stop_on_fail: bool = False) -> AsyncGenerator[NamedMLSTProfile, Any]:
|
||||||
async for named_strings in query_named_string_groups:
|
async for named_strings in query_named_string_groups:
|
||||||
names: list[str] = list()
|
|
||||||
sequences: list[str] = list()
|
|
||||||
for named_string in named_strings:
|
for named_string in named_strings:
|
||||||
names.append(named_string.name)
|
try:
|
||||||
sequences.append(named_string.sequence)
|
yield NamedMLSTProfile(named_string.name, (await self.profile_string([named_string.sequence])))
|
||||||
try:
|
except NoBIGSdbMatchesException as e:
|
||||||
yield NamedMLSTProfile("-".join(names), (await self.profile_string(sequences)))
|
if stop_on_fail:
|
||||||
except NoBIGSdbMatchesException as e:
|
raise e
|
||||||
if stop_on_fail:
|
yield NamedMLSTProfile(named_string.name, None)
|
||||||
raise e
|
|
||||||
yield NamedMLSTProfile("-".join(names), None)
|
|
||||||
|
|
||||||
async def close(self):
|
async def close(self):
|
||||||
await self._http_client.close()
|
await self._http_client.close()
|
||||||
|
@ -3,7 +3,7 @@ import csv
|
|||||||
from os import PathLike
|
from os import PathLike
|
||||||
from typing import AsyncIterable, Collection, Mapping, Sequence, Union
|
from typing import AsyncIterable, Collection, Mapping, Sequence, Union
|
||||||
|
|
||||||
from autobigs.engine.structures.mlst import Allele, MLSTProfile, NamedMLSTProfile
|
from autobigs.engine.structures.mlst import Allele, MLSTProfile
|
||||||
|
|
||||||
|
|
||||||
def alleles_to_text_map(alleles: Collection[Allele]) -> Mapping[str, Union[Sequence[str], str]]:
|
def alleles_to_text_map(alleles: Collection[Allele]) -> Mapping[str, Union[Sequence[str], str]]:
|
||||||
@ -17,14 +17,12 @@ def alleles_to_text_map(alleles: Collection[Allele]) -> Mapping[str, Union[Seque
|
|||||||
result[locus] = tuple(result[locus]) # type: ignore
|
result[locus] = tuple(result[locus]) # type: ignore
|
||||||
return dict(result)
|
return dict(result)
|
||||||
|
|
||||||
async def write_mlst_profiles_as_csv(mlst_profiles_iterable: AsyncIterable[NamedMLSTProfile], handle: Union[str, bytes, PathLike[str], PathLike[bytes]]) -> Sequence[str]:
|
async def write_mlst_profiles_as_csv(mlst_profiles_iterable: AsyncIterable[tuple[str, Union[MLSTProfile, None]]], handle: Union[str, bytes, PathLike[str], PathLike[bytes]]) -> Sequence[str]:
|
||||||
failed = list()
|
failed = list()
|
||||||
with open(handle, "w", newline='') as filehandle:
|
with open(handle, "w", newline='') as filehandle:
|
||||||
header = None
|
header = None
|
||||||
writer: Union[csv.DictWriter, None] = None
|
writer: Union[csv.DictWriter, None] = None
|
||||||
async for named_mlst_profile in mlst_profiles_iterable:
|
async for name, mlst_profile in mlst_profiles_iterable:
|
||||||
name = named_mlst_profile.name
|
|
||||||
mlst_profile = named_mlst_profile.mlst_profile
|
|
||||||
if mlst_profile is None:
|
if mlst_profile is None:
|
||||||
failed.append(name)
|
failed.append(name)
|
||||||
continue
|
continue
|
||||||
|
@ -3,7 +3,7 @@ from typing import AsyncIterable, Iterable
|
|||||||
import pytest
|
import pytest
|
||||||
from autobigs.engine.structures.alignment import AlignmentStats
|
from autobigs.engine.structures.alignment import AlignmentStats
|
||||||
from autobigs.engine.writing import alleles_to_text_map, write_mlst_profiles_as_csv
|
from autobigs.engine.writing import alleles_to_text_map, write_mlst_profiles_as_csv
|
||||||
from autobigs.engine.structures.mlst import Allele, MLSTProfile, NamedMLSTProfile
|
from autobigs.engine.structures.mlst import Allele, MLSTProfile
|
||||||
import tempfile
|
import tempfile
|
||||||
from csv import reader
|
from csv import reader
|
||||||
from os import path
|
from os import path
|
||||||
@ -11,20 +11,20 @@ from os import path
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def dummy_alphabet_mlst_profile():
|
def dummy_alphabet_mlst_profile():
|
||||||
return NamedMLSTProfile("name", MLSTProfile((
|
return MLSTProfile((
|
||||||
Allele("A", "1", None),
|
Allele("A", "1", None),
|
||||||
Allele("D", "1", None),
|
Allele("D", "1", None),
|
||||||
Allele("B", "1", None),
|
Allele("B", "1", None),
|
||||||
Allele("C", "1", None),
|
Allele("C", "1", None),
|
||||||
Allele("C", "2", AlignmentStats(90, 10, 0, 90))
|
Allele("C", "2", AlignmentStats(90, 10, 0, 90))
|
||||||
), "mysterious", "very mysterious"))
|
), "mysterious", "very mysterious")
|
||||||
|
|
||||||
async def iterable_to_asynciterable(iterable: Iterable):
|
async def iterable_to_asynciterable(iterable: Iterable):
|
||||||
for iterated in iterable:
|
for iterated in iterable:
|
||||||
yield iterated
|
yield iterated
|
||||||
|
|
||||||
async def test_column_order_is_same_as_expected_file(dummy_alphabet_mlst_profile: MLSTProfile):
|
async def test_column_order_is_same_as_expected_file(dummy_alphabet_mlst_profile: MLSTProfile):
|
||||||
dummy_profiles = [dummy_alphabet_mlst_profile]
|
dummy_profiles = [("test_1", dummy_alphabet_mlst_profile)]
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
output_path = path.join(temp_dir, "out.csv")
|
output_path = path.join(temp_dir, "out.csv")
|
||||||
await write_mlst_profiles_as_csv(iterable_to_asynciterable(dummy_profiles), output_path)
|
await write_mlst_profiles_as_csv(iterable_to_asynciterable(dummy_profiles), output_path)
|
||||||
@ -34,8 +34,8 @@ async def test_column_order_is_same_as_expected_file(dummy_alphabet_mlst_profile
|
|||||||
target_columns = lines[4:]
|
target_columns = lines[4:]
|
||||||
assert target_columns == sorted(target_columns)
|
assert target_columns == sorted(target_columns)
|
||||||
|
|
||||||
async def test_alleles_to_text_map_mapping_is_correct(dummy_alphabet_mlst_profile: NamedMLSTProfile):
|
async def test_alleles_to_text_map_mapping_is_correct(dummy_alphabet_mlst_profile: MLSTProfile):
|
||||||
mapping = alleles_to_text_map(dummy_alphabet_mlst_profile.mlst_profile.alleles) # type: ignore
|
mapping = alleles_to_text_map(dummy_alphabet_mlst_profile.alleles)
|
||||||
expected_mapping = {
|
expected_mapping = {
|
||||||
"A": "1",
|
"A": "1",
|
||||||
"B": "1",
|
"B": "1",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user