Skip to content

Commit

Permalink
Add ability to have a directory of files associated with an individua…
Browse files Browse the repository at this point in the history
…l dataset. Relative links in html work.

Put all desired files in the directory specified in a tool XML as $output.files_path.
Example:
<command interpreter="python">script.py $input $output $output.files_path</command>
becomes:
python ./tools/filters/script.py ./database/files/dataset_1.dat ./database/files/dataset_2.dat ./database/tmp/dataset_2_files
Any file put in ./database/tmp/dataset_2_files will be accessable to html files using a relative link.

Directories are moved to a more permanent location only if they contain files.
  • Loading branch information
blankenberg committed Aug 6, 2007
1 parent 84ef484 commit 1aecfdb
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/galaxy/jobs/__init__.py
Expand Up @@ -286,6 +286,8 @@ def finish( self, stdout, stderr ):
out_data = dict( [ ( da.name, da.dataset ) for da in job.output_datasets ] )
param_dict = dict( [ ( p.name, p.value ) for p in job.parameters ] )
param_dict = self.tool.params_from_strings( param_dict, self.app )
# Check for and move associated_files
self.tool.collect_associated_files(out_data)
# Create generated output children and primary datasets and add to param_dict
collected_datasets = {'children':self.tool.collect_child_datasets(out_data),'primary':self.tool.collect_primary_datasets(out_data)}
param_dict.update({'__collected_datasets__':collected_datasets})
Expand Down
2 changes: 2 additions & 0 deletions lib/galaxy/model/__init__.py
Expand Up @@ -278,6 +278,8 @@ def purge( self ):
self.purged = True
try: os.unlink(self.file_name)
except: pass
try: os.unlink(os.path.join(self.file_path, "dataset_%d_files" % (self.id)))
except: pass
def get_converter_types(self):
return self.datatype.get_converter_types( self, datatypes_registry)
def add_validation_error( self, validation_error ):
Expand Down
16 changes: 14 additions & 2 deletions lib/galaxy/tools/__init__.py
Expand Up @@ -778,6 +778,8 @@ def wrap_values( inputs, input_values ):
param_dict[ key ] = DatasetFilenameWrapper( child )
for name, data in output_datasets.items():
param_dict[name] = DatasetFilenameWrapper( data )
# Provide access to a path to store additional files
param_dict[name].files_path = os.path.join(self.app.config.new_file_path, "dataset_%s_files" % (data.id) )
for child_association in data.children:
child = child_association.child
key = "_CHILD___%s___%s" % ( name, child.designation )
Expand Down Expand Up @@ -860,8 +862,18 @@ def call_hook( self, hook_name, *args, **kwargs ):
return code( *args, **kwargs )
except Exception, e:
e.args = ( "Error in '%s' hook '%s', original message: %s" % ( self.name, hook_name, e.args[0] ) )
raise

raise

def collect_associated_files( self, output):
for name, outdata in output.items():
temp_file_path = os.path.join(self.app.config.new_file_path, "dataset_%s_files" % (outdata.id) )
try:
if len(os.listdir(temp_file_path)) > 0:
store_file_path = os.path.join(self.app.config.file_path, "dataset_%s_files" % (outdata.id) )
shutil.move(temp_file_path, store_file_path)
except:
continue

def collect_child_datasets( self, output):
children = {}
#Loop through output file names, looking for generated children in form of 'child_parentId_designation_visibility_extension'
Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/web/buildapp.py
Expand Up @@ -47,6 +47,7 @@ def app_factory( global_conf, **kwargs ):
webapp.add_route( '/async/:tool_id/:data_id/:data_secret', controller='async', action='index', tool_id=None, data_id=None, data_secret=None )
webapp.add_route( '/:controller/:action', action='index' )
webapp.add_route( '/:action', controller='root', action='index' )
webapp.add_route( '/datasets/:dataset_id/:action/:filename', controller='dataset', action='index', dataset_id=None, filename=None)
webapp.finalize_config()
# Wrap the webapp in some useful middleware
if kwargs.get( 'middleware', True ):
Expand Down
36 changes: 35 additions & 1 deletion lib/galaxy/web/controllers/dataset.py
Expand Up @@ -10,6 +10,10 @@
import smtplib
from email.MIMEText import MIMEText

import pkg_resources;
pkg_resources.require( "Paste" )
import paste.httpexceptions

log = logging.getLogger( __name__ )

error_report_template = """
Expand Down Expand Up @@ -82,4 +86,34 @@ def report_error( self, trans, id, email="no email provided", message="" ):
s.close()
return trans.show_ok_message( "Your error report has been sent" )
except:
return trans.show_error_message( "An error occurred sending the report by email" )
return trans.show_error_message( "An error occurred sending the report by email" )

@web.expose
def default(self, trans, dataset_id=None, **kwd):
return 'This link may not be followed from within Galaxy.'

@web.expose
def display(self, trans, dataset_id=None, filename=None, **kwd):
"""Catches the dataset id and displays file contents as directed"""
if filename is None or filename.lower() == "index":
try:
data = trans.app.model.Dataset.get( dataset_id )
if data:
mime = trans.app.datatypes_registry.get_mimetype_by_extension( data.extension.lower() )
trans.response.set_content_type(mime)
trans.log_event( "Display dataset id: %s" % str(dataset_id) )
try:
return open( data.file_name )
except:
return "This item contains no content"
except:
pass
return "Invalid dataset specified"
else:
#display files from directory here
try:
file_path = os.path.join(trans.app.config.file_path, "dataset_%s_files" % (dataset_id))
file_path = os.path.join(file_path, filename)
return open(file_path)
except:
raise paste.httpexceptions.HTTPNotFound( "File Not Found (%s)." % (filename) )
2 changes: 1 addition & 1 deletion templates/dataset_code.tmpl
Expand Up @@ -111,7 +111,7 @@
</td>
<td>
<div>
<div style="float: right;"><a href="$h.url_for( 'display', id=data.id )" target="_top"><img src="$h.url_for('/static/images/eye_icon.png')" rollover="$h.url_for('/static/images/eye_icon_dark.png')" width='16' height='16' alt='display data' title='display data' class='displayButton' border='0'></a>
<div style="float: right;"><a href="/datasets/$data.id/display/index" target="_top"><img src="$h.url_for('/static/images/eye_icon.png')" rollover="$h.url_for('/static/images/eye_icon_dark.png')" width='16' height='16' alt='display data' title='display data' class='displayButton' border='0'></a>
<a href="edit?id=$data.id" target="galaxy_main"><img src="$h.url_for('/static/images/pencil_icon.png')" rollover="$h.url_for('/static/images/pencil_icon_dark.png')" width='16' height='16' alt='edit attributes' title='edit attributes' class='editButton' border='0'></a>
<a href="delete?id=$data.id" class="historyItemDelete" id="historyItemDelter-${data.id}"><img src="$h.url_for('/static/images/delete_icon.png')" rollover="$h.url_for('/static/images/delete_icon_dark.png')" width='16' height='16' alt='delete' class='deleteButton' border='0'></a>
<!--
Expand Down
2 changes: 1 addition & 1 deletion templates/history.tmpl
Expand Up @@ -179,7 +179,7 @@ div#footer {
</td>
<td>
<div>
<div style="float: right;"><a href="$h.url_for( 'display', id=data.id )" target="_top"><img src="$h.url_for('/static/images/eye_icon.png')" rollover="$h.url_for('/static/images/eye_icon_dark.png')" width='16' height='16' alt='display data' title='display data' class='displayButton' border='0'></a>
<div style="float: right;"><a href="/datasets/$data.id/display/index" target="_top"><img src="$h.url_for('/static/images/eye_icon.png')" rollover="$h.url_for('/static/images/eye_icon_dark.png')" width='16' height='16' alt='display data' title='display data' class='displayButton' border='0'></a>
<a href="edit?id=$data.id" target="galaxy_main"><img src="$h.url_for('/static/images/pencil_icon.png')" rollover="$h.url_for('/static/images/pencil_icon_dark.png')" width='16' height='16' alt='edit attributes' title='edit attributes' class='editButton' border='0'></a>
<a href="delete?id=$data.id" class="historyItemDelete" id="historyItemDelter-${data.id}"><img src="$h.url_for('/static/images/delete_icon.png')" rollover="$h.url_for('/static/images/delete_icon_dark.png')" width='16' height='16' alt='delete' class='deleteButton' border='0'></a>
<!--
Expand Down

0 comments on commit 1aecfdb

Please sign in to comment.