commit/galaxy-central: jgoecks: Trackster: add support for including a global model when running tools in Trackster. This is done by using a new HiddenDataToolParameter and implementing 'set parameter' actions in a tool's trackster configuration. Cufflinks now uses a global model to produce correct output when run in Trackster.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/356e8b9510a9/ changeset: 356e8b9510a9 user: jgoecks date: 2011-12-21 23:04:23 summary: Trackster: add support for including a global model when running tools in Trackster. This is done by using a new HiddenDataToolParameter and implementing 'set parameter' actions in a tool's trackster configuration. Cufflinks now uses a global model to produce correct output when run in Trackster. affected #: 6 files diff -r 38fcdb8f0e63a8430bb80bac4500ad4faa7a4115 -r 356e8b9510a965d09226c450746dfa2ba267a42c lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -29,6 +29,7 @@ from cgi import FieldStorage from galaxy.util.hash_util import * from galaxy.util import listify +from galaxy.visualization.tracks.visual_analytics import TracksterConfig log = logging.getLogger( __name__ ) @@ -567,7 +568,11 @@ # Determine if this tool can be used in workflows self.is_workflow_compatible = self.check_workflow_compatible() # Trackster configuration. - self.trackster_conf = ( root.find( "trackster_conf" ) is not None ) + trackster_conf = root.find( "trackster_conf" ) + if trackster_conf: + self.trackster_conf = TracksterConfig.parse( trackster_conf ) + else: + self.trackster_conf = None def parse_inputs( self, root ): """ diff -r 38fcdb8f0e63a8430bb80bac4500ad4faa7a4115 -r 356e8b9510a965d09226c450746dfa2ba267a42c lib/galaxy/tools/parameters/basic.py --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -1549,6 +1549,22 @@ if call_attribute: ref = ref() return ref + +class HiddenDataToolParameter( HiddenToolParameter, DataToolParameter ): + """ + Hidden parameter that behaves as a DataToolParameter. As with all hidden + parameters, this is a HACK. + """ + def __init__( self, tool, elem ): + DataToolParameter.__init__( self, tool, elem ) + self.value = "None" + + def get_initial_value( self, trans, context ): + return None + + def get_html_field( self, trans=None, value=None, other_values={} ): + return form_builder.HiddenField( self.name, self.value ) + class LibraryDatasetToolParameter( ToolParameter ): """ @@ -1644,6 +1660,7 @@ select = SelectToolParameter, data_column = ColumnListParameter, hidden = HiddenToolParameter, + hidden_data = HiddenDataToolParameter, baseurl = BaseURLToolParameter, file = FileToolParameter, ftpfile = FTPFileToolParameter, diff -r 38fcdb8f0e63a8430bb80bac4500ad4faa7a4115 -r 356e8b9510a965d09226c450746dfa2ba267a42c lib/galaxy/visualization/tracks/visual_analytics.py --- a/lib/galaxy/visualization/tracks/visual_analytics.py +++ b/lib/galaxy/visualization/tracks/visual_analytics.py @@ -3,6 +3,31 @@ from galaxy.tools.parameters.basic import IntegerToolParameter, FloatToolParameter, SelectToolParameter from galaxy.tools.parameters.dynamic_options import DynamicOptions +class TracksterConfig: + """ Trackster configuration encapsulation. """ + + def __init__( self, actions ): + self.actions = actions + + @staticmethod + def parse( root ): + actions = [] + for action_elt in root.findall( "action" ): + actions.append( SetParamAction.parse( action_elt ) ) + return TracksterConfig( actions ) + +class SetParamAction: + """ Set parameter action. """ + + def __init__( self, name, output_name ): + self.name = name + self.output_name = output_name + + @staticmethod + def parse( elt ): + """ Parse action from element. """ + return SetParamAction( elt.get( "name" ), elt.get( "output_name" ) ) + def get_dataset_job( hda ): # Get dataset's job. job = None diff -r 38fcdb8f0e63a8430bb80bac4500ad4faa7a4115 -r 356e8b9510a965d09226c450746dfa2ba267a42c lib/galaxy/web/controllers/tracks.py --- a/lib/galaxy/web/controllers/tracks.py +++ b/lib/galaxy/web/controllers/tracks.py @@ -824,7 +824,7 @@ return to_json_string( msg ) # - # Set tool parameters--except dataset parameters--using combination of + # Set tool parameters--except non-hidden dataset parameters--using combination of # job's previous parameters and incoming parameters. Incoming parameters # have priority. # @@ -872,15 +872,10 @@ else: target_history = trans.get_history( create=True ) hda_permissions = trans.app.security_agent.history_get_default_permissions( target_history ) - - # - # Set input datasets for tool. If running on region, extract and use subset - # when possible. - # def set_param_value( param_dict, param_name, param_value ): """ - Set new parameter value in a parameter dictionary. + Set new parameter value in a tool's parameter dictionary. """ # Recursive function to set param value. @@ -913,8 +908,30 @@ group_index = int( group[ index + 1: ] ) return set_value( param_dict, group_name, group_index, param_name, param_value ) - + + # Set parameters based tool's trackster config. + params_set = {} + for action in tool.trackster_conf.actions: + success = False + for joda in original_job.output_datasets: + if joda.name == action.output_name: + set_param_value( tool_params, action.name, joda.dataset ) + params_set[ action.name ] = True + success = True + break + + if not success: + return messages.ERROR + + # + # Set input datasets for tool. If running on region, extract and use subset + # when possible. + # for jida in original_job.input_datasets: + # If param set previously by config actions, do nothing. + if jida.name in params_set: + continue + input_dataset = jida.dataset if input_dataset is None: #optional dataset and dataset wasn't selected tool_params[ jida.name ] = None diff -r 38fcdb8f0e63a8430bb80bac4500ad4faa7a4115 -r 356e8b9510a965d09226c450746dfa2ba267a42c tools/ngs_rna/cufflinks_wrapper.py --- a/tools/ngs_rna/cufflinks_wrapper.py +++ b/tools/ngs_rna/cufflinks_wrapper.py @@ -1,6 +1,8 @@ #!/usr/bin/env python import optparse, os, shutil, subprocess, sys, tempfile +from galaxy import eggs +from galaxy.datatypes.util.gff_util import parse_gff_attributes, gff_attributes_to_str def stop_err( msg ): sys.stderr.write( "%s\n" % msg ) @@ -51,6 +53,9 @@ parser.add_option( '', '--index_dir', dest='index_dir', help='GALAXY_DATA_INDEX_DIR' ) parser.add_option( '', '--ref_file', dest='ref_file', help='The reference dataset from the history' ) + # Global model. + parser.add_option( '', '--global_model', dest='global_model_file', help='Global model used for computing on local data' ) + (options, args) = parser.parse_args() # output version # of tool @@ -122,7 +127,9 @@ # Add input files. cmd += " " + options.input + # # Run command. + # try: tmp_name = tempfile.NamedTemporaryFile( dir="." ).name tmp_stderr = open( tmp_name, 'wb' ) @@ -130,7 +137,60 @@ returncode = proc.wait() tmp_stderr.close() - # Get stderr, allowing for case where it's very large. + # Read standard error to get total map mass. + total_map_mass = -1 + tmp_stderr = open( tmp_name, 'r' ) + for line in tmp_stderr: + if line.lower().find( "total map mass") >= 0: + total_map_mass = float( line.split(":")[1].strip() ) + break + tmp_stderr.close() + + # + # If there's a global model provided, use model's total map mass + # to adjust FPKM + confidence intervals. + # + if options.global_model_file: + # Global model is simply total map mass from original run. + global_model_file = open( options.global_model_file, 'r' ) + global_model_total_map_mass = float( global_model_file.readline() ) + global_model_file.close() + + # Ratio of global model's total map mass to original run's map mass is + # factor used to adjust FPKM. + fpkm_map_mass_ratio = total_map_mass / global_model_total_map_mass + + # Update FPKM values in transcripts.gtf file. + transcripts_file = open( "transcripts.gtf", 'r' ) + tmp_transcripts = tempfile.NamedTemporaryFile( dir="." ).name + new_transcripts_file = open( tmp_transcripts, 'w' ) + for line in transcripts_file: + fields = line.split( '\t' ) + attrs = parse_gff_attributes( fields[8] ) + attrs[ "FPKM" ] = str( float( attrs[ "FPKM" ] ) * fpkm_map_mass_ratio ) + attrs[ "conf_lo" ] = str( float( attrs[ "conf_lo" ] ) * fpkm_map_mass_ratio ) + attrs[ "conf_hi" ] = str( float( attrs[ "conf_hi" ] ) * fpkm_map_mass_ratio ) + fields[8] = gff_attributes_to_str( attrs, "GTF" ) + new_transcripts_file.write( "%s\n" % '\t'.join( fields ) ) + transcripts_file.close() + new_transcripts_file.close() + shutil.copyfile( tmp_transcripts, "transcripts.gtf" ) + + # TODO: update expression files as well. + + # Set outputs. Transcript and gene expression handled by wrapper directives. + shutil.copyfile( "transcripts.gtf" , options.assembled_isoforms_output_file ) + if total_map_mass > -1: + f = open( "global_model.txt", 'w' ) + f.write( "%f\n" % total_map_mass ) + f.close() + + # Error checking. + if returncode != 0: + raise Exception, stderr + except Exception, e: + raise e + # Read stderr so that it can be reported: tmp_stderr = open( tmp_name, 'rb' ) stderr = '' buffsize = 1048576 @@ -142,14 +202,7 @@ except OverflowError: pass tmp_stderr.close() - - # Copy outputs. - shutil.copyfile( "transcripts.gtf" , options.assembled_isoforms_output_file ) - # Error checking. - if returncode != 0: - raise Exception, stderr - except Exception, e: stop_err( 'Error running cufflinks. ' + str( e ) ) if __name__=="__main__": __main__() diff -r 38fcdb8f0e63a8430bb80bac4500ad4faa7a4115 -r 356e8b9510a965d09226c450746dfa2ba267a42c tools/ngs_rna/cufflinks_wrapper.xml --- a/tools/ngs_rna/cufflinks_wrapper.xml +++ b/tools/ngs_rna/cufflinks_wrapper.xml @@ -43,6 +43,11 @@ --dbkey=${input.metadata.dbkey} --index_dir=${GALAXY_DATA_INDEX_DIR} #end if + + ## Include global model if available. + #if $global_model: + --global_model=$global_model + #end if </command><inputs><param format="sam,bam" name="input" type="data" label="SAM or BAM file of aligned RNA-Seq reads" help=""/> @@ -97,15 +102,20 @@ <param name="inner_distance_std_dev" type="integer" value="20" label="Standard Deviation for Inner Distance between Mate Pairs"/></when></conditional> + <param name="global_model" type="hidden_data" label="Global model (for use in Trackster)" optional="True"/></inputs><outputs><data format="tabular" name="genes_expression" label="${tool.name} on ${on_string}: gene expression" from_work_dir="genes.fpkm_tracking"/><data format="tabular" name="transcripts_expression" label="${tool.name} on ${on_string}: transcript expression" from_work_dir="isoforms.fpkm_tracking"/><data format="gtf" name="assembled_isoforms" label="${tool.name} on ${on_string}: assembled transcripts"/> + <data format="txt" name="total_map_mass" label="${tool.name} on ${on_string}: total map mass" hidden="true" from_work_dir="global_model.txt"/></outputs> - <trackster_conf/> + <trackster_conf> + <action type="set_param" name="global_model" output_name="total_map_mass"/> + </trackster_conf> + <tests><!-- Simple test that uses test data included with cufflinks. Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
Bitbucket