diff --git a/config/tool_conf.xml.sample b/config/tool_conf.xml.sample index 2f039985374..b8b98a82d77 100644 --- a/config/tool_conf.xml.sample +++ b/config/tool_conf.xml.sample @@ -37,6 +37,7 @@ +
diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index e442812a3e9..686c4e6e8a5 100755 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -2555,11 +2555,49 @@ class RelabelFromFileTool(DatabaseOperationTool): ) +class FilterFromFileTool(DatabaseOperationTool): + tool_type = 'filter_from_file' + + def produce_outputs(self, trans, out_data, output_collections, incoming, history): + hdca = incoming["input"] + how_filter = incoming["how"]["how_filter"] + filter_dataset_assoc = incoming["how"]["filter_source"] + filtered_elements = odict() + discarded_elements = odict() + + filtered_path = filter_dataset_assoc.file_name + filtered_identifiers_raw = open(filtered_path, "r").readlines(1024 * 1000000) + filtered_identifiers = [i.strip() for i in filtered_identifiers_raw] + + # If filtered_dataset_assoc is not a two-column tabular dataset we label with the current line of the dataset + for i, dce in enumerate(hdca.collection.elements): + dce_object = dce.element_object + element_identifier = dce.element_identifier + in_filter_file = element_identifier in filtered_identifiers + passes_filter = in_filter_file if how_filter == "remove_if_absent" else not in_filter_file + + copied_value = dce_object.copy() + if getattr(copied_value, "history_content_type", None) == "dataset": + history.add_dataset(copied_value, set_hid=False) + + if passes_filter: + filtered_elements[element_identifier] = copied_value + else: + discarded_elements[element_identifier] = copied_value + + output_collections.create_collection( + self.outputs["output_filtered"], "output_filtered", elements=filtered_elements + ) + output_collections.create_collection( + self.outputs["output_discarded"], "output_discarded", elements=discarded_elements + ) + + # Populate tool_type to ToolClass mappings tool_types = {} for tool_class in [ Tool, SetMetadataTool, OutputParameterJSONTool, DataManagerTool, DataSourceTool, AsyncDataSourceTool, - UnzipCollectionTool, ZipCollectionTool, MergeCollectionTool, RelabelFromFileTool, + UnzipCollectionTool, ZipCollectionTool, MergeCollectionTool, RelabelFromFileTool, FilterFromFileTool, DataDestinationTool ]: tool_types[ tool_class.tool_type ] = tool_class diff --git a/lib/galaxy/tools/filter_from_file.xml b/lib/galaxy/tools/filter_from_file.xml new file mode 100644 index 00000000000..6dbb28277a4 --- /dev/null +++ b/lib/galaxy/tools/filter_from_file.xml @@ -0,0 +1,91 @@ + + from contents of a file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/galaxy/tools/relabel_from_file.xml b/lib/galaxy/tools/relabel_from_file.xml index ca806b3b5ec..797e647819a 100644 --- a/lib/galaxy/tools/relabel_from_file.xml +++ b/lib/galaxy/tools/relabel_from_file.xml @@ -131,7 +131,10 @@ - + + ]]> diff --git a/test-data/filter_labels_1.txt b/test-data/filter_labels_1.txt new file mode 100644 index 00000000000..928f40b2d21 --- /dev/null +++ b/test-data/filter_labels_1.txt @@ -0,0 +1 @@ +i2 diff --git a/test/functional/tools/samples_tool_conf.xml b/test/functional/tools/samples_tool_conf.xml index 35a1480f817..415766d0603 100644 --- a/test/functional/tools/samples_tool_conf.xml +++ b/test/functional/tools/samples_tool_conf.xml @@ -147,5 +147,6 @@ +