annotate ebcsgen_simulate.py @ 2:bd726f013bc1 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:22:31 +0000
parents 179d32e79968
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
1 import argparse
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
2
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
3 from eBCSgen.Errors import UnspecifiedParsingError
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
4 from eBCSgen.Errors.InvalidInputError import InvalidInputError
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
5 from eBCSgen.Errors.ModelParsingError import ModelParsingError
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
6 from eBCSgen.Errors.RatesNotSpecifiedError import RatesNotSpecifiedError
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
7 from eBCSgen.Parsing.ParseBCSL import Parser
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
8
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
9
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
10 args_parser = argparse.ArgumentParser(description='Simulation')
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
11
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
12 args_parser._action_groups.pop()
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
13 required = args_parser.add_argument_group('required arguments')
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
14
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
15 required.add_argument('--model', type=str, required=True)
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
16 required.add_argument('--output', type=str, required=True)
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
17 required.add_argument('--deterministic', required=True)
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
18 required.add_argument('--direct', required=True)
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
19 required.add_argument('--runs', type=int, required=True)
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
20 required.add_argument('--max_time', type=float, required=True)
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
21 required.add_argument('--volume', type=float, required=True)
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
22 required.add_argument('--step', type=float, required=True)
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
23
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
24 args = args_parser.parse_args()
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
25
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
26 model_parser = Parser("model")
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
27 model_str = open(args.model, "r").read()
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
28
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
29 model = model_parser.parse(model_str)
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
30
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
31 if model.success:
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
32 if len(model.data.params) != 0:
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
33 raise InvalidInputError("Provided model is parametrised - simulation cannot be executed.")
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
34 if not model.data.all_rates:
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
35 raise RatesNotSpecifiedError("Some rules do not have rates specified - simulation cannot be executed.")
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
36
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
37 if eval(args.deterministic):
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
38 vm = model.data.to_vector_model()
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
39 df = vm.deterministic_simulation(args.max_time, args.volume, args.step)
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
40 else:
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
41 if eval(args.direct):
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
42 df = model.data.network_free_simulation(args.max_time)
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
43 else:
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
44 vm = model.data.to_vector_model()
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
45 df = vm.stochastic_simulation(args.max_time, args.runs)
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
46
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
47 df.to_csv(args.output, index=None, header=True)
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
48 else:
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
49 if "error" in model.data:
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
50 raise UnspecifiedParsingError(model.data["error"])
179d32e79968 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 33b83dc8c71401922b087400fa1f4080e9abe170
sybila
parents:
diff changeset
51 raise ModelParsingError(model.data, model_str)