Ejemplo n.º 1
0
    def _prepare_specs(self):
        with self.yaml_path.open("r") as file:
            specs = yaml.safe_load(file)

        ParameterValidator.assert_keys_present(specs.keys(), ["definitions", "instructions"], GalaxyTrainMLModel.__name__, "YAML specification")
        ParameterValidator.assert_all_in_valid_list(specs.keys(), ["definitions", "instructions", "output"], GalaxyTrainMLModel.__name__,
                                                    "YAML specification")

        ParameterValidator.assert_type_and_value(specs["instructions"], dict, GalaxyTrainMLModel.__name__, "instructions")

        assert len(list(specs["instructions"].keys())) == 1, f"{GalaxyTrainMLModel.__name__}: one instruction has to be specified under " \
                                                             f"`instructions`, got the following instead: {list(specs['instructions'].keys())}."

        self.instruction_name = list(specs["instructions"].keys())[0]

        ParameterValidator.assert_type_and_value(specs['instructions'][self.instruction_name], dict, GalaxyTrainMLModel.__name__,
                                                 self.instruction_name)
        ParameterValidator.assert_keys_present(specs['instructions'][self.instruction_name].keys(), ['type'], GalaxyTrainMLModel.__name__,
                                               self.instruction_name)

        assert specs['instructions'][self.instruction_name]['type'] == TrainMLModelInstruction.__name__[:-11], \
            f"{GalaxyTrainMLModel.__name__}: instruction `type` under {self.instruction_name} has to be {TrainMLModelInstruction.__name__[:-11]} " \
            f"for this tool."

        assert len(
            specs['instructions'][self.instruction_name]['labels']) == 1, f"{GalaxyTrainMLModel.__name__}: one label has to be specified under " \
                                                                          f"`labels`, got the following instead: {specs['instructions'][self.instruction_name]['labels']}."
        Util.check_paths(specs, GalaxyTrainMLModel.__name__)
        Util.update_result_paths(specs, self.result_path, self.yaml_path)
Ejemplo n.º 2
0
 def __init__(self, specification_path: Path, result_path: Path, **kwargs):
     Util.check_parameters(specification_path, result_path, kwargs,
                           DataSimulationTool.__name__)
     super().__init__(specification_path, result_path, **kwargs)
     self.expected_instruction = DatasetExportInstruction.__name__[:-11]
     self.instruction_name = None
     self.dataset_name = None
     self.export_format = None
Ejemplo n.º 3
0
    def _run(self):
        self.prepare_specs()
        Util.run_tool(self.yaml_path, self.result_path)

        dataset_location = self.result_path / f"{self.instruction_name}/{self.dataset_name}/{self.export_format}/"
        shutil.copytree(dataset_location, self.result_path / 'result/')

        logging.info(
            f"{DataSimulationTool.__name__}: immuneML has finished and the dataset was created."
        )
Ejemplo n.º 4
0
    def _run(self):
        self.prepare_specs()

        Util.run_tool(self.yaml_path, self.result_path)

        dataset_location = list(
            self.result_path.glob("*/exported_dataset/*/"))[0]
        shutil.copytree(dataset_location, self.result_path / 'result/')

        logging.info(
            f"{GalaxySimulationTool.__name__}: immuneML has finished and the signals were implanted in the dataset."
        )
Ejemplo n.º 5
0
    def prepare_specs(self):
        with self.yaml_path.open("r") as file:
            specs = yaml.safe_load(file)

        instruction_name = Util.check_instruction_type(
            specs, GalaxySimulationTool.__name__,
            SimulationInstruction.__name__[:-11])
        Util.check_export_format(specs, GalaxySimulationTool.__name__,
                                 instruction_name)

        Util.update_dataset_key(specs, GalaxySimulationTool.__name__)
        Util.check_paths(specs, "GalaxySimulationTool")
        Util.update_result_paths(specs, self.result_path, self.yaml_path)
Ejemplo n.º 6
0
    def _update_specs(self):
        with self.yaml_path.open('r') as file:
            specs = yaml.safe_load(file)

        ParameterValidator.assert_keys_present(specs.keys(),
                                               ["definitions", "instructions"],
                                               DatasetGenerationTool.__name__,
                                               "YAML specification")
        ParameterValidator.assert_all_in_valid_list(
            specs.keys(), ["definitions", "instructions", "output"],
            DatasetGenerationTool.__name__, "YAML specification")

        self._check_dataset(specs)
        self._check_instruction(specs)

        Util.check_paths(specs, DatasetGenerationTool.__name__)
        Util.update_result_paths(specs, self.result_path, self.yaml_path)
Ejemplo n.º 7
0
    def prepare_specs(self):
        with self.yaml_path.open("r") as file:
            specs = yaml.safe_load(file)

        self.instruction_name = Util.check_instruction_type(
            specs, DataSimulationTool.__name__, self.expected_instruction)
        self.export_format = Util.check_export_format(
            specs, DataSimulationTool.__name__, self.instruction_name)

        ParameterValidator.assert_keys_present(specs["definitions"],
                                               ["datasets"],
                                               DataSimulationTool.__name__,
                                               "definitions/datasets")
        ParameterValidator.assert_type_and_value(
            specs['definitions']['datasets'], dict,
            DataSimulationTool.__name__, "definitions/datasets")

        dataset_names = list(specs['definitions']['datasets'].keys())
        assert len(dataset_names) == 1, f"{DataSimulationTool.__name__}: one dataset has to be defined under definitions/datasets, got " \
                                        f"{dataset_names} instead."

        self.dataset_name = dataset_names[0]

        Util.check_paths(specs, DataSimulationTool.__name__)
        Util.update_result_paths(specs, self.result_path, self.yaml_path)
Ejemplo n.º 8
0
    def _check_instruction(self, specs):
        instruction_name = Util.check_instruction_type(
            specs, DatasetGenerationTool.__name__,
            DatasetExportInstruction.__name__[:-11])

        for key in ['datasets', 'export_formats']:
            ParameterValidator.assert_keys_present(
                list(specs['instructions'][instruction_name].keys()), [key],
                DatasetGenerationTool.__name__, instruction_name)
            ParameterValidator.assert_type_and_value(
                specs["instructions"][instruction_name][key], list,
                DatasetGenerationTool.__name__, f"{instruction_name}/{key}")

            assert len(specs['instructions'][instruction_name][key]) == 1, \
                f"{DatasetGenerationTool.__name__}: this tool accepts only one item under {key}, got {specs['instructions'][instruction_name][key]} " \
                f"instead."
Ejemplo n.º 9
0
    def _check_specs(self):
        with open(self.yaml_path, "r") as file:
            specs = yaml.load(file)

        instruction_name = Util.check_instruction_type(
            specs, GalaxyMLApplicationTool.__name__,
            MLApplicationInstruction.__name__[:-11])

        ParameterValidator.assert_keys_present(
            list(specs['instructions'][instruction_name].keys()),
            ["dataset", "config_path"], GalaxyMLApplicationTool.__name__,
            instruction_name)

        assert os.path.isfile(specs['instructions'][instruction_name]['config_path']), \
            f"{GalaxyMLApplicationTool.__name__}: file specified under 'config_path' parameter " \
            f"({specs['instructions'][instruction_name]['config_path']}) is not available. Please check if it was correctly uploaded or if the file" \
            f" name is correct."
Ejemplo n.º 10
0
    def prepare_specs(self):
        with self.yaml_path.open("r") as file:
            specs = yaml.safe_load(file)

        self.instruction_name = Util.check_instruction_type(
            specs, DataSimulationTool.__name__, self.expected_instruction)
        self.export_format = Util.check_export_format(
            specs, DataSimulationTool.__name__, self.instruction_name)

        ParameterValidator.assert_keys_present(specs["definitions"],
                                               ["datasets"],
                                               DataSimulationTool.__name__,
                                               "definitions/datasets")
        ParameterValidator.assert_type_and_value(
            specs['definitions']['datasets'], dict,
            DataSimulationTool.__name__, "definitions/datasets")

        self.dataset_name = "dataset"
        Util.update_dataset_key(specs, DataSimulationTool.__name__,
                                self.dataset_name)

        Util.check_paths(specs, DataSimulationTool.__name__)
        Util.update_result_paths(specs, self.result_path, self.yaml_path)
Ejemplo n.º 11
0
 def __init__(self, specification_path: Path, result_path: Path, **kwargs):
     Util.check_parameters(specification_path, result_path, kwargs,
                           "Dataset generation tool")
     super().__init__(specification_path, result_path, **kwargs)
Ejemplo n.º 12
0
 def __init__(self, specification_path: Path, result_path: Path, **kwargs):
     Util.check_parameters(specification_path, result_path, kwargs,
                           GalaxySimulationTool.__name__)
     super().__init__(specification_path, result_path, **kwargs)
Ejemplo n.º 13
0
 def __init__(self, specification_path: Path, result_path: Path, **kwargs):
     Util.check_parameters(specification_path, result_path, kwargs, GalaxyTrainMLModel.__name__)
     super().__init__(specification_path, result_path, **kwargs)
     self.instruction_name = None
Ejemplo n.º 14
0
    def update_specs(self):
        with self.yaml_path.open("r") as file:
            specs_dict = yaml.safe_load(file)

        Util.check_paths(specs_dict, 'GalaxyYamlTool')
        Util.update_result_paths(specs_dict, self.result_path, self.yaml_path)
Ejemplo n.º 15
0
 def __init__(self, specification_path: Path, result_path: Path, **kwargs):
     Util.check_parameters(specification_path, result_path, kwargs, "GalaxyYamlTool")
     super().__init__(specification_path, result_path, **kwargs)