Ejemplo n.º 1
0
def get_workflow_name_and_version_from_config(config_file, dont_raise=False):
    filesnpaths.is_file_json_formatted(config_file)
    config = json.load(open(config_file))
    workflow_name = config.get('workflow_name')
    # Notice that if there is no config_version then we return "0".
    # This is in order to accomodate early config files that had no such parameter.
    version = config.get('config_version', "0")

    if (not dont_raise) and (not workflow_name):
        raise ConfigError('Config files must contain a workflow_name.')

    return (workflow_name, version)
Ejemplo n.º 2
0
    def __init__(self):
        if 'args' not in self.__dict__:
            raise ConfigError(
                "You need to initialize `WorkflowSuperClass` from within a class that\
                               has a member `self.args`.")

        A = lambda x: self.args.__dict__[x
                                         ] if x in self.args.__dict__ else None
        # FIXME: it is redundant to have both config and config_file
        # Alon and Meren will discuss how to do this right.
        # but for now this is how it is so things would work.
        # basically, when this class is called from a snakefile
        # then a config (dictionary) will be provided.
        # When this class is called from anvi-run-snakemake-workflow
        # for sanity checks  and things like that, then a config file
        # will be provided.
        self.config = A('config')
        self.config_file = A('config_file')
        self.default_config_output_path = A('get_default_config')
        self.save_workflow_graph = A('save_workflow_graph')
        self.list_dependencies = A('list_dependencies')
        self.dry_run_only = A('dry_run')
        self.additional_params = A('additional_params')

        if self.additional_params:
            run.warning(
                "OK, SO THIS IS SERIOUS, AND WHEN THINGS ARE SERIOUS THEN WE USE CAPS. \
                         WE SEE THAT YOU ARE USING --additional-params AND THAT'S GREAT, BUT WE \
                         WANT TO REMIND YOU THAT ANYTHING THAT FOLLOWS --additional-params WILL \
                         BE CONSIDERED AS A snakemake PARAM THAT IS TRANSFERRED TO snakemake DIRECTLY. \
                         So make sure that these don't include anything that you didn't mean to \
                         include as an additional param: %s." %
                ', '.join(str(i) for i in self.additional_params))

        if self.save_workflow_graph:
            self.dry_run_only = True

        # if this class is being inherited from a snakefile that was 'included' from
        # within another snakefile.
        self.slave_mode = A('slave_mode')

        if self.config_file:
            filesnpaths.is_file_json_formatted(self.config_file)
            self.config = json.load(open(self.config_file))

        self.rules = []
        self.rule_acceptable_params_dict = {}
        self.dirs_dict = {}
        self.general_params = []
        self.default_config = {}
        self.rules_dependencies = {}
        self.forbidden_params = {}
Ejemplo n.º 3
0
    def __init__(self):
        if 'args' not in self.__dict__:
            raise ConfigError("You need to initialize `WorkflowSuperClass` from within a class that\
                               has a member `self.args`.")

        A = lambda x: self.args.__dict__[x] if x in self.args.__dict__ else None
        # FIXME: it is redundant to have both config and config_file
        # Alon and Meren will discuss how to do this right.
        # but for now this is how it is so things would work.
        # basically, when this class is called from a snakefile
        # then a config (dictionary) will be provided.
        # When this class is called from anvi-run-snakemake-workflow
        # for sanity checks  and things like that, then a config file
        # will be provided.
        self.config = A('config')
        self.config_file = A('config_file')
        self.default_config_output_path = A('get_default_config')
        self.save_workflow_graph = A('save_workflow_graph')
        self.list_dependencies = A('list_dependencies')
        self.dry_run_only = A('dry_run')
        self.additional_params = A('additional_params')

        if self.additional_params:
            run.warning("OK, SO THIS IS SERIOUS, AND WHEN THINGS ARE SERIOUS THEN WE USE CAPS. \
                         WE SEE THAT YOU ARE USING --additional-params AND THAT'S GREAT, BUT WE \
                         WANT TO REMIND YOU THAT ANYTHING THAT FOLLOWS --additional-params WILL \
                         BE CONSIDERED AS A snakemake PARAM THAT IS TRANSFERRED TO snakemake DIRECTLY. \
                         So make sure that these don't include anything that you didn't mean to \
                         include as an additional param: %s." % ', '.join(str(i) for i in self.additional_params))

        if self.save_workflow_graph:
            self.dry_run_only = True

        # if this class is being inherited from a snakefile that was 'included' from
        # within another snakefile.
        self.slave_mode = A('slave_mode')

        if self.config_file:
            filesnpaths.is_file_json_formatted(self.config_file)
            self.config = json.load(open(self.config_file))

        self.rules = []
        self.rule_acceptable_params_dict = {}
        self.dirs_dict = {}
        self.general_params = []
        self.default_config = {}
        self.rules_dependencies = {}
        self.forbidden_params = {}
Ejemplo n.º 4
0
    def __init__(self):
        if 'args' not in self.__dict__:
            raise ConfigError("You need to initialize `WorkflowSuperClass` from within a class that "
                              "has a member `self.args`.")

        A = lambda x: self.args.__dict__[x] if x in self.args.__dict__ else None
        # FIXME: it is redundant to have both config and config_file
        # Alon and Meren will discuss how to do this right.
        # but for now this is how it is so things would work.
        # basically, when this class is called from a snakefile
        # then a config (dictionary) will be provided.
        # When this class is called from anvi-run-snakemake-workflow
        # for sanity checks  and things like that, then a config file
        # will be provided.
        self.config = A('config')
        self.config_file = A('config_file')
        self.default_config_output_path = A('get_default_config')
        self.save_workflow_graph = A('save_workflow_graph')
        self.list_dependencies = A('list_dependencies')
        self.dry_run_only = A('dry_run')
        self.additional_params = A('additional_params')
        self.skip_version_check = A('skip_version_check')

        if self.additional_params:
            run.warning("OK, SO THIS IS SERIOUS, AND WHEN THINGS ARE SERIOUS THEN WE USE CAPS. "
                        "WE SEE THAT YOU ARE USING --additional-params AND THAT'S GREAT, BUT WE "
                        "WANT TO REMIND YOU THAT ANYTHING THAT FOLLOWS --additional-params WILL "
                        "BE CONSIDERED AS A snakemake PARAM THAT IS TRANSFERRED TO snakemake DIRECTLY. "
                        "So make sure that these don't include anything that you didn't mean to "
                        "include as an additional param: %s." % ', '.join(str(i) for i in self.additional_params))

        if self.save_workflow_graph:
            self.dry_run_only = True

        # if this class is being inherited from a snakefile that was 'included' from
        # within another snakefile.
        self.this_workflow_is_inherited_by_another = A('this_workflow_is_inherited_by_another')

        if self.config_file:
            filesnpaths.is_file_json_formatted(self.config_file)
            self.config = json.load(open(self.config_file))

        if self.config and ('config_version' not in self.config or 'workflow_name' not in self.config):
            raise ConfigError(f"You config file '{self.config_file}' is probably too old as it is missing some key varaibles "
                              f"in it. Please make sure your config includes entries for both `config_version` and "
                              f"`workflow_name`.")

        # If a config exists, check that its current
        if self.config and not self.skip_version_check:
            if self.config['config_version'] != workflow_config_version:
                raise ConfigError(f"Anvi'o couldn't get things moving because the version of your config file is out "
                                  f"of date (your version: {self.config['config_version']}; up-to-date version: "
                                  f"{workflow_config_version}). Not a problem though, simply run `anvi-migrate {self.config_file} "
                                  f"--migrate-dbs-safely` and it will be updated. Then re-run the command producing "
                                  f"this error message.")

        self.rules = []
        self.rule_acceptable_params_dict = {}
        self.dirs_dict = {}
        self.general_params = []
        self.default_config = {}
        self.rules_dependencies = {}
        self.forbidden_params = {}