Ejemplo n.º 1
0
def parseCTDCommandLine(argv, model, openms_param):
    # Configure CTDOpt to use OpenMS style on the command line.
    directives = parse_cl_directives(argv,
                                     input_ctd='ini',
                                     write_tool_ctd='write_ini',
                                     prefix='-')

    if directives[
            "write_tool_ctd"] is not None:  # triggered if -write_ini was provided on CML
        # if called with -write_ini write CTD
        model.write_ctd(directives["write_tool_ctd"])
        exit(0)
    elif directives["input_ctd"] is not None:  # read ctd/ini file
        model = CTDModel(from_file=directives["input_ctd"])
        #        print(model.get_defaults())

        param = pms.Param()
        fh = pms.ParamXMLFile()
        fh.load(directives["input_ctd"], param)
        openms_param.update(param, True)
        return model.get_defaults(), openms_param

    else:  # only command line options provided
        temp = tempfile.NamedTemporaryFile(
            suffix='ini')  # makes sure we get a writable file
        tmp_name = temp.name
        temp.close()  # removes the file

        model.write_ctd(tmp_name)
        param = pms.Param()
        fh = pms.ParamXMLFile()
        fh.load(tmp_name, param)
        openms_param.update(param)
        os.remove(tmp_name)
        return model.parse_cl_args(argv), openms_param
Ejemplo n.º 2
0
    # load CTDModel
    ini_model = None
    try:
        ini_model = CTDModel(from_file=args.ini_file)
    except ModelTypeError:
        pass
    try:
        ini_model = Parameters(from_file=args.ini_file)
    except ModelTypeError:
        pass
    assert ini_model is not None, "Could not parse %s, seems to be no CTD/PARAMS" % (
        args.ini_file)

    # get a dictionary of the ctd arguments where the values of the parameters
    # given on the command line are overwritten
    ini_values = ini_model.parse_cl_args(cl_args=cliargs, ignore_required=True)

    if args.ctd_file:
        ctd_model = CTDModel(from_file=args.ctd_file)
        ctd_values = ctd_model.get_defaults()
        for param in ini_model.get_parameters():
            if not param.required and (param.default is None
                                       or type(param.default) is _Null):
                lineage = param.get_lineage(name_only=True)
                try:
                    default = getFromDict(ctd_values, lineage)
                except KeyError:
                    continue
                setInDict(ini_values, lineage, default)

    # write the ctd with the values taken from the dictionary
Ejemplo n.º 3
0
    description='Only adds results to entries with decoy set to true. DEFAULT: false'
)

pout2mzidparams.add(
    'validate',
    type=bool,
    description='This is a flag: Type 1 to set flag. Sets that validation of XML schema should not be performed. Faster parsing.'
)

pout2mzidparams.add(
    'warning',
    type=bool,
    description='This is a flag: Type 1 to set flag. Sets that upon warning the software should terminate'
)

args = msgf_percolator_model.parse_cl_args()

try:
    args = args_from_file(args['ctd'])
    print "try to load ctd"

    ### MZID2PIN Parameter ###
    try:
        args['mzid2pin']['mzid2pin_path']
        args['mzid2pin']['target_input']
        args['mzid2pin']['decoy_input']
    except:
        print "Path or decoy/target-files missing!"
    str = ''
    try:
        if args['mzid2pin']['outputXML'] != '':
Ejemplo n.º 4
0
print ("One might want to combine arguments loaded from a CTD file with arguments coming from elsewhere, like the command line."
    "In that case, the method CTDopts.override_args(*arg_dicts) creates a combined argument dictionary where argument values "
    "are always taken from the rightmost (last) dictionary that has them. Let's override a few parameters:")
override = {
    'this_that': 'that',
    'positive_int': 777
    }
overridden = override_args(validated, override)
pretty_print(overridden)
print()

print ("So how to deal with command line arguments? If we have a model, we can look for its arguments. "
    "Call CTDModel.parse_cl_args() with either a string of the command line call or a list with the split words. "
    "By default, it will assume a '--' prefix before parameter names, but it can be overridden with prefix='-'."
    "Grouped parameters are expected in --group:subgroup:param_x format.")
cl_args = model.parse_cl_args('--positive_int 44 --subparams:param_2 5.0 5.5 6.0 --input_files a.fastq b.fastq')
pretty_print(cl_args)
print()
# # you can get unmatchable command line arguments with get_remaining=True like:
# cl_args, unparsed = model.parse_cl_args('--positive_int 44 --subparams:param_2 5.0 5.5 6.0 --unrelated_stuff abc', get_remaining=True)

print ("Override other parameters with them, and validate it against the model:")
overridden_with_cl = override_args(validated, cl_args)
validated_3 = model.validate_args(overridden_with_cl)
pretty_print(validated_3)
print()

print ("One last thing: certain command line directives that are specific to CTD functionality can be parsed for, "
    "to help your script performing common tasks. These are CTD argument input, CTD model file writing and CTD argument "
    "file writing. CTDopts.parse_cl_directives() can also be customized as to what directives to look for if the defaults "
    "--input_ctd, --write_tool_ctd and --write_param_ctd respectively don't satisfy you.")
Ejemplo n.º 5
0
    "One might want to combine arguments loaded from a CTD file with arguments coming from elsewhere, like the command line."
    "In that case, the method CTDopts.override_args(*arg_dicts) creates a combined argument dictionary where argument values "
    "are always taken from the rightmost (last) dictionary that has them. Let's override a few parameters:"
)
override = {'this_that': 'that', 'positive_int': 777}
overridden = override_args(validated, override)
pretty_print(overridden)
print()

print(
    "So how to deal with command line arguments? If we have a model, we can look for its arguments. "
    "Call CTDModel.parse_cl_args() with either a string of the command line call or a list with the split words. "
    "By default, it will assume a '--' prefix before parameter names, but it can be overridden with prefix='-'."
    "Grouped parameters are expected in --group:subgroup:param_x format.")
cl_args = model.parse_cl_args(
    '--positive_int 44 --subparams:param_2 5.0 5.5 6.0 --input_files a.fastq b.fastq --output out_dir/'
)
pretty_print(cl_args)
print()
# # you can get unmatchable command line arguments with get_remaining=True like:
# cl_args, unparsed = model.parse_cl_args('--positive_int 44 --subparams:param_2 5.0 5.5 6.0 --unrelated_stuff abc', get_remaining=True)

print(
    "Override other parameters with them, and validate it against the model:")
overridden_with_cl = override_args(validated, cl_args)
validated_3 = model.validate_args(overridden_with_cl)
pretty_print(validated_3)
print

print(
    "One last thing: certain command line directives that are specific to CTD functionality can be parsed for, "
Ejemplo n.º 6
0
                            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())