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