From 9b6a9dc0c73dfc0625e55a3db4c262174bda0dff Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 13 Feb 2017 14:20:13 -0500 Subject: [PATCH] Start work on a relabelling collection operation. I think it needs to be touched up but the basic operation seems to work so far. I think what remains to be done is: - Validate uniqueness of identifiers and provide nice messages if they are not unique. - Validate that at least the required number of lines are present in the file and provide a nice message if not. - Add strict mode to ensure exactly the correct number of lines is added. - Find where validation of identifiers happens in the API and apply same validation here - try not to let unsafe identifiers be created. - Consider more advanced modes - selecting a column, apply a regex replace, pick two columns for nested lists, etc.... None of this may need to be needed in the first iteration. - Consider another mode where a collection is labelled against an existing collection - should that be a separate tool of the same tool. --- config/tool_conf.xml.sample | 1 + lib/galaxy/tools/__init__.py | 22 ++++++++- lib/galaxy/tools/relabel_from_file.xml | 53 +++++++++++++++++++++ test-data/new_labels_1.txt | 1 + test/functional/tools/samples_tool_conf.xml | 1 + 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 lib/galaxy/tools/relabel_from_file.xml create mode 100644 test-data/new_labels_1.txt diff --git a/config/tool_conf.xml.sample b/config/tool_conf.xml.sample index 3e19d92f265..2f039985374 100644 --- a/config/tool_conf.xml.sample +++ b/config/tool_conf.xml.sample @@ -36,6 +36,7 @@ +
diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index b84709615f6..94c65ed43d2 100755 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -2506,11 +2506,31 @@ class FlattenTool( DatabaseOperationTool ): ) +class RelabelFromFileTool( DatabaseOperationTool ): + tool_type = 'relabel_from_file' + + def produce_outputs( self, trans, out_data, output_collections, incoming, history ): + hdca = incoming[ "input" ] + new_labels_dataset_assoc = incoming[ "labels" ] + new_elements = odict() + log.info(new_labels_dataset_assoc) + new_labels_path = new_labels_dataset_assoc.file_name + new_labels = open(new_labels_path, "r").readlines(1024 * 1000000) + + for i, dce in enumerate(hdca.collection.elements): + dce_object = dce.element_object + new_elements[new_labels[i].strip()] = dce_object.copy() + + output_collections.create_collection( + next(iter(self.outputs.values())), "output", elements=new_elements + ) + + # Populate tool_type to ToolClass mappings tool_types = {} for tool_class in [ Tool, SetMetadataTool, OutputParameterJSONTool, DataManagerTool, DataSourceTool, AsyncDataSourceTool, - UnzipCollectionTool, ZipCollectionTool, MergeCollectionTool, + UnzipCollectionTool, ZipCollectionTool, MergeCollectionTool, RelabelFromFileTool, DataDestinationTool ]: tool_types[ tool_class.tool_type ] = tool_class diff --git a/lib/galaxy/tools/relabel_from_file.xml b/lib/galaxy/tools/relabel_from_file.xml new file mode 100644 index 00000000000..f52c9e38ef9 --- /dev/null +++ b/lib/galaxy/tools/relabel_from_file.xml @@ -0,0 +1,53 @@ + + from contents of a file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This tool will take an input list and a text file with new identifiers + and build a new list with the same datasets but these new identifiers. + + This tool will create new history datasets from your collection + but your quota usage will not increase. + + diff --git a/test-data/new_labels_1.txt b/test-data/new_labels_1.txt new file mode 100644 index 00000000000..3fe0afa80c6 --- /dev/null +++ b/test-data/new_labels_1.txt @@ -0,0 +1 @@ +new_i1 \ No newline at end of file diff --git a/test/functional/tools/samples_tool_conf.xml b/test/functional/tools/samples_tool_conf.xml index 59f76c37d1d..35a1480f817 100644 --- a/test/functional/tools/samples_tool_conf.xml +++ b/test/functional/tools/samples_tool_conf.xml @@ -146,5 +146,6 @@ +