Skip to content

Commit

Permalink
Allow composite datatypes of type auto_primary_file to automatically …
Browse files Browse the repository at this point in the history
…generate primary datatype for standard (non-upload) jobs when the tool does not already create the file.
  • Loading branch information
blankenberg committed Feb 21, 2017
1 parent cdb15f6 commit 9abe8a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/galaxy/datatypes/data.py
Expand Up @@ -594,8 +594,8 @@ def substitute_composite_key( key, composite_file ):
files[ substitute_composite_key( key, value ) ] = value
return files

def generate_auto_primary_file( self, dataset=None ):
raise Exception( "generate_auto_primary_file is not implemented for this datatype." )
def generate_primary_file( self, dataset=None ):
raise Exception( "generate_primary_file is not implemented for this datatype." )

@property
def has_resolution(self):
Expand Down
11 changes: 11 additions & 0 deletions lib/galaxy/jobs/__init__.py
Expand Up @@ -15,6 +15,7 @@
import traceback
from abc import ABCMeta, abstractmethod
from json import loads
from tempfile import NamedTemporaryFile
from xml.etree import ElementTree

import six
Expand Down Expand Up @@ -1321,6 +1322,16 @@ def finish(
dataset.info = dataset.info.rstrip() + "\n" + context['stderr'].strip()
dataset.tool_version = self.version_string
dataset.set_size()
# Handle composite datatypes of auto_primary_file type
if dataset.datatype.composite_type == 'auto_primary_file' and not dataset.has_data():
try:
with NamedTemporaryFile() as temp_fh:
temp_fh.write( dataset.datatype.generate_primary_file( dataset ) )
temp_fh.flush()
self.app.object_store.update_from_file( dataset.dataset, file_name=temp_fh.name, create=True )
dataset.set_size()
except Exception as e:
log.warning( 'Unable to generate primary composite file automatically for %s: %s', dataset.dataset.id, e )
if 'uuid' in context:
dataset.dataset.uuid = context['uuid']
# Update (non-library) job output datasets through the object store
Expand Down

0 comments on commit 9abe8a7

Please sign in to comment.