hAMRonization 1.2.1__tar.gz → 1.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hamronization-1.2.1 → hamronization-1.3.1}/PKG-INFO +2 -2
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/Interfaces.py +33 -4
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/__init__.py +1 -1
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/hAMRonizedResult.py +46 -1
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization.egg-info/PKG-INFO +2 -2
- {hamronization-1.2.1 → hamronization-1.3.1}/test/test_parsing_validity.py +50 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/LICENSE.txt +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/README.md +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/AbricateIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/AmrFinderPlusIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/AmrPlusPlusIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/AribaIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/CSStarIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/DeepArgIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/FARGeneIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/GrootIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/KmerResistanceIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/MykrobeIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/ResFamsIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/ResFinderIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/RgiIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/SraxIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/Srst2IO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/StarAmrIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/TBProfilerIO.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/constants.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/hamronize.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization/summarize.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization.egg-info/SOURCES.txt +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization.egg-info/dependency_links.txt +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization.egg-info/entry_points.txt +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization.egg-info/requires.txt +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization.egg-info/top_level.txt +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/hAMRonization.egg-info/zip-safe +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/setup.cfg +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/setup.py +0 -0
- {hamronization-1.2.1 → hamronization-1.3.1}/test/test_interfaces.py +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hAMRonization
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.1
|
|
4
4
|
Summary: Tool to convert and summarize AMR gene detection outputs using the hAMRonization specification
|
|
5
5
|
Home-page: https://github.com/pha4ge/hAMRonization
|
|
6
|
-
Download-URL: https://github.com/pha4ge/archive/v1.
|
|
6
|
+
Download-URL: https://github.com/pha4ge/archive/v1.3.1.tar.gz
|
|
7
7
|
Author: Finlay Maguire
|
|
8
8
|
Author-email: finlaymaguire@gmail.com
|
|
9
9
|
License: LGPLv3
|
|
@@ -5,12 +5,16 @@ import os
|
|
|
5
5
|
import csv
|
|
6
6
|
import json
|
|
7
7
|
import argparse
|
|
8
|
+
import logging
|
|
9
|
+
import traceback
|
|
8
10
|
import dataclasses
|
|
9
11
|
from abc import ABC, abstractmethod
|
|
10
12
|
import hAMRonization
|
|
11
13
|
import hAMRonization.summarize
|
|
12
14
|
from .hAMRonizedResult import hAMRonizedResult
|
|
13
15
|
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
|
|
14
18
|
|
|
15
19
|
class hAMRonizedResultIterator(ABC):
|
|
16
20
|
"""
|
|
@@ -39,16 +43,27 @@ class hAMRonizedResultIterator(ABC):
|
|
|
39
43
|
|
|
40
44
|
try:
|
|
41
45
|
if os.stat(source).st_size == 0:
|
|
42
|
-
|
|
46
|
+
logger.warning("Input file %s is empty", source)
|
|
43
47
|
self.stream = open(source, "r")
|
|
44
|
-
except FileNotFoundError:
|
|
45
|
-
|
|
46
|
-
exit(1)
|
|
48
|
+
except FileNotFoundError:
|
|
49
|
+
logger.error("File not found: %s", source)
|
|
50
|
+
sys.exit(1)
|
|
47
51
|
|
|
48
52
|
try:
|
|
49
53
|
self.hAMRonized_results = self.parse(self.stream)
|
|
54
|
+
except KeyError as e:
|
|
55
|
+
self.stream.close()
|
|
56
|
+
logger.error(
|
|
57
|
+
"Expected column %s not found in %s. "
|
|
58
|
+
"Please check you are using the correct AMR "
|
|
59
|
+
"prediction tool output file.",
|
|
60
|
+
e, source
|
|
61
|
+
)
|
|
62
|
+
logger.debug("Full traceback:\n%s", traceback.format_exc())
|
|
63
|
+
sys.exit(1)
|
|
50
64
|
except Exception:
|
|
51
65
|
self.stream.close()
|
|
66
|
+
raise
|
|
52
67
|
|
|
53
68
|
# TODO: the field_map_override is a half-hack to support the scenario
|
|
54
69
|
# (as for amrfinderplus) where different records need different mappings,
|
|
@@ -242,6 +257,13 @@ def generic_cli_interface():
|
|
|
242
257
|
version=f"%(prog)s {hAMRonization.__version__}",
|
|
243
258
|
)
|
|
244
259
|
|
|
260
|
+
parser.add_argument(
|
|
261
|
+
"--debug",
|
|
262
|
+
action="store_true",
|
|
263
|
+
default=False,
|
|
264
|
+
help="Enable debug mode with full tracebacks",
|
|
265
|
+
)
|
|
266
|
+
|
|
245
267
|
# add tool specific parsers
|
|
246
268
|
subparser = parser.add_subparsers(
|
|
247
269
|
title="Tools with hAMRonizable reports", help="", dest="analysis_tool"
|
|
@@ -280,6 +302,13 @@ def generic_cli_interface():
|
|
|
280
302
|
|
|
281
303
|
args = parser.parse_args()
|
|
282
304
|
|
|
305
|
+
if args.debug:
|
|
306
|
+
logging.basicConfig(level=logging.DEBUG,
|
|
307
|
+
format="%(levelname)s:%(name)s:%(message)s")
|
|
308
|
+
else:
|
|
309
|
+
logging.basicConfig(level=logging.WARNING,
|
|
310
|
+
format="%(levelname)s: %(message)s")
|
|
311
|
+
|
|
283
312
|
if args.analysis_tool and args.analysis_tool != "summarize":
|
|
284
313
|
required_mandatory_metadata = hAMRonization._RequiredToolMetadata[
|
|
285
314
|
args.analysis_tool
|
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
|
+
import logging
|
|
4
5
|
import dataclasses
|
|
5
6
|
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
# Fields where upstream tools may report multiple semicolon-separated values
|
|
10
|
+
# or dash-separated ranges instead of a single number (e.g., RGI-bwt).
|
|
11
|
+
# For these fields we extract the first numeric value rather than failing.
|
|
12
|
+
_MULTI_VALUE_NUMERIC_FIELDS = {
|
|
13
|
+
"reference_gene_length",
|
|
14
|
+
"sequence_identity",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _extract_first_numeric(value, target_type):
|
|
19
|
+
"""
|
|
20
|
+
Given a string that may contain semicolon-separated values
|
|
21
|
+
(e.g., '3561; 3564; 3570') or dash-separated ranges
|
|
22
|
+
(e.g., '92.82 - 100.0'), extract and return the first numeric
|
|
23
|
+
value cast to target_type.
|
|
24
|
+
"""
|
|
25
|
+
raw = str(value).strip()
|
|
26
|
+
for sep in [";", " - ", "-"]:
|
|
27
|
+
if sep in raw:
|
|
28
|
+
first = raw.split(sep)[0].strip()
|
|
29
|
+
if first:
|
|
30
|
+
return target_type(first)
|
|
31
|
+
return target_type(raw)
|
|
32
|
+
|
|
6
33
|
|
|
7
34
|
@dataclasses.dataclass
|
|
8
35
|
class hAMRonizedResult:
|
|
@@ -64,7 +91,25 @@ class hAMRonizedResult:
|
|
|
64
91
|
if not isinstance(value, field.type) and value:
|
|
65
92
|
try:
|
|
66
93
|
setattr(self, field.name, field.type(value))
|
|
67
|
-
except ValueError:
|
|
94
|
+
except (ValueError, TypeError):
|
|
95
|
+
if field.name in _MULTI_VALUE_NUMERIC_FIELDS:
|
|
96
|
+
try:
|
|
97
|
+
extracted = _extract_first_numeric(
|
|
98
|
+
value, field.type
|
|
99
|
+
)
|
|
100
|
+
setattr(self, field.name, extracted)
|
|
101
|
+
logger.debug(
|
|
102
|
+
"Field '%s' contained multiple values "
|
|
103
|
+
"(%r), extracted first: %s",
|
|
104
|
+
field.name, value, extracted
|
|
105
|
+
)
|
|
106
|
+
continue
|
|
107
|
+
except (ValueError, TypeError):
|
|
108
|
+
pass
|
|
109
|
+
logger.error(
|
|
110
|
+
"Expected %s to be %s, got %r",
|
|
111
|
+
field.name, field.type, value
|
|
112
|
+
)
|
|
68
113
|
raise ValueError(
|
|
69
114
|
f"Expected {field.name} "
|
|
70
115
|
f"to be {field.type}, "
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hAMRonization
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.1
|
|
4
4
|
Summary: Tool to convert and summarize AMR gene detection outputs using the hAMRonization specification
|
|
5
5
|
Home-page: https://github.com/pha4ge/hAMRonization
|
|
6
|
-
Download-URL: https://github.com/pha4ge/archive/v1.
|
|
6
|
+
Download-URL: https://github.com/pha4ge/archive/v1.3.1.tar.gz
|
|
7
7
|
Author: Finlay Maguire
|
|
8
8
|
Author-email: finlaymaguire@gmail.com
|
|
9
9
|
License: LGPLv3
|
|
@@ -992,3 +992,53 @@ def test_fargene():
|
|
|
992
992
|
assert result.input_protein_start == 7
|
|
993
993
|
assert result.input_protein_stop == 118
|
|
994
994
|
assert result.input_protein_length == 140
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
def test_rgi_bwt_multi_value_fields():
|
|
998
|
+
"""Test that RGI-bwt output with multi-value reference_gene_length
|
|
999
|
+
and range-style sequence_identity is parsed correctly (issue #84)."""
|
|
1000
|
+
metadata = {
|
|
1001
|
+
"analysis_software_version": "6.0.1",
|
|
1002
|
+
"reference_database_version": "3.2.8",
|
|
1003
|
+
"input_file_name": "rgi_bwt_test",
|
|
1004
|
+
}
|
|
1005
|
+
parsed_report = hAMRonization.parse(
|
|
1006
|
+
"data/dummy/rgi/rgi_bwt.txt", metadata, "rgi"
|
|
1007
|
+
)
|
|
1008
|
+
|
|
1009
|
+
for result in parsed_report:
|
|
1010
|
+
assert result.input_file_name == "rgi_bwt_test"
|
|
1011
|
+
assert result.gene_symbol == (
|
|
1012
|
+
"Bifidobacterium adolescentis rpoB mutants conferring "
|
|
1013
|
+
"resistance to rifampicin"
|
|
1014
|
+
)
|
|
1015
|
+
assert result.reference_accession == "3004480"
|
|
1016
|
+
assert result.analysis_software_name == "rgi"
|
|
1017
|
+
assert result.reference_database_name == "CARD; Resistomes & Variants"
|
|
1018
|
+
|
|
1019
|
+
# issue #84: these fields contain multi-values in RGI-bwt output
|
|
1020
|
+
# reference_gene_length '3561; 3561; 3564; 3570' -> first value 3561
|
|
1021
|
+
assert result.reference_gene_length == 3561
|
|
1022
|
+
assert isinstance(result.reference_gene_length, int)
|
|
1023
|
+
|
|
1024
|
+
# sequence_identity '92.82 - 100.0' -> first value 92.82
|
|
1025
|
+
assert result.sequence_identity == 92.82
|
|
1026
|
+
assert isinstance(result.sequence_identity, float)
|
|
1027
|
+
|
|
1028
|
+
assert result.coverage_percentage == 34.84
|
|
1029
|
+
assert result.input_gene_length == 1249
|
|
1030
|
+
assert result.drug_class == "rifamycin antibiotic"
|
|
1031
|
+
assert result.resistance_mechanism == (
|
|
1032
|
+
"antibiotic target alteration; antibiotic target replacement"
|
|
1033
|
+
)
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
def test_extract_first_numeric():
|
|
1037
|
+
"""Unit test for the multi-value numeric field parser."""
|
|
1038
|
+
from hAMRonization.hAMRonizedResult import _extract_first_numeric
|
|
1039
|
+
|
|
1040
|
+
assert _extract_first_numeric("3561; 3564; 3570", int) == 3561
|
|
1041
|
+
assert _extract_first_numeric("92.82 - 100.0", float) == 92.82
|
|
1042
|
+
assert _extract_first_numeric("42", int) == 42
|
|
1043
|
+
assert _extract_first_numeric("99.5", float) == 99.5
|
|
1044
|
+
assert _extract_first_numeric("100; 200", int) == 100
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|