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