Skip to content

Commit 423481c

Browse files
committed
Merge branch 'model-msg' into 'dev'
Tweak some model choosing exception messages See merge request research/medaka!595
2 parents 60f96d7 + d90e821 commit 423481c

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

medaka/medaka.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __call__(self, parser, namespace, values, option_string=None):
3434
try:
3535
model_fp = medaka.models.resolve_model(val)
3636
except Exception as e:
37-
msg = "Error validating model from '--{}' argument: {}."
37+
msg = "Error validating model from '--{}' argument: {}"
3838
raise RuntimeError(msg.format(self.dest, str(e)))
3939
setattr(namespace, f"{self.dest}_was_given", True)
4040
setattr(namespace, self.dest, model_fp)
@@ -44,8 +44,9 @@ class AutoModel(argparse.Action):
4444
def __call__(self, parser, namespace, values, option_string=None):
4545
variant, input_file = values
4646
if variant not in {'consensus', 'variant', 'consensus_bacteria'}:
47-
raise ValueError("'TYPE' must be one of 'consensus', 'variant',"
48-
"or 'consensus_bacteria'.")
47+
raise ValueError(
48+
"'TYPE' must be one of 'consensus', 'variant',"
49+
"or 'consensus_bacteria'.")
4950
bacteria = 'bacteria' in variant
5051
variant = variant == 'variant'
5152
model = medaka.models.model_from_basecaller(
@@ -197,11 +198,11 @@ def _model_arg():
197198
formatter_class=argparse.ArgumentDefaultsHelpFormatter, add_help=False)
198199
grp = parser.add_mutually_exclusive_group()
199200
grp.add_argument('--model', action=ResolveModel,
200-
default=medaka.options.default_models['consensus'],
201-
help="Model to use. Can be a medaka model name or a basecaller model name suffixed with ':consensus' or ':variant'. For example '[email protected]:variant'.")
201+
default=medaka.options.default_models['consensus'],
202+
help="Model to use. Can be a medaka model name or a basecaller model name suffixed with ':consensus' or ':variant'. For example '[email protected]:variant'.")
202203
grp.add_argument('--auto_model', nargs=2, action=AutoModel,
203-
metavar=("TYPE", "INPUT"), dest='model',
204-
help="Automatically choose model according to INPUT. TYPE should be one of 'consensus' or 'variant'.")
204+
metavar=("TYPE", "INPUT"), dest='model',
205+
help="Automatically choose model according to INPUT. TYPE should be one of 'consensus' or 'variant'.")
205206
return parser
206207

207208

medaka/models.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,22 @@ def resolve_model(model):
5252
raise ex
5353
except Exception:
5454
logger.warning(err_msg)
55+
56+
extra_msg = ""
57+
if "fast" in model:
58+
extra_msg = (
59+
" 'fast' basecalling models are not supported by medaka, "
60+
"if you have used a 'fast' model to perform basecalling you "
61+
"will need to first perform basecalling with a "
62+
"'high accuracy' or 'super accuracy' model before using "
63+
"medaka.")
5564
raise ValueError(
56-
f"Model {model} is not a known model or existant file.")
65+
f"The model '{model}' is not a recognised basecaller model or "
66+
"existant file. This could indicate a malformed input file (for "
67+
"which medaka was unable to identify correctly the basecaller "
68+
"meta-information) or simply be that the model is not supported "
69+
f"by medaka.{extra_msg}")
70+
5771
else:
5872
# check for model in model stores
5973
for suffix in model_suffixes:
@@ -168,7 +182,7 @@ def model_from_basecaller(fname, variant=False, bacteria=False):
168182
# replace with bacterial consensus model if needed
169183
if bacteria and not variant:
170184
if model in medaka.options.bact_methyl_compatible_models:
171-
model = "r1041_e82_400bps_bacterial_methylation"
185+
model = medaka.options.bact_methyl_model
172186
else:
173187
logger.warning(
174188
"WARNING: --bacteria specified but input data was not "
@@ -210,7 +224,13 @@ def _model_from_fastq(fname):
210224
"basecall_model_version_id=")[1].split()[0]
211225
models.add(model)
212226
except Exception:
213-
pass
227+
try:
228+
# rogue non-spec conforming minknow versions
229+
model = rec.comment.split(
230+
"model_version_id=")[1].split()[0]
231+
models.add(model)
232+
except Exception:
233+
pass
214234
if len(models) > 1:
215235
# filter out any models without an `@`. These are likely FPs of
216236
# the search above (there are unversioned models whose name

medaka/options.py

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
'r1041_e82_400bps_bacterial_methylation',
166166
]
167167

168+
bact_methyl_model = 'r1041_e82_400bps_bacterial_methylation'
168169
bact_methyl_compatible_models = [
169170
'r1041_e82_400bps_hac_v4.2.0', 'r1041_e82_400bps_sup_v4.2.0',
170171
'r1041_e82_400bps_hac_v4.3.0', 'r1041_e82_400bps_sup_v4.3.0',

0 commit comments

Comments
 (0)