Skip to content

Commit

Permalink
Update package reference for sbmlpbkutils and add option to include C…
Browse files Browse the repository at this point in the history
…ITATION.cff for annotation of authors
  • Loading branch information
jwkruisselbrink committed Dec 11, 2024
1 parent c939b12 commit f2e0992
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ jobs:
- name: Annotate SBML
id: annotate-sbml
run: |
(python sbml-pbk-workflow/src/annotate_sbml.py -f model/${{inputs.model-name}}.sbml model/${{inputs.model-name}}.annotations.csv model/${{inputs.model-name}}.sbml) | tee log/annotate-terms.log
if [ -f CITATION.cff ]; then
(python sbml-pbk-workflow/src/annotate_sbml.py model/${{inputs.model-name}}.sbml model/${{inputs.model-name}}.annotations.csv model/${{inputs.model-name}}.sbml -c CITATION.cff -f) | tee log/annotate-terms.log
else
(python sbml-pbk-workflow/src/annotate_sbml.py model/${{inputs.model-name}}.sbml model/${{inputs.model-name}}.annotations.csv model/${{inputs.model-name}}.sbml -f) | tee log/annotate-terms.log
fi
shell: bash

- name: Validate SBML
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ python-libsbml>=5.20.2
sbmlutils>=0.9.0
tellurium>=2.2.10
numpy>=1.26.4
sbmlpbkutils @ git+https://github.com/jwkruisselbrink/sbml-pbk-utils.git@v0.10.0
sbmlpbkutils @ git+https://github.com/jwkruisselbrink/sbml-pbk-utils.git@v0.12.0
13 changes: 9 additions & 4 deletions src/annotate_sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,31 @@ def main():
parser.add_argument("sbml_file", help="Full path to SBML file")
parser.add_argument("annotations_file", help="Full path to SBML file")
parser.add_argument("out_file", help="Output file")
parser.add_argument("-c", "--cff", type=str, help="CFF file (optional)")
parser.add_argument("-f", "--force", action="store_true", help="Overwrite existing")
args = parser.parse_args()
f_in = Path(args.sbml_file)
f_ann = Path(args.annotations_file)
f_cff = Path(args.cff) if args.cff else None
f_out = Path(args.out_file)
if not f_in.is_file():
raise FileNotFoundError(f'SBML file [{f_in}] does not exist.')
raise FileNotFoundError(f'SBML file [{f_in}] not found.')
if not f_ann.is_file():
raise FileNotFoundError(f'Annotations file [{f_ann}] does not exist.')
raise FileNotFoundError(f'Annotations file [{f_ann}] not found.')
if f_cff is not None and not f_cff.is_file():
raise FileNotFoundError(f'CFF file [{f_cff}] not found.')
try:
if not f_out.exists() or args.force:

# Check if output folder exists, otherwise create it
out_dir = os.path.dirname(f_out)
if not os.path.exists(out_dir):
os.makedirs(out_dir)

# Annotate SBML file
annotator = PbkModelAnnotator()
document = annotator.annotate(f_in, f_ann, logger)
document = ls.readSBML(f_in)
annotator.annotate(document, f_ann, f_cff, logger)

# Write SBML
ls.writeSBML(document, str(f_out))
Expand Down
8 changes: 8 additions & 0 deletions tests/models/simple.CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cff-version: 1.2.0
title: simple
version: 0.0.1
authors:
- family-names: Doe
given-names: John
email: [email protected]
affiliation: ACME
13 changes: 13 additions & 0 deletions tests/test_annotate_sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,18 @@ def test_simple(self):
path = pl.Path('./tests/output/simple.annotated.sbml')
self.assertIsFile(path)

@patch('sys.argv', [
'ant2sbml.py',
'./tests/models/simple.sbml',
'./tests/models/simple.annotations.csv',
'./tests/output/simple.annotated.cff.sbml',
'-c', './tests/models/simple.CITATION.cff',
'-f'
])
def test_simple_cff(self):
src.annotate_sbml.main()
path = pl.Path('./tests/output/simple.annotated.cff.sbml')
self.assertIsFile(path)

if __name__ == '__main__':
unittest.main()

0 comments on commit f2e0992

Please sign in to comment.