Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement group: tags (toward multi-factor analysis with group tagging) #6491

Merged
merged 3 commits into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/galaxy/managers/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _append_tags(self, dataset_collection_instance, implicit_inputs=None, tags=N
tags = tags or {}
implicit_inputs = implicit_inputs or []
for _, v in implicit_inputs:
for tag in [t for t in v.tags if t.user_tname == 'name']:
for tag in v.auto_propagated_tags:
tags[tag.value] = tag
for _, tag in tags.items():
dataset_collection_instance.tags.append(tag.copy(cls=model.HistoryDatasetCollectionTagAssociation))
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/managers/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def _get_name_value_pair(self, tag_str):
"""Get name, value pair from a tag string."""
# Use regular expression to parse name, value.
reg_exp = re.compile("[" + self.key_value_separators + "]")
name_value_pair = reg_exp.split(tag_str)
name_value_pair = reg_exp.split(tag_str, 1)
# Add empty slot if tag does not have value.
if len(name_value_pair) < 2:
name_value_pair.append(None)
Expand Down
6 changes: 6 additions & 0 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
JOB_METRIC_MAX_LENGTH = 1023
JOB_METRIC_PRECISION = 26
JOB_METRIC_SCALE = 7
# Tags that get automatically propagated from inputs to outputs when running jobs.
AUTO_PROPAGATED_TAGS = ["name", "group"]


class NoConverterException(Exception):
Expand Down Expand Up @@ -128,6 +130,10 @@ def copy_tags_from(self, target_user, source):
new_tag_assoc.user = target_user
self.tags.append(new_tag_assoc)

@property
def auto_propagated_tags(self):
return [t for t in self.tags if t.user_tname in AUTO_PROPAGATED_TAGS]


class HasName(object):

Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/tools/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _collect_inputs(self, tool, trans, incoming, history, current_user_roles):
if not data:
continue

for tag in [t for t in data.tags if t.user_tname == 'name']:
for tag in data.auto_propagated_tags:
preserved_tags[tag.value] = tag

# grap tags from incoming HDCAs
Expand All @@ -215,7 +215,7 @@ def _collect_inputs(self, tool, trans, incoming, history, current_user_roles):
# if sub-collection mapping, this will be an DC not an HDCA
# (e.g. part of collection not a collection instance) and thus won't have tags.
if hasattr(collection, "tags"):
for tag in [t for t in collection.tags if t.user_tname == 'name']:
for tag in collection.auto_propagated_tags:
preserved_tags[tag.value] = tag

return history, inp_data, inp_dataset_collections, preserved_tags
Expand Down
48 changes: 48 additions & 0 deletions test/api/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,54 @@ def test_run_hide_on_mapped_over_collection(self):
assert content["history_content_type"] == "dataset_collection", content
assert not content["visible"]

@skip_without_tool("cat")
def test_tag_auto_propagation(self):
with self.dataset_populator.test_history() as history_id:
self._run_jobs("""
class: GalaxyWorkflow
inputs:
- id: input1
steps:
- label: first_cat
tool_id: cat
state:
input1:
$link: input1
outputs:
out_file1:
add_tags:
- "name:treated1fb"
- "group:condition:treated"
- "group:type:single-read"
- "machine:illumina"
- label: second_cat
tool_id: cat
state:
input1:
$link: first_cat#out_file1
test_data:
input1:
value: 1.fasta
type: File
name: fasta1
""", history_id=history_id)

details0 = self.dataset_populator.get_history_dataset_details(history_id, hid=2, wait=True, assert_ok=True)
tags = details0["tags"]
assert len(tags) == 4, details0
assert "name:treated1fb" in tags, tags
assert "group:condition:treated" in tags, tags
assert "group:type:single-read" in tags, tags
assert "machine:illumina" in tags, tags

details1 = self.dataset_populator.get_history_dataset_details(history_id, hid=3, wait=True, assert_ok=True)
tags = details1["tags"]
assert len(tags) == 3, details1
assert "name:treated1fb" in tags, tags
assert "group:condition:treated" in tags, tags
assert "group:type:single-read" in tags, tags
assert "machine:illumina" not in tags, tags

@skip_without_tool("collection_creates_pair")
def test_run_add_tag_on_collection_output(self):
with self.dataset_populator.test_history() as history_id:
Expand Down