Skip to content

Commit

Permalink
Merge pull request #98 from biosimulators/lps-warning-consolidation-plus
Browse files Browse the repository at this point in the history
Fix for #96: consolidate warnings
  • Loading branch information
jonrkarr authored Feb 23, 2022
2 parents cb05ab5 + 9774c22 commit 4403922
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 50 deletions.
8 changes: 4 additions & 4 deletions biosimulators_utils/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def _default(self):
errors, warnings, _ = biosimulators_utils.sedml.validation.validate_model_with_language(filename, language, config=config)

if warnings:
msg = 'The model file `{}` may be invalid.\n {}'.format(
msg = 'The model file `{}` has warnings.\n {}'.format(
filename, flatten_nested_list_of_strings(warnings).replace('\n', '\n '))
warn(msg, BioSimulatorsWarning)

Expand Down Expand Up @@ -249,7 +249,7 @@ def _default(self):
raise

if reader.warnings:
msg = 'The SED-ML file `{}` may be invalid.\n {}'.format(
msg = 'The SED-ML file `{}` has warnings.\n {}'.format(
args.filename, flatten_nested_list_of_strings(reader.warnings).replace('\n', '\n '))
warn(msg, BioSimulatorsWarning)

Expand Down Expand Up @@ -289,7 +289,7 @@ def _default(self):
_, errors, warnings = biosimulators_utils.omex_meta.io.read_omex_meta_file(args.filename)

if warnings:
msg = 'The OMEX Metadata file `{}` may be invalid.\n {}'.format(
msg = 'The OMEX Metadata file `{}` has warnings.\n {}'.format(
args.filename, flatten_nested_list_of_strings(warnings).replace('\n', '\n '))
warn(msg, BioSimulatorsWarning)

Expand Down Expand Up @@ -345,7 +345,7 @@ def _default(self):
config=config,
)
if warnings:
msg = 'The COMBINE/OMEX archive may be invalid.\n {}'.format(
msg = 'The COMBINE/OMEX archive has warnings.\n {}'.format(
flatten_nested_list_of_strings(warnings).replace('\n', '\n '))
warn(msg, BioSimulatorsWarning)

Expand Down
2 changes: 1 addition & 1 deletion biosimulators_utils/combine/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def sed_doc_executer(doc, working_dir, base_out_path, rel_out_path=None,
# validate archive
errors, warnings = validate(archive, archive_tmp_dir, config=config)
if warnings:
msg = 'The COMBINE/OMEX archive may be invalid.\n {}'.format(
msg = 'The COMBINE/OMEX archive has warnings.\n {}'.format(
flatten_nested_list_of_strings(warnings).replace('\n', '\n '))
warn(msg, BioSimulatorsWarning)

Expand Down
6 changes: 3 additions & 3 deletions biosimulators_utils/combine/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def run(self, archive, in_dir, out_file):
self.warnings.extend(warnings)

if self.warnings:
warn('COMBINE/OMEX archive may be invalid.\n ' + flatten_nested_list_of_strings(self.warnings).replace('\n', '\n '),
warn('COMBINE/OMEX archive has warnings.\n ' + flatten_nested_list_of_strings(self.warnings).replace('\n', '\n '),
BioSimulatorsWarning)
if self.errors:
raise ValueError('COMBINE/OMEX archive is invalid.\n ' + flatten_nested_list_of_strings(self.errors).replace('\n', '\n '))
Expand All @@ -105,7 +105,7 @@ def write_manifest(self, contents, filename):

errors, warnings = get_combine_errors_warnings(manifest)
if warnings:
msg = 'COMBINE/OMEX archive may be invalid.\n ' + flatten_nested_list_of_strings(warnings).replace('\n', '\n ')
msg = 'COMBINE/OMEX archive has warnings.\n ' + flatten_nested_list_of_strings(warnings).replace('\n', '\n ')
warn(msg, BioSimulatorsWarning)
if errors:
msg = 'COMBINE/OMEX archive is invalid.\n ' + flatten_nested_list_of_strings(errors).replace('\n', '\n ')
Expand Down Expand Up @@ -237,7 +237,7 @@ def run(self, in_file, out_dir, include_omex_metadata_files=True, config=None):

# raise warnings and errors
if self.warnings:
warn('COMBINE/OMEX archive may be invalid.\n ' + flatten_nested_list_of_strings(self.warnings).replace('\n', '\n '),
warn('COMBINE/OMEX archive has warnings.\n ' + flatten_nested_list_of_strings(self.warnings).replace('\n', '\n '),
BioSimulatorsWarning)
if self.errors:
raise ValueError('`{}` is not a valid COMBINE/OMEX archive.\n {}'.format(
Expand Down
2 changes: 1 addition & 1 deletion biosimulators_utils/combine/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def validate_content(content, archive_dirname,
]]
if warnings:
warnings = [[
'The {} file at location `{}` may be invalid.'.format(file_type, content.location),
'The {} file at location `{}` has warnings.'.format(file_type, content.location),
warnings,
]]

Expand Down
25 changes: 23 additions & 2 deletions biosimulators_utils/model_lang/sbml/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,33 @@ def validate_model(filename, name=None, validate_consistency=True, config=None):
if validate_consistency:
doc.checkConsistency()

warning_map = {}
for i_error in range(doc.getNumErrors()):
sbml_error = doc.getError(i_error)
if sbml_error.isInfo() or sbml_error.isWarning():
warnings.append([sbml_error.getMessage()])
err_id = sbml_error.getErrorId()
if err_id not in warning_map:
warning_map[err_id] = [
0,
sbml_error.getCategoryAsString(),
sbml_error.getMessage().strip(),
sbml_error.getLine(),
sbml_error.getColumn(),
sbml_error.getSeverityAsString().lower(),
]
warning_map[err_id][0] += 1
else:
errors.append([sbml_error.getMessage()])
errors.append(['{} ({}) at line {}, column {}: {}'.format(
sbml_error.getCategoryAsString(), sbml_error.getErrorId(),
sbml_error.getLine(), sbml_error.getColumn(),
sbml_error.getMessage())
])
for err_id, (count, category, first_msg, line, column, severity) in warning_map.items():
warnings.append([
'{} {}{} of type {} ({}). The following is the first {} at line {}, column {}:'.format(
count, severity, 's' if count > 1 else '', category, err_id, severity, line, column),
[[first_msg]]
])

else:
errors.append(['`{}` is not a file.'.format(filename or '')])
Expand Down
4 changes: 2 additions & 2 deletions biosimulators_utils/omex_meta/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def run(self, filename_or_filenames, archive=None, working_dir=None, config=None

if temp_warnings:
if isinstance(filename_or_filenames, (tuple, list)):
warnings.append(['The OMEX Metadata file at location `{}` may be invalid.'.format(error_filename), temp_warnings])
warnings.append(['The OMEX Metadata file at location `{}` has warnings.'.format(error_filename), temp_warnings])
else:
warnings.extend(temp_warnings)

Expand Down Expand Up @@ -503,7 +503,7 @@ def run(self, filename_or_filenames, archive=None, working_dir=None, config=None

if temp_warnings:
if isinstance(filename_or_filenames, (tuple, list)):
warnings.append(['The OMEX Metadata file at location `{}` may be invalid.'.format(error_filename), temp_warnings])
warnings.append(['The OMEX Metadata file at location `{}` has warnings.'.format(error_filename), temp_warnings])
else:
warnings.extend(temp_warnings)

Expand Down
2 changes: 1 addition & 1 deletion biosimulators_utils/omex_meta/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def validate_biosimulations_metadata(metadata, archive=None, working_dir=None):

if temp_warnings:
el_uri = get_global_combine_archive_content_uri(el_metadata['uri'], el_metadata['combine_archive_uri'])
warnings.append(['The metadata for URI `{}` may be invalid.'.format(
warnings.append(['The metadata for URI `{}` has warnings.'.format(
el_uri), temp_warnings])

if not has_archive_metadata:
Expand Down
15 changes: 15 additions & 0 deletions biosimulators_utils/sedml/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,21 @@ def is_equal(self, other):
and self.language == other.language \
and are_lists_equal(self.changes, other.changes)

def has_structural_changes(self):
""" Check if there are structural model changes present.
* Add element
* Replace element
* Remove element
Returns:
:obj:`bool`: :obj:`True`, if structural model changes are present
"""
for change in self.changes:
if isinstance(change, (AddElementModelChange, ReplaceElementModelChange, RemoveElementModelChange)):
return True
return False


class ModelChange(SedBase, SedIdGroupMixin, TargetGroupMixin):
""" A change to a model
Expand Down
Loading

0 comments on commit 4403922

Please sign in to comment.