diff --git a/client/src/mvc/rules/rule-definitions.js b/client/src/mvc/rules/rule-definitions.js index 1abb889402c..09aa3818978 100644 --- a/client/src/mvc/rules/rule-definitions.js +++ b/client/src/mvc/rules/rule-definitions.js @@ -788,7 +788,7 @@ const MAPPING_TARGETS = { help: _l( "Add a general purpose tag based on the specified column value, use : to separate key-value pairs if desired. These tags are not propagated to derived datasets the way name and group tags are." ), - modes: ["raw", "ftp", "datasets", "library_datasets"], + modes: ["raw", "ftp", "datasets", "library_datasets", "collection_contents"], }, group_tags: { multiple: true, @@ -796,7 +796,7 @@ const MAPPING_TARGETS = { help: _l( "Add a group tag based on the specified column value, use : to separate key-value pairs. These tags are propagated to derived datasets and may be useful for factorial experiments." ), - modes: ["raw", "ftp", "datasets", "library_datasets"], + modes: ["raw", "ftp", "datasets", "library_datasets", "collection_contents"], }, name: { label: _l("Name"), diff --git a/lib/galaxy/managers/collections.py b/lib/galaxy/managers/collections.py index 060496526ac..c7b6ad80106 100644 --- a/lib/galaxy/managers/collections.py +++ b/lib/galaxy/managers/collections.py @@ -499,6 +499,7 @@ class DatasetCollectionManager: def _build_elements_from_rule_data(self, collection_type_description, rule_set, data, sources, handle_dataset): identifier_columns = rule_set.identifier_columns + mapping_as_dict = rule_set.mapping_as_dict elements = OrderedDict() for data_index, row_data in enumerate(data): # For each row, find place in depth for this element. @@ -518,7 +519,22 @@ class DatasetCollectionManager: else: raise Exception("Unknown indicator of paired status encountered - only values of F, R, 1, 2, R1, R2, forward, or reverse are allowed.") - elements_at_depth[identifier] = handle_dataset(sources[data_index]["dataset"]) + tags = [] + if "group_tags" in mapping_as_dict: + columns = mapping_as_dict["group_tags"]["columns"] + for tag_column in columns: + tag = row_data[tag_column] + tags.append("group:%s" % tag) + + if "tags" in mapping_as_dict: + columns = mapping_as_dict["tags"]["columns"] + for tag_column in columns: + tag = row_data[tag_column] + tags.append(tag) + + effective_dataset = handle_dataset(sources[data_index]["dataset"], tags) + elements_at_depth[identifier] = effective_dataset + # log.info("Handling dataset [%s] with sources [%s], need to add tags [%s]" % (effective_dataset, sources, tags)) else: collection_type_at_depth = collection_type_at_depth.child_collection_type_description() found = False diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index 315a6221fee..2ad7345053a 100644 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -3158,9 +3158,11 @@ class ApplyRulesTool(DatabaseOperationTool): rule_set = RuleSet(incoming["rules"]) copied_datasets = [] - def copy_dataset(dataset): + def copy_dataset(dataset, tags): copied_dataset = dataset.copy(flush=False) copied_datasets.append(copied_dataset) + if tags is not None: + self.app.tag_handler.set_tags_from_list(trans.get_user(), copied_dataset, tags) return copied_dataset new_elements = self.app.dataset_collections_service.apply_rules( diff --git a/lib/galaxy/tools/apply_rules.xml b/lib/galaxy/tools/apply_rules.xml index e98d2b880d1..eb31edc48a3 100644 --- a/lib/galaxy/tools/apply_rules.xml +++ b/lib/galaxy/tools/apply_rules.xml @@ -1,6 +1,6 @@ 0 + assert "group:single" in tags, tags + assert "i1" in tags, tags + + +def check_example_6(hdca, dataset_populator): + assert hdca["collection_type"] == "list" + assert hdca["element_count"] == 3 + i1_element = hdca["elements"][0] + assert "object" in i1_element, hdca + assert "element_identifier" in i1_element + assert i1_element["element_identifier"] == "i1", hdca + tags = i1_element["object"]["tags"] + assert len(tags) == 2 + assert "random" in tags + assert "group:type:single" in tags EXAMPLE_1 = { @@ -208,3 +241,110 @@ EXAMPLE_4 = { "check": check_example_4, "output_hid": 8, } + + +EXAMPLE_5 = { + "rules": { + "rules": [ + { + "type": "add_column_metadata", + "value": "identifier0", + }, + { + "type": "add_column_group_tag_value", + "value": "type", + "default_value": "unused" + } + ], + "mapping": [ + { + "type": "list_identifiers", + "columns": [1, 0], + }, + { + "type": "group_tags", + "columns": [1], + }, + { + "type": "tags", + "columns": [0], + }, + ], + }, + "test_data": { + "type": "list", + "elements": [ + { + "identifier": "i1", + "contents": "0", + "class": "File", + "tags": ["random", "group:type:single"] + }, + { + "identifier": "i2", + "contents": "1", + "class": "File", + "tags": ["random", "group:type:paired"] + }, + { + "identifier": "i3", + "contents": "2", + "class": "File", + "tags": ["random", "group:type:paired"] + }, + ] + }, + "check": check_example_5, + "output_hid": 8, +} + + +EXAMPLE_6 = { + "rules": { + "rules": [ + { + "type": "add_column_metadata", + "value": "identifier0", + }, + { + "type": "add_column_metadata", + "value": "tags", + } + ], + "mapping": [ + { + "type": "list_identifiers", + "columns": [0], + }, + { + "type": "tags", + "columns": [1], + }, + ], + }, + "test_data": { + "type": "list", + "elements": [ + { + "identifier": "i1", + "contents": "0", + "class": "File", + "tags": ["random", "group:type:single"] + }, + { + "identifier": "i2", + "contents": "1", + "class": "File", + "tags": ["random", "group:type:paired"] + }, + { + "identifier": "i3", + "contents": "2", + "class": "File", + "tags": ["random", "group:type:paired"] + }, + ] + }, + "check": check_example_6, + "output_hid": 8, +}