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