Mercurial > repos > galaxyp > openms_xmlvalidator
comparison fill_ctd_clargs.py @ 14:860f12e67d2d draft default tip
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 2adf8edc3de4e1cd3b299b26abb14544d17d0636"
| author | galaxyp |
|---|---|
| date | Fri, 06 Nov 2020 18:47:43 +0000 |
| parents | 826fe1247aad |
| children |
comparison
equal
deleted
inserted
replaced
| 13:5dd58eb9ed8c | 14:860f12e67d2d |
|---|---|
| 1 #!/usr/bin/env python3 | |
| 2 from argparse import ArgumentParser | |
| 3 from io import StringIO | |
| 4 | |
| 5 from CTDopts.CTDopts import ( | |
| 6 CTDModel, | |
| 7 ModelTypeError, | |
| 8 Parameters | |
| 9 ) | |
| 10 | |
| 11 if __name__ == "__main__": | |
| 12 # note add_help=False since otherwise arguments starting with -h will | |
| 13 # trigger an error (despite allow_abbreviate) | |
| 14 parser = ArgumentParser(prog="fill_ctd_clargs", | |
| 15 description="fill command line arguments" | |
| 16 "into a CTD file and write the CTD file to", | |
| 17 add_help=False, allow_abbrev=False) | |
| 18 parser.add_argument("--ctd", dest="ctd", help="input ctd file", | |
| 19 metavar='CTD', default=None, required=True) | |
| 20 args, cliargs = parser.parse_known_args() | |
| 21 # load CTDModel | |
| 22 model = None | |
| 23 try: | |
| 24 model = CTDModel(from_file=args.ctd) | |
| 25 except ModelTypeError: | |
| 26 pass | |
| 27 try: | |
| 28 model = Parameters(from_file=args.ctd) | |
| 29 except ModelTypeError: | |
| 30 pass | |
| 31 assert model is not None, "Could not parse %s, seems to be no CTD/PARAMS" % (args.ctd) | |
| 32 | |
| 33 # get a dictionary of the ctd arguments where the values of the parameters | |
| 34 # given on the command line are overwritten | |
| 35 margs = model.parse_cl_args(cl_args=cliargs, ignore_required=True) | |
| 36 | |
| 37 # write the ctd with the values taken from the dictionary | |
| 38 out = StringIO() | |
| 39 ctd_tree = model.write_ctd(out, margs) | |
| 40 print(out.getvalue()) |
