Beispiel #1
0
def config_to_dictionary(config):
    """convert the contents of a :py:class:`ConfigParser.ConfigParser`
    object to a dictionary

    This method works by iterating over all configuration values in a
    :py:class:`ConfigParser.ConfigParser` object and inserting values
    into a dictionary. Section names are prefixed using and underscore.
    Thus::

        [sample]
        name=12

    is entered as ``sample_name=12`` into the dictionary. The sections
    ``general`` and ``DEFAULT`` are treated specially in that both
    the prefixed and the unprefixed values are inserted: ::

       [general]
       genome=hg19

    will be added as ``general_genome=hg19`` and ``genome=hg19``.

    Numbers will be automatically recognized as such and converted into
    integers or floats.

    Returns
    -------
    config : dict
        A dictionary of configuration values

    """
    p = defaultdict(lambda: defaultdict(TriggeredDefaultFactory()))
    for section in config.sections():
        for key, value in config.items(section):
            try:
                v = iotools.str2val(value)
            except TypeError:
                E.error("error converting key %s, value %s" % (key, value))
                E.error("Possible multiple concurrent attempts to "
                        "read configuration")
                raise

            p["%s_%s" % (section, key)] = v

            # IMS: new heirarchical format
            try:
                p[section][key] = v
            except TypeError:
                # fails with things like genome_dir=abc
                # if [genome] does not exist.
                continue

            if section in ("general", "DEFAULT"):
                p["%s" % (key)] = v

    for key, value in config.defaults().items():
        p["%s" % (key)] = iotools.str2val(value)

    return p
Beispiel #2
0
def update_params_with_commandline_options(params, options):
    """add and update selected parameters in the parameter
    dictionary with command line options.
    """

    params["pipeline_name"] = options.pipeline_name
    params["dryrun"] = options.dry_run
    if options.cluster_queue is not None:
        params["cluster_queue"] = options.cluster_queue
    if options.cluster_priority is not None:
        params["cluster_priority"] = options.cluster_priority
    if options.cluster_num_jobs is not None:
        params["cluster_num_jobs"] = options.cluster_num_jobs
    if options.cluster_options is not None:
        params["cluster_options"] = options.cluster_options
    if options.cluster_parallel_environment is not None:
        params["cluster_parallel_environment"] =\
            options.cluster_parallel_environment
    if options.without_cluster:
        params["without_cluster"] = True

    params["shell_logfile"] = options.shell_logfile

    params["ruffus_checksums_level"] = options.ruffus_checksums_level
    # always create an "input" section
    params["input_globs"] = {}
    for variable in options.input_globs:
        if "=" in variable:
            variable, value = variable.split("=")
            params["input_globs"][variable.strip()] = value.strip()
        else:
            params["input_globs"]["default"] = variable.strip()

    for variables in options.variables_to_set:
        variable, value = variables.split("=")
        value = iotools.str2val(value.strip())
        # enter old style
        params[variable.strip()] = value
        # enter new style
        parts = variable.split("_")
        for x in range(1, len(parts)):
            prefix = "_".join(parts[:x])
            if prefix in params:
                suffix = "_".join(parts[x:])
                params[prefix][suffix] = value

    if options.work_dir:
        params["work_dir"] = os.path.abspath(options.work_dir)
    else:
        params["work_dir"] = params["start_dir"]
Beispiel #3
0
 def _convert(key, v):
     return iotools.str2val(v)
Beispiel #4
0
 def conv(v):
     return iotools.str2val(re.sub(",", "", v.strip()))