Merge pull request #3381 from jmchilton/rename_improvements

Test cases & small enhancement to workflow renaming PJAs.
This commit is contained in:
Björn Grüning
2017-01-08 14:07:20 +01:00
committed by GitHub
7 changed files with 208 additions and 11 deletions
+9
View File
@@ -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
+4 -4
View File
@@ -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
+1 -2
View File
@@ -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(
+5 -1
View File
@@ -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,
+155 -4
View File
@@ -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" )
@@ -0,0 +1,33 @@
<tool id="mapper2" name="mapper2" version="0.1.0">
<command>
cp $__tool_directory__/1.bam $out_file1
</command>
<inputs>
<!-- Conditional input block loosely based on bwa-mem. -->
<conditional name="fastq_input">
<param name="fastq_input_selector" type="select" label="Single or Paired-end reads">
<option value="paired">Paired</option>
<option value="single">Single</option>
<option value="paired_collection">Paired Collection</option>
<option value="paired_iv">Paired Interleaved</option>
</param>
<when value="paired">
<param name="fastq_input1" type="data" format="fastq" label="Select first set of reads" />
<param name="fastq_input2" type="data" format="fastq" label="Select second set of reads" />
</when>
<when value="single">
<param name="fastq_input1" type="data" format="fastq" label="Select fastq dataset"/>
</when>
<when value="paired_collection">
<param name="fastq_input1" format="fastq" type="data_collection" collection_type="paired" label="Select a paired collection" />
</when>
<when value="paired_iv">
<param name="fastq_input1" type="data" format="fastq" label="Select fastq dataset" />
</when>
</conditional>
<param name="reference" type="data" format="fasta" label="Fasta Input"/>
</inputs>
<outputs>
<data name="out_file1" format="bam" />
</outputs>
</tool>
@@ -114,6 +114,7 @@
<tool file="for_workflows/cat_interleave.xml" />
<tool file="for_workflows/pileup.xml" />
<tool file="for_workflows/mapper.xml" />
<tool file="for_workflows/mapper2.xml" />
<tool file="for_workflows/split.xml" />
<tool file="for_workflows/create_input_collection.xml" />