[STABLE] Revise re-run mapping of datasets and collections for imported and copied history items. The previous method (from tool_runner.py) had difficulties with consistently hashing history items which caused issues for imported datasets. We fixed that, however now datasets copied back to the same history are shown instead of the original dataset.

This commit is contained in:
guerler
2015-04-03 11:46:17 -04:00
parent acd67001f8
commit 3bca8799b5
+37 -26
View File
@@ -2590,28 +2590,44 @@ class Tool( object, Dictifiable ):
# dataset used; parameter should be the analygous dataset in the
# current history.
history = trans.get_history()
hda_source_dict = {} # Mapping from HDA in history to source HDAs.
# Create index for hdas.
hda_source_dict = {}
for hda in history.datasets:
source_hda = hda.copied_from_history_dataset_association
while source_hda:
if source_hda.dataset.id not in hda_source_dict or source_hda.hid == hda.hid:
hda_source_dict[ source_hda.dataset.id ] = hda
source_hda = source_hda.copied_from_history_dataset_association
key = '%s_%s' % (hda.hid, hda.dataset.id)
hda_source_dict[ hda.dataset.id ] = hda_source_dict[ key ] = hda
# Ditto for dataset collections.
hdca_source_dict = {}
for hdca in history.dataset_collections:
source_hdca = hdca.copied_from_history_dataset_collection_association
while source_hdca:
if source_hdca.collection.id not in hdca_source_dict or source_hdca.hid == hdca.hid:
hdca_source_dict[ source_hdca.collection.id ] = hdca
source_hdca = source_hdca.copied_from_history_dataset_collection_association
key = '%s_%s' % (hdca.hid, hdca.collection.id)
hdca_source_dict[ hda.collection.id ] = hdca_source_dict[ key ] = hdca
# Map dataset or collection to current history
def map_to_history(value):
id = None
source = None
if isinstance(value, trans.app.model.HistoryDatasetAssociation):
id = value.dataset.id
source = hda_source_dict
elif isinstance(value, trans.app.model.HistoryDatasetCollectionAssociation):
id = value.collection.id
source = hdca_source_dict
else:
return None
key = '%s_%s' % (value.hid, id)
if key in source:
return source[ key ]
elif id in source:
return source[ id ]
else:
return None
# Unpack unvalidated values to strings, they'll be validated when the
# form is submitted (this happens when re-running a job that was
# initially run by a workflow)
#This needs to be done recursively through grouping parameters
def rerun_callback( input, value, prefixed_name, prefixed_label ):
def mapping_callback( input, value, prefixed_name, prefixed_label ):
if isinstance( value, UnvalidatedValue ):
try:
return input.to_html_value( value.value, trans.app )
@@ -2623,22 +2639,17 @@ class Tool( object, Dictifiable ):
if isinstance(value,list):
values = []
for val in value:
if isinstance(val, trans.app.model.HistoryDatasetAssociation):
if val.dataset.id in hda_source_dict:
values.append( hda_source_dict[ val.dataset.id ] )
else:
values.append( val )
new_val = map_to_history( val )
if new_val:
values.append( new_val )
else:
values.append( val )
return values
if isinstance(value, trans.app.model.HistoryDatasetAssociation):
if value.dataset.id in hda_source_dict:
return hda_source_dict[ value.dataset.id ]
if isinstance(value, trans.app.model.HistoryDatasetCollectionAssociation):
if value.collection.id in hdca_source_dict:
return hdca_source_dict[ value.collection.id ]
else:
return map_to_history( value )
elif isinstance( input, DataCollectionToolParameter ):
if value.collection.id in hdca_source_dict:
return hdca_source_dict[ value.collection.id ]
visit_input_values( tool_inputs, params, rerun_callback )
return map_to_history( value )
visit_input_values( tool_inputs, params, mapping_callback )
def _compare_tool_version( self, trans, job ):
"""