Skip to content

Commit 4138cc3

Browse files
committed
address code review
1 parent 262fd85 commit 4138cc3

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

microSALT/utils/referencer/utils.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,35 @@ def get_species(organism_name: str) -> str:
1111
return organism_name.lower().split()[-1]
1212

1313

14-
def is_escherichia(species_name: str) -> bool:
14+
def get_genus(organism_name: str) -> str:
15+
"""Returns the genus of the organism name."""
16+
return organism_name.lower().split()[0]
17+
18+
19+
def is_escherichia(species_name) -> bool:
1520
"""Checks if the organism name is a proper Escherichia."""
1621
return any(species_name == member.value for member in Escherichia)
1722

1823

19-
def is_klebsiella(species_name: str) -> bool:
24+
def is_klebsiella(species_name) -> bool:
2025
"""Checks if the organism name is a proper Klebsiella."""
2126
return any(species_name == member.value for member in Klebsiella)
2227

2328

2429
def get_reference_if_enterobacteriaceae(organism_name: str) -> str:
2530
"""Returns the reference for the organism name if it belongs to Enterobacteriaceae."""
26-
species: str = get_species(organism_name)
2731
GENUS_REFERENCE_MAP = {
2832
"escherichia": (is_escherichia, ESCHERICHIA_REFERENCE),
2933
"klebsiella": (is_klebsiella, KLEBSIELLA_REFERENCE),
3034
}
31-
return next(
32-
(
33-
reference
34-
for check_func, reference in GENUS_REFERENCE_MAP.values()
35-
if check_func(species_name=species)
36-
),
37-
organism_name,
38-
)
35+
36+
species: str = get_species(organism_name)
37+
genus = get_genus(organism_name)
38+
39+
is_species, reference = GENUS_REFERENCE_MAP.get(
40+
genus, (None, None)
41+
) # if the genus is not in the map, return None, None
42+
43+
return (
44+
reference if is_species(species_name=species) else organism_name
45+
) # if the species is not in the species for the genus, return the organism name

0 commit comments

Comments
 (0)