Mercurial > repos > galaxyp > openms_openswathchromatogramextractor
comparison fill_ctd_clargs.py @ 9:e9c148b32f87 draft
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
author | galaxyp |
---|---|
date | Wed, 09 Sep 2020 20:03:02 +0000 |
parents | |
children | f78d734b7c01 |
comparison
equal
deleted
inserted
replaced
8:0b2a3b05a9b4 | 9:e9c148b32f87 |
---|---|
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()) |