Mercurial > repos > sybila > ebcsgen_static_analysis
comparison ebcsgen_static_analysis.py @ 0:35cc9bb0b4e9 draft
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit f39ef50b0964744be7816de065024eeb1fb69364
author | sybila |
---|---|
date | Sat, 08 Oct 2022 14:07:25 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:35cc9bb0b4e9 |
---|---|
1 import argparse | |
2 | |
3 from eBCSgen.Errors.ComplexParsingError import ComplexParsingError | |
4 from eBCSgen.Errors.ModelParsingError import ModelParsingError | |
5 from eBCSgen.Errors.UnspecifiedParsingError import UnspecifiedParsingError | |
6 from eBCSgen.Parsing.ParseBCSL import Parser | |
7 | |
8 | |
9 def save_model(model, filename): | |
10 f = open(filename, "w") | |
11 f.write(repr(model)) | |
12 f.close() | |
13 | |
14 | |
15 args_parser = argparse.ArgumentParser(description='Static analysis') | |
16 | |
17 args_parser._action_groups.pop() | |
18 required = args_parser.add_argument_group('required arguments') | |
19 optional = args_parser.add_argument_group('optional arguments') | |
20 | |
21 required.add_argument('--model', type=str, required=True) | |
22 required.add_argument('--output', type=str, required=True) | |
23 required.add_argument('--method', type=str, required=True) | |
24 optional.add_argument('--complex') | |
25 | |
26 args = args_parser.parse_args() | |
27 | |
28 model_parser = Parser("model") | |
29 model_str = open(args.model, "r").read() | |
30 model = model_parser.parse(model_str) | |
31 | |
32 if model.success: | |
33 if args.method == "reduce": | |
34 model.data.reduce_context() | |
35 save_model(model.data, args.output) | |
36 elif args.method == "eliminate": | |
37 model.data.eliminate_redundant() | |
38 save_model(model.data, args.output) | |
39 else: | |
40 complex_parser = Parser("rate_complex") | |
41 complex = complex_parser.parse(args.complex) | |
42 if complex.success: | |
43 result = model.data.static_non_reachability(complex.data.children[0]) | |
44 f = open(args.output, "w") | |
45 s = "can possibly" if result else "cannot" | |
46 message = "The given agent\n\t{}\n{} be reached in the model.".format(complex.data.children[0], s) | |
47 f.write(message) | |
48 f.close() | |
49 else: | |
50 raise ComplexParsingError(complex.data, args.complex) | |
51 else: | |
52 if "error" in model.data: | |
53 raise UnspecifiedParsingError(model.data["error"]) | |
54 raise ModelParsingError(model.data, model_str) |