Allow the Apply Rules tool to attach tags to output datasets.

This commit is contained in:
John Chilton
2020-10-08 15:23:40 -04:00
parent 65718c9d30
commit 6c96d187d9
6 changed files with 169 additions and 5 deletions
+2 -2
View File
@@ -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"),
+17 -1
View File
@@ -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
+3 -1
View File
@@ -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(
+1 -1
View File
@@ -1,6 +1,6 @@
<tool id="__APPLY_RULES__"
name="Apply Rule to Collection"
version="1.0.0"
version="1.1.0"
tool_type="apply_rules_to_collection">
<type class="ApplyRulesTool" module="galaxy.tools" />
<action module="galaxy.tools.actions.model_operations"
+6
View File
@@ -553,6 +553,12 @@ class ToolsTestCase(ApiTestCase, TestsTools):
def test_apply_rules_4(self):
self._apply_rules_and_check(rules_test_data.EXAMPLE_4)
def test_apply_rules_5(self):
self._apply_rules_and_check(rules_test_data.EXAMPLE_5)
def test_apply_rules_6(self):
self._apply_rules_and_check(rules_test_data.EXAMPLE_6)
@skip_without_tool("multi_select")
def test_multi_select_as_list(self):
with self.dataset_populator.test_history() as history_id:
+140
View File
@@ -37,6 +37,39 @@ def check_example_4(hdca, dataset_populator):
assert "object" in i1_element, hdca
assert "element_identifier" in i1_element
assert i1_element["element_identifier"] == "i1", hdca
assert len(i1_element["object"]["tags"]) == 0
def check_example_5(hdca, dataset_populator):
assert hdca["collection_type"] == "list:list"
assert hdca["element_count"] == 2
first_collection_level = hdca["elements"][0]
assert first_collection_level["element_identifier"] == "single", hdca
assert first_collection_level["element_type"] == "dataset_collection"
second_collection_level = first_collection_level["object"]
assert "elements" in second_collection_level, hdca
assert len(second_collection_level["elements"]) == 1, hdca
i1_element = second_collection_level["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) > 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,
}