@@ -0,0 +1,2599 @@
+# -*- coding: utf-8 -*-%0A%0A# Copyright 2019 Novo Nordisk Foundation Center for Biosustainability,%0A# Technical University of Denmark.%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22);%0A# you may not use this file except in compliance with the License.%0A# You may obtain a copy of the License at%0A#%0A#     http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS,%0A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A# See the License for the specific language governing permissions and%0A# limitations under the License.%0A%0A%22%22%22Structurally validate SBML-formatted file input.%22%22%22%0A%0Afrom libsbml import SBMLValidator%0Afrom cobra.io.sbml3 import read_sbml_model%0Afrom warnings import catch_warnings, simplefilter%0A%0A%0Adef run_libsbml_validation(filename, notifications):%0A    %22%22%22Reports errors and warnings from validation with libSBML Python API.%22%22%22%0A    validator = SBMLValidator()%0A    validator.validate(str(filename))%0A%0A    # Could be relevant later on.%0A    # doc = validator.getDocument()%0A    # latest_level = (str(doc.getLevel()) != %223%22 or str(%0A    #     doc.getVersion()) != %221%22 or doc.getPlugin('fbc') == None)%0A%0A    warnings = %5B%5D%0A    errors = %5B%5D%0A    display_pattern = %22Line %7B%7D, Column %7B%7D - #%7B%7D: %7B%7D - %22 %5C%0A                      %22Category: %7B%7D, Severity: %7B%7D%22%0A    for i in range(validator.getNumFailures()):%0A        failure = validator.getFailure(i)%0A        if failure.isWarning():%0A            warnings.append(display_pattern.format(%0A                failure.getLine(),%0A                failure.getColumn(),%0A                failure.getErrorId(),%0A                failure.getMessage(),%0A                failure.getCategoryAsString(),%0A                failure.getSeverity()))%0A        else:%0A            errors.append(display_pattern.format(%0A                failure.getLine(),%0A                failure.getColumn(),%0A                failure.getErrorId(),%0A                failure.getMessage(),%0A                failure.getCategoryAsString(),%0A                failure.getSeverity()))%0A        return errors, warnings#, latest_level%0A%0A%0Adef run_cobrapy_validation(filename, notifications):%0A    %22%22%22Reports errors and warnings from validation with cobrapy.%22%22%22%0A    with catch_warnings(record=True) as warnings:%0A        simplefilter(%22always%22)%0A        model = None%0A        try:%0A            model = read_sbml_model(filename)%0A        except Exception as e:%0A            notifications%5B'errors'%5D.append(str(e))%0A        notifications%5B'warnings'%5D.extend(warnings)%0A        return model%0A%0A

add validation.py module.