diff fill_ctd_clargs.py @ 8:146b59d2d3e5 draft

"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit e499c9124d3fd85a7fc47b95c206ce91a5e3678c-dirty"
author galaxyp
date Wed, 04 Nov 2020 13:04:26 +0000
parents
children 6b01678ec2fc
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fill_ctd_clargs.py	Wed Nov 04 13:04:26 2020 +0000
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+from argparse import ArgumentParser
+from io import StringIO
+
+from CTDopts.CTDopts import (
+    CTDModel,
+    ModelTypeError,
+    Parameters
+)
+
+if __name__ == "__main__":
+    # note add_help=False since otherwise arguments starting with -h will
+    # trigger an error (despite allow_abbreviate)
+    parser = ArgumentParser(prog="fill_ctd_clargs",
+                            description="fill command line arguments"
+                            "into a CTD file and write the CTD file to",
+                            add_help=False, allow_abbrev=False)
+    parser.add_argument("--ctd", dest="ctd", help="input ctd file",
+                        metavar='CTD', default=None, required=True)
+    args, cliargs = parser.parse_known_args()
+    # load CTDModel
+    model = None
+    try:
+        model = CTDModel(from_file=args.ctd)
+    except ModelTypeError:
+        pass
+    try:
+        model = Parameters(from_file=args.ctd)
+    except ModelTypeError:
+        pass
+    assert model is not None, "Could not parse %s, seems to be no CTD/PARAMS" % (args.ctd)
+
+    # get a dictionary of the ctd arguments where the values of the parameters
+    # given on the command line are overwritten
+    margs = model.parse_cl_args(cl_args=cliargs, ignore_required=True)
+
+    # write the ctd with the values taken from the dictionary
+    out = StringIO()
+    ctd_tree = model.write_ctd(out, margs)
+    print(out.getvalue())