annotate ebcsgen_sbml_export.py @ 2:26cdeab59c55 draft default tip

planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
author sybila
date Sat, 15 Oct 2022 09:20:29 +0000
parents a09b6d472931
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
1 import argparse
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
2
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
3 from eBCSgen.Errors.ModelParsingError import ModelParsingError
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
4 from eBCSgen.Errors.UnspecifiedParsingError import UnspecifiedParsingError
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
5 from eBCSgen.Parsing.ParseBCSL import Parser
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
6
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
7 import libsbml
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
8
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
9
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
10 args_parser = argparse.ArgumentParser(description='Export SBML model with usage of SBML-multi package')
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
11
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
12 args_parser._action_groups.pop()
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
13 required = args_parser.add_argument_group('required arguments')
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
14
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
15 required.add_argument('--model', type=str, required=True)
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
16 required.add_argument('--output', type=str, required=True)
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
17
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
18 args = args_parser.parse_args()
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
19
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
20 model_parser = Parser("model")
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
21 model_str = open(args.model, "r").read()
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
22
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
23 model = model_parser.parse(model_str)
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
24 if model.success:
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
25 document = model.data.export_sbml()
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
26 libsbml.writeSBMLToFile(document, args.output)
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
27 else:
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
28 if "error" in model.data:
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
29 raise UnspecifiedParsingError(model.data["error"])
a09b6d472931 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 74a375c33936106a892dafb042be953a943af026
sybila
parents:
diff changeset
30 raise ModelParsingError(model.data, model_str)