Skip to content

Commit

Permalink
Switch tag tool to use select and add remove mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Feb 6, 2018
1 parent fd37350 commit e306a44
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
2 changes: 1 addition & 1 deletion config/tool_conf.xml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
<tool file="${model_tools_path}/filter_failed_collection.xml" />
<tool file="${model_tools_path}/flatten_collection.xml" />
<tool file="${model_tools_path}/merge_collection.xml" />
<tool file="${model_tools_path}/tag_collection_from_file.xml" />
<tool file="${model_tools_path}/relabel_from_file.xml" />
<tool file="${model_tools_path}/filter_from_file.xml" />
<tool file="${model_tools_path}/sort_collection_list.xml" />
<tool file="${model_tools_path}/tag_collection_from_file.xml" />
</section>
<section id="liftOver" name="Lift-Over">
<tool file="extract/liftOver_wrapper.xml" />
Expand Down
16 changes: 11 additions & 5 deletions lib/galaxy/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2611,7 +2611,7 @@ class TagFromFileTool(DatabaseOperationTool):

def produce_outputs(self, trans, out_data, output_collections, incoming, history, **kwds):
hdca = incoming["input"]
set_tags = incoming['set_tags']
how = incoming['how']
new_tags_dataset_assoc = incoming["tags"]
new_elements = odict()
tags_manager = GalaxyTagManager(trans.app.model.context)
Expand All @@ -2624,10 +2624,13 @@ def add_copied_value_to_new_elements(new_tags_dict, dce):
history.add_dataset(copied_value, copied_value, set_hid=False)
new_tags = new_tags_dict.get(dce.element_identifier)
if new_tags:
if not set_tags and dce.element_object.tags:
if how in ('add', 'remove') and dce.element_object.tags:
# We need get the original tags and update them with the new tags
old_tags = set(tag for tag in tags_manager.get_tags_str(dce.element_object.tags).split(',') if tag)
old_tags.update(set(new_tags))
if how == 'add':
old_tags.update(set(new_tags))
elif how == 'remove':
old_tags = old_tags - set(new_tags)
new_tags = old_tags
tags_manager.add_tags_from_list(user=history.user, item=copied_value, new_tags_list=new_tags)
else:
Expand All @@ -2638,10 +2641,13 @@ def add_copied_value_to_new_elements(new_tags_dict, dce):
# don't set `visible` to `False` if you don't hide the original elements.
new_element.element_object.visible = False
new_tags = new_tags_dict.get(new_element.element_identifier)
if not set_tags:
if how in ('add', 'remove'):
old_tags = set(tag for tag in tags_manager.get_tags_str(old_element.element_object.tags).split(',') if tag)
if new_tags:
old_tags.update(set(new_tags))
if how == 'add':
old_tags.update(set(new_tags))
elif how == 'remove':
old_tags = old_tags - set(new_tags)
new_tags = old_tags
tags_manager.add_tags_from_list(user=history.user, item=new_element.element_object, new_tags_list=new_tags)
new_elements[dce.element_identifier] = copied_value
Expand Down
52 changes: 29 additions & 23 deletions lib/galaxy/tools/tag_collection_from_file.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
class="ModelOperationToolAction"/>
<inputs>
<param type="data_collection" name="input" label="Input Collection" help="A tabular file indicating how to tag collection elements."/>
<param type="data" name="tags" format="tabular" label="Add tags from this file" />
<param name="set_tags" type="boolean" label="Set tags instead of updating tags?" help="If you select yes existing tags will be removed, otherwise new tags and existing tags will be merged."/>
<param type="data" name="tags" format="tabular" label="Tag collection elements according to this file"/>
<param name="how" type="select" label="How should the tags be updated">
<option value="add">New tags will be added, existing tags will be kept</option>
<option value="set">New tags will be added, existing tags will be removed</option>
<option value="remove">The tags listed will be removed</option>
</param>
</inputs>
<outputs>
<collection name="output" format_source="input" type_source="input" label="${on_string} (Tagged)" >
Expand All @@ -24,18 +28,19 @@
</collection>
</param>
<param name="tags" value="new_tags_1.txt" ftype="txt" />
<param name="how" value="add"/>
<output_collection name="output" type="list">
<element name="forward">
<assert_contents>
<has_text_matching expression="^This is a line of text.\n$" />
</assert_contents>
<metadata name="tags" value="alias:r1,orientation:forward" />
<assert_contents>
<has_text_matching expression="^This is a line of text.\n$" />
</assert_contents>
<metadata name="tags" value="alias:r1,orientation:forward" />
</element>
<element name="reverse">
<assert_contents>
<has_text_matching expression="^This is a different line of text.\n$" />
</assert_contents>
<metadata name="tags" value="alias:r2,orientation:reverse" />
<assert_contents>
<has_text_matching expression="^This is a different line of text.\n$" />
</assert_contents>
<metadata name="tags" value="alias:r2,orientation:reverse" />
</element>
</output_collection>
</test>
Expand All @@ -50,22 +55,23 @@
</element>
</collection>
</param>
<param name="how" value="set"/>
<param name="tags" value="new_tags_1.txt" ftype="txt" />
<output_collection name="output" type="list:paired">
<element name="i1">
<element name="forward">
<assert_contents>
<has_text_matching expression="^This is a line of text.\n$" />
</assert_contents>
<metadata name="tags" value="alias:r1,orientation:forward" />
</element>
<element name="reverse">
<assert_contents>
<has_text_matching expression="^This is a different line of text.\n$" />
</assert_contents>
<metadata name="tags" value="alias:r2,orientation:reverse" />
<element name="i1">
<element name="forward">
<assert_contents>
<has_text_matching expression="^This is a line of text.\n$" />
</assert_contents>
<metadata name="tags" value="alias:r1,orientation:forward" />
</element>
<element name="reverse">
<assert_contents>
<has_text_matching expression="^This is a different line of text.\n$" />
</assert_contents>
<metadata name="tags" value="alias:r2,orientation:reverse" />
</element>
</element>
</element>
</output_collection>
</test>
</tests>
Expand Down

0 comments on commit e306a44

Please sign in to comment.