Mercurial > repos > galaxyp > openms_mapaligneridentification
annotate fill_ctd_clargs.py @ 6:992bb7e5bf8d draft
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 55a2aeba8bfd8a6910630721de9857dcdfe05d3c"
author | galaxyp |
---|---|
date | Tue, 13 Oct 2020 20:30:36 +0000 |
parents | bf50f9eb1dcb |
children | 8434f070e939 |
rev | line source |
---|---|
4
bf50f9eb1dcb
"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 |
bf50f9eb1dcb
"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 |
bf50f9eb1dcb
"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 |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
4 |
bf50f9eb1dcb
"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 ( |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
6 CTDModel, |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
7 ModelTypeError, |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
8 Parameters |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
9 ) |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
10 |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
11 if __name__ == "__main__": |
bf50f9eb1dcb
"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 |
bf50f9eb1dcb
"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) |
bf50f9eb1dcb
"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", |
bf50f9eb1dcb
"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" |
bf50f9eb1dcb
"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", |
bf50f9eb1dcb
"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) |
bf50f9eb1dcb
"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", |
bf50f9eb1dcb
"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) |
bf50f9eb1dcb
"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() |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
21 # load CTDModel |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
22 model = None |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
23 try: |
bf50f9eb1dcb
"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) |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
25 except ModelTypeError: |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
26 pass |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
27 try: |
bf50f9eb1dcb
"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) |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
29 except ModelTypeError: |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
30 pass |
bf50f9eb1dcb
"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) |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
32 |
bf50f9eb1dcb
"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 |
bf50f9eb1dcb
"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 |
bf50f9eb1dcb
"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) |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
36 |
bf50f9eb1dcb
"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 |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
38 out = StringIO() |
bf50f9eb1dcb
"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) |
bf50f9eb1dcb
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 020906fb54bde7fc143c356f41975c378a741315"
galaxyp
parents:
diff
changeset
|
40 print(out.getvalue()) |