diff --git a/lib/galaxy/jobs/actions/post.py b/lib/galaxy/jobs/actions/post.py index 00309452c8b..dfab700ba66 100644 --- a/lib/galaxy/jobs/actions/post.py +++ b/lib/galaxy/jobs/actions/post.py @@ -142,6 +142,15 @@ class RenameDatasetAction(DefaultJobAction): if input_assoc.name == input_file_var: replacement = input_assoc.dataset.name + # Ditto for collections... + for input_assoc in job.input_dataset_collections: + if input_assoc.name == input_file_var: + if input_assoc.dataset_collection: + hdca = input_assoc.dataset_collection + replacement = hdca.name + + # In case name was None. + replacement = replacement or '' # Do operations on replacement # Any control that is not defined will be ignored. # This should be moved out to a class or module function diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 08dd0e5d733..60a0578c323 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -593,8 +593,8 @@ class Job( object, JobLike, Dictifiable ): def add_output_dataset( self, name, dataset ): self.output_datasets.append( JobToOutputDatasetAssociation( name, dataset ) ) - def add_input_dataset_collection( self, name, dataset ): - self.input_dataset_collections.append( JobToInputDatasetCollectionAssociation( name, dataset ) ) + def add_input_dataset_collection( self, name, dataset_collection ): + self.input_dataset_collections.append( JobToInputDatasetCollectionAssociation( name, dataset_collection ) ) def add_output_dataset_collection( self, name, dataset_collection_instance ): self.output_dataset_collection_instances.append( JobToOutputDatasetCollectionAssociation( name, dataset_collection_instance ) ) @@ -924,9 +924,9 @@ class JobToOutputDatasetAssociation( object ): class JobToInputDatasetCollectionAssociation( object ): - def __init__( self, name, dataset ): + def __init__( self, name, dataset_collection ): self.name = name - self.dataset = dataset + self.dataset_collection = dataset_collection # Many jobs may map to one HistoryDatasetCollection using these for a given diff --git a/lib/galaxy/model/mapping.py b/lib/galaxy/model/mapping.py index 28dba680878..25f1f3006b3 100644 --- a/lib/galaxy/model/mapping.py +++ b/lib/galaxy/model/mapping.py @@ -2026,8 +2026,7 @@ mapper( model.JobToOutputDatasetAssociation, model.JobToOutputDatasetAssociation mapper( model.JobToInputDatasetCollectionAssociation, model.JobToInputDatasetCollectionAssociation.table, properties=dict( job=relation( model.Job ), dataset_collection=relation( model.HistoryDatasetCollectionAssociation, - lazy=False, - backref="dependent_jobs" ) + lazy=False ) ) ) mapper( model.JobToOutputDatasetCollectionAssociation, model.JobToOutputDatasetCollectionAssociation.table, properties=dict( diff --git a/test/api/helpers.py b/test/api/helpers.py index a4276a010cf..36b93024889 100644 --- a/test/api/helpers.py +++ b/test/api/helpers.py @@ -349,7 +349,7 @@ class LibraryPopulator( object ): class BaseDatasetCollectionPopulator( object ): - def create_list_from_pairs( self, history_id, pairs ): + def create_list_from_pairs( self, history_id, pairs, name="Dataset Collection from pairs" ): element_identifiers = [] for i, pair in enumerate( pairs ): element_identifiers.append( dict( @@ -363,6 +363,7 @@ class BaseDatasetCollectionPopulator( object ): history_id=history_id, element_identifiers=json.dumps(element_identifiers), collection_type="list:paired", + name=name, ) return self.__create( payload ) @@ -401,6 +402,9 @@ class BaseDatasetCollectionPopulator( object ): if "element_identifiers" not in kwds: kwds[ "element_identifiers" ] = json.dumps( identifiers_func( history_id, contents=contents ) ) + if "name" not in kwds: + kwds["name"] = "Test Dataset Collection" + payload = dict( history_id=history_id, collection_type=collection_type, diff --git a/test/api/test_workflows.py b/test/api/test_workflows.py index a8d3476c1c6..c3e00526b46 100644 --- a/test/api/test_workflows.py +++ b/test/api/test_workflows.py @@ -201,12 +201,15 @@ class BaseWorkflowsApiTestCase( api.ApiTestCase, ImporterGalaxyInterface ): elements.append( ( identifier, content ) ) # TODO: make this collection_type collection_type = value["type"] + new_collection_kwds = {} + if "name" in value: + new_collection_kwds["name"] = value["name"] if collection_type == "list:paired": - hdca = self.dataset_collection_populator.create_list_of_pairs_in_history( history_id ).json() + hdca = self.dataset_collection_populator.create_list_of_pairs_in_history( history_id, **new_collection_kwds ).json() elif collection_type == "list": - hdca = self.dataset_collection_populator.create_list_in_history( history_id, contents=elements ).json() + hdca = self.dataset_collection_populator.create_list_in_history( history_id, contents=elements, **new_collection_kwds ).json() else: - hdca = self.dataset_collection_populator.create_pair_in_history( history_id, contents=elements ).json() + hdca = self.dataset_collection_populator.create_pair_in_history( history_id, contents=elements, **new_collection_kwds ).json() label_map[key] = self._ds_entry( hdca ) inputs[key] = hdca has_uploads = True @@ -214,7 +217,14 @@ class BaseWorkflowsApiTestCase( api.ApiTestCase, ImporterGalaxyInterface ): input_type = value["type"] if input_type == "File": content = read_test_data(value) - hda = self.dataset_populator.new_dataset( history_id, content=content ) + new_dataset_kwds = { + "content": content + } + if "name" in value: + new_dataset_kwds["name"] = value["name"] + if "file_type" in value: + new_dataset_kwds["file_type"] = value["file_type"] + hda = self.dataset_populator.new_dataset( history_id, **new_dataset_kwds ) label_map[key] = self._ds_entry( hda ) has_uploads = True elif input_type == "raw": @@ -1251,6 +1261,147 @@ test_data: content = self.dataset_populator.get_history_dataset_details( history_id, wait=True, assert_ok=True ) assert content[ "name" ] == "foo was replaced" + @skip_without_tool( "cat" ) + def test_run_rename_based_on_input( self ): + history_id = self.dataset_populator.new_history() + self._run_jobs(""" +class: GalaxyWorkflow +inputs: + - id: input1 +steps: + - tool_id: cat + label: first_cat + state: + input1: + $link: input1 + outputs: + out_file1: + rename: "#{input1 | basename} suffix" +test_data: + input1: + value: 1.fasta + type: File + name: fasta1 +""", history_id=history_id) + content = self.dataset_populator.get_history_dataset_details( history_id, wait=True, assert_ok=True ) + name = content[ "name" ] + assert name == "fasta1 suffix", name + + @skip_without_tool( "cat" ) + def test_run_rename_based_on_input_repeat( self ): + history_id = self.dataset_populator.new_history() + self._run_jobs(""" +class: GalaxyWorkflow +inputs: + - id: input1 + - id: input2 +steps: + - tool_id: cat + label: first_cat + state: + input1: + $link: input1 + queries: + - input2: + $link: input2 + outputs: + out_file1: + rename: "#{queries_0.input2| basename} suffix" +test_data: + input1: + value: 1.fasta + type: File + name: fasta1 + input2: + value: 1.fasta + type: File + name: fasta2 +""", history_id=history_id) + content = self.dataset_populator.get_history_dataset_details( history_id, wait=True, assert_ok=True ) + name = content[ "name" ] + assert name == "fasta2 suffix", name + + @skip_without_tool( "mapper2" ) + def test_run_rename_based_on_input_conditional( self ): + history_id = self.dataset_populator.new_history() + self._run_jobs(""" +class: GalaxyWorkflow +inputs: + - id: fasta_input + - id: fastq_input +steps: + - tool_id: mapper2 + state: + fastq_input: + fastq_input_selector: single + fastq_input1: + $link: fastq_input + reference: + $link: fasta_input + outputs: + out_file1: + # Wish it was qualified for conditionals but it doesn't seem to be. -John + # rename: "#{fastq_input.fastq_input1 | basename} suffix" + rename: "#{fastq_input1 | basename} suffix" +test_data: + fasta_input: + value: 1.fasta + type: File + name: fasta1 + file_type: fasta + fastq_input: + value: 1.fastqsanger + type: File + name: fastq1 + file_type: fastqsanger +""", history_id=history_id) + content = self.dataset_populator.get_history_dataset_details( history_id, wait=True, assert_ok=True ) + name = content[ "name" ] + assert name == "fastq1 suffix", name + + @skip_without_tool( "mapper2" ) + def test_run_rename_based_on_input_collection( self ): + history_id = self.dataset_populator.new_history() + self._run_jobs(""" +class: GalaxyWorkflow +inputs: + - id: fasta_input + - id: fastq_inputs +steps: + - tool_id: mapper2 + state: + fastq_input: + fastq_input_selector: paired_collection + fastq_input1: + $link: fastq_inputs + reference: + $link: fasta_input + outputs: + out_file1: + # Wish it was qualified for conditionals but it doesn't seem to be. -John + # rename: "#{fastq_input.fastq_input1 | basename} suffix" + rename: "#{fastq_input1} suffix" +test_data: + fasta_input: + value: 1.fasta + type: File + name: fasta1 + file_type: fasta + fastq_inputs: + type: list + name: the_dataset_pair + elements: + - identifier: forward + value: 1.fastq + type: File + - identifier: reverse + value: 1.fastq + type: File +""", history_id=history_id) + content = self.dataset_populator.get_history_dataset_details( history_id, wait=True, assert_ok=True ) + name = content[ "name" ] + assert name == "the_dataset_pair suffix", name + @skip_without_tool( "cat1" ) def test_run_with_runtime_pja( self ): workflow = self.workflow_populator.load_workflow( name="test_for_pja_runtime" ) diff --git a/test/functional/tools/for_workflows/mapper2.xml b/test/functional/tools/for_workflows/mapper2.xml new file mode 100644 index 00000000000..d3fb3b9d9a5 --- /dev/null +++ b/test/functional/tools/for_workflows/mapper2.xml @@ -0,0 +1,33 @@ + + + cp $__tool_directory__/1.bam $out_file1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/functional/tools/samples_tool_conf.xml b/test/functional/tools/samples_tool_conf.xml index ccef907c6a1..58ecb3b6f5a 100644 --- a/test/functional/tools/samples_tool_conf.xml +++ b/test/functional/tools/samples_tool_conf.xml @@ -114,6 +114,7 @@ +