Skip to content

Commit

Permalink
fix: matlab loading and sbml validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mihai-sysbio committed Oct 27, 2023
1 parent c7150f7 commit 293653d
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 58 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
container:
image: ghcr.io/metabolicatlas/memote-docker:0.13
volumes:
- /Users/petre/standard-gem-validation/crap:/project:rw
- ${{ github.workspace }}:/project:rw
options: --user root --workdir /project
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
Expand All @@ -29,14 +29,14 @@ jobs:
git config --global --add safe.directory /__w/standard-GEM-validation/standard-GEM-validation
python -c 'import runner; runner.matrix()'
# - name: Commit index of standard-GEMs
# uses: stefanzweifel/git-auto-commit-action@v5
# with:
# commit_user_name: validation-bot
# commit_message: update index of standard-GEMs
# file_pattern: index.json
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit index of standard-GEMs
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_user_name: validation-bot
commit_message: update index of standard-GEMs
file_pattern: index.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Define job matrix from index
id: set-matrix
Expand All @@ -48,7 +48,7 @@ jobs:
container:
image: ghcr.io/metabolicatlas/memote-docker:0.13
volumes:
- /Users/petre/standard-gem-validation/crap:/project:rw
- ${{ github.workspace }}:/project:rw
options: --user root --workdir /project
continue-on-error: true
env:
Expand All @@ -70,14 +70,14 @@ jobs:
git config --global --add safe.directory /__w/standard-GEM-validation/standard-GEM-validation
python -c 'import runner; runner.validate("${{ matrix.gem }}")'
# - name: Update branch
# run: git pull --ff
- name: Update branch
run: git pull --ff

# - name: Auto-commit results
# uses: stefanzweifel/git-auto-commit-action@v5
# with:
# commit_user_name: validation-bot
# commit_message: update validation results for ${{ matrix.gem }}
# file_pattern: results/*.json
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Auto-commit results
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_user_name: validation-bot
commit_message: update validation results for ${{ matrix.gem }}
file_pattern: results/*.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24 changes: 12 additions & 12 deletions runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
MODEL_FILENAME = 'model'
MODEL_FORMATS = ['.yml', '.xml', '.mat', '.json']
RELEASES = 5
TEST_RESULTS = {}

header_auth = {'Authorization': 'token %s' % API_TOKEN}
# additional_branch_tags = []
Expand Down Expand Up @@ -56,7 +55,7 @@ def releases(nameWithOwner):
release_tags = list(map(lambda x: x['node']['tagName'], json_data))
if not release_tags:
return []
return release_tags + additional_branch_tags
return additional_branch_tags + release_tags

def matrix():
m = json.dumps(list(gem_repositories()))
Expand All @@ -80,24 +79,25 @@ def validate(nameWithOwner):
for model_release in releases(nameWithOwner):
release_data = {}
standard_gem_releases = releases('MetabolicAtlas/standard-GEM')
last_standard = standard_gem_releases[len(standard_gem_releases)-3:-2]
last_standard = standard_gem_releases[len(standard_gem_releases)-1:]
for standard_version in last_standard:
print("{}: {} | standard-GEM version: {}".format(nameWithOwner, model_release, standard_version))
gem_is_standard = gem_follows_standard(nameWithOwner, model_release, standard_version)
test_results = {}
if gem_is_standard:
for model_format in MODEL_FORMATS:
my_model = model + model_format
response = requests.get('https://raw.githubusercontent.com/{}/{}/model/{}'.format(nameWithOwner, model_release, my_model), timeout=10)
if response.ok:
with open(my_model, 'w') as file:
file.write(response.text)
resultJSONString(tests.yaml.validate, model)
resultJSONString(tests.cobra.loadYaml, model)
resultJSONString(tests.cobra.loadSbml, model)
resultJSONString(tests.cobra.loadMatlab, model)
resultJSONString(tests.cobra.loadJson, model)
resultJSONString(tests.cobra.validateSbml, model)
resultJSONString(tests.memote.scoreAnnotationAndConsistency, model)
test_results.update(resultJSONString(tests.cobra.loadYaml, model))
test_results.update(resultJSONString(tests.cobra.loadSbml, model))
test_results.update(resultJSONString(tests.cobra.loadMatlab, model))
test_results.update(resultJSONString(tests.cobra.loadJson, model))
test_results.update(resultJSONString(tests.cobra.validateSbml, model))
test_results.update(resultJSONString(tests.yaml.validate, model))
test_results.update(resultJSONString(tests.memote.scoreAnnotationAndConsistency, model))
else:
print('is not following standard')
release_data = { 'standard-GEM' : [ { standard_version : gem_is_standard }, { 'test_results' : test_results} ] }
Expand All @@ -106,5 +106,5 @@ def validate(nameWithOwner):
output.write(json.dumps(data, indent=2, sort_keys=True))

def resultJSONString(testToRun, model):
testModule, moduleVersion, status, errors = testToRun(model)
TEST_RESULTS.update({testModule: { moduleVersion : status, 'errors': errors[:300] } })
testModule, description, moduleVersion, status, errors = testToRun(model)
return {testModule: { 'description': description, 'version': moduleVersion, 'status': status, 'errors': errors[:300] } }
54 changes: 32 additions & 22 deletions tests/cobra.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,83 @@
import cobra
import json
from pathlib import Path

def loadYaml(model_name):
print('load yaml')
is_valid = False
description = 'Check if the model in YAML can be loaded with cobrapy.'
print(description)
status = False
errors = ''
try:
cobra.io.load_yaml_model(model_name + '.yml')
is_valid = True
status = True
except FileNotFoundError:
errors = "File missing"
except Exception as e:
errors = json.dumps(str(e))
print(e)
return 'cobrapy-load-yaml', cobra.__version__, is_valid, errors
return 'cobrapy-load-yaml', description, cobra.__version__, status, errors

def loadSbml(model_name):
print('load sbml')
is_valid = False
description = 'Check if the model in SBML format can be loaded with cobrapy.'
print(description)
status = False
errors = ''
try:
cobra.io.read_sbml_model(model_name + '.xml')
is_valid = True
status = True
except FileNotFoundError:
errors = "File missing"
except Exception as e:
errors = json.dumps(str(e))
print(e)
return 'cobrapy-load-sbml', cobra.__version__, is_valid, errors
return 'cobrapy-load-sbml', description, cobra.__version__, status, errors

def loadMatlab(model_name):
print('load matlab')
is_valid = False
description = 'Check if the model in Matlab format can be loaded with cobrapy.'
print(description)
status = False
errors = ''
try:
cobra.io.load_matlab_model(model_name + '.mat')
is_valid = True
data_dir = Path(".") / ".."
data_dir = data_dir.resolve()
model_path = data_dir / "{}.mat".format(model_name)
cobra.io.load_matlab_model(str(model_path.resolve()))
status = True
except FileNotFoundError:
errors = "File missing"
except Exception as e:
errors = json.dumps(str(e))
print(e)
return 'cobrapy-load-matlab', cobra.__version__, is_valid, errors
return 'cobrapy-load-matlab', description, cobra.__version__, status, errors

def loadJson(model_name):
print('load json')
is_valid = False
description = 'Check if the model in JSON format can be loaded with cobrapy.'
print(description)
status = False
errors = ''
try:
cobra.io.load_json_model(model_name + '.json')
is_valid = True
status = True
except FileNotFoundError:
errors = "File missing"
except Exception as e:
errors = json.dumps(str(e))
print(e)
return 'cobrapy-load-json', cobra.__version__, is_valid, errors
return 'cobrapy-load-json', description, cobra.__version__, status, errors


def validateSbml(model_name):
print('validate sbml with cobrapy')
is_valid = False
description = 'Check with cobrapy if the model in SBML format is valid.'
print(description)
status = False
errors = ''
try:
_, result = cobra.io.sbml.validate_sbml_model(model_name + '.xml')
if result == {}:
is_valid = True
if result['SBML_FATAL'] == [] and result['SBML_ERROR'] == [] and result['SBML_SCHEMA_ERROR'] == [] and result['COBRA_FATAL'] == [] and result['COBRA_ERROR'] == []:
status = True
else:
raise Exception(result)
except Exception as e:
errors = json.dumps(str(e))
print(e)
return 'cobrapy-validate-sbml', cobra.__version__, is_valid, errors
return 'cobrapy-validate-sbml', description, cobra.__version__, status, errors
5 changes: 3 additions & 2 deletions tests/memote.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import memote

def scoreAnnotationAndConsistency(model_name):
print('memote scoring')
description = 'Check the score of the model in SBML format with Memote.'
print(description)
memote_score = False
errors = ''
try:
Expand All @@ -16,4 +17,4 @@ def scoreAnnotationAndConsistency(model_name):
except Exception as e:
errors = json.dumps(str(e))
print(e)
return 'memote-score', memote.__version__, memote_score, errors
return 'memote-score', description, memote.__version__, memote_score, errors
5 changes: 3 additions & 2 deletions tests/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import json

def validate(model_name):
print('validate YAML with yamllint')
description = 'Check if the model in YAML format is formatted correctly.'
print(description)
is_valid = False
errors = ''
try:
Expand All @@ -17,4 +18,4 @@ def validate(model_name):
except Exception as e:
errors = json.dumps(str(e))
print(e)
return 'yamllint', yamllint.__version__, is_valid, errors
return 'yamllint', description, yamllint.__version__, is_valid, errors

0 comments on commit 293653d

Please sign in to comment.