# HG changeset patch # User devteam # Date 1486510782 18000 # Node ID 1707a530e598e335728f903750cb2e5fcd1953a7 # Parent 8160c8ea4eb9957826380cf0b7f3461e940bff71 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cuffmerge commit eb18f691975ef9539b5ebd4f118343c8ad967a1f diff -r 8160c8ea4eb9 -r 1707a530e598 cuff_macros.xml --- a/cuff_macros.xml Wed Nov 11 12:35:04 2015 -0500 +++ b/cuff_macros.xml Tue Feb 07 18:39:42 2017 -0500 @@ -1,11 +1,13 @@ 2.2.1 + cufflinks + @@ -26,21 +28,21 @@ - + - + - + - + @@ -48,16 +50,16 @@ #if $in_type.set_in_type in ['BAM', 'CXB'] #for $condition in $in_type.conditions: #set samples = ','.join( [ str( $sample ) for $sample in $condition.samples ] ) - $samples + '$samples' #end for #elif $in_type.set_in_type == 'CONDITION_LIST' #for $sample in $in_type.conditions: - $sample + '$sample' #end for #elif $in_type.set_in_type == 'CONDITION_REPLICATE_LIST' #for $condition_list in $in_type.conditions: #set samples = ','.join( [ str( $sample ) for $sample in $condition_list ] ) - $samples + '$samples' #end for #end if @@ -79,11 +81,11 @@ ## Inputs. #for $input_file in $inputs: - "${input_file}" + '${input_file}' #end for #for $additional_input in $additional_inputs: #for $input_file in $additional_input.additional_inputs: - "${input_file}" + '${input_file}' #end for #end for diff -r 8160c8ea4eb9 -r 1707a530e598 cuffmerge_wrapper.py --- a/cuffmerge_wrapper.py Wed Nov 11 12:35:04 2015 -0500 +++ b/cuffmerge_wrapper.py Tue Feb 07 18:39:42 2017 -0500 @@ -1,67 +1,71 @@ #!/usr/bin/env python -import optparse, os, shutil, subprocess, sys, tempfile +import optparse +import os +import shutil +import subprocess +import sys +import tempfile -def stop_err( msg ): - sys.stderr.write( '%s\n' % msg ) + +def stop_err(msg): + sys.stderr.write('%s\n' % msg) sys.exit() + def __main__(): - #Parse Command Line parser = optparse.OptionParser() - parser.add_option( '-g', dest='ref_annotation', help='An optional "reference" annotation GTF. Each sample is matched against this file, and sample isoforms are tagged as overlapping, matching, or novel where appropriate. See the refmap and tmap output file descriptions below.' ) - parser.add_option( '-s', dest='use_seq_data', action="store_true", help='Causes cuffmerge to look into for fasta files with the underlying genomic sequences (one file per contig) against which your reads were aligned for some optional classification functions. For example, Cufflinks transcripts consisting mostly of lower-case bases are classified as repeats. Note that must contain one fasta file per reference chromosome, and each file must be named after the chromosome, and have a .fa or .fasta extension.') - parser.add_option( '-p', '--num-threads', dest='num_threads', help='Use this many threads to align reads. The default is 1.' ) - + parser.add_option('-g', dest='ref_annotation', help='An optional "reference" annotation GTF. Each sample is matched against this file, and sample isoforms are tagged as overlapping, matching, or novel where appropriate. See the refmap and tmap output file descriptions below.') + parser.add_option('-s', dest='use_seq_data', action="store_true", help='Causes cuffmerge to look into for fasta files with the underlying genomic sequences (one file per contig) against which your reads were aligned for some optional classification functions. For example, Cufflinks transcripts consisting mostly of lower-case bases are classified as repeats. Note that must contain one fasta file per reference chromosome, and each file must be named after the chromosome, and have a .fa or .fasta extension.') + parser.add_option('-p', '--num-threads', dest='num_threads', help='Use this many threads to align reads. The default is 1.') + # Wrapper / Galaxy options. - parser.add_option( '', '--index', dest='index', help='The path of the reference genome' ) - parser.add_option( '', '--ref_file', dest='ref_file', help='The reference dataset from the history' ) - + parser.add_option('', '--index', dest='index', help='The path of the reference genome') + parser.add_option('', '--ref_file', dest='ref_file', help='The reference dataset from the history') + # Outputs. - parser.add_option( '', '--merged-transcripts', dest='merged_transcripts' ) - parser.add_option( '--min-isoform-fraction', dest='min_isoform_fraction' ) - + parser.add_option('', '--merged-transcripts', dest='merged_transcripts') + parser.add_option('--min-isoform-fraction', dest='min_isoform_fraction') + (options, args) = parser.parse_args() - + # output version # of tool try: - tmp = tempfile.NamedTemporaryFile().name - tmp_stdout = open( tmp, 'wb' ) - proc = subprocess.Popen( args='cuffmerge -v 2>&1', shell=True, stdout=tmp_stdout ) - tmp_stdout.close() - returncode = proc.wait() - stdout = None - for line in open( tmp_stdout.name, 'rb' ): - if line.lower().find( 'merge_cuff_asms v' ) >= 0: - stdout = line.strip() - break + with tempfile.NamedTemporaryFile() as tmp_stdout: + returncode = subprocess.call(args='cuffmerge -v 2>&1', stdout=tmp_stdout, shell=True) + stdout = None + with open(tmp_stdout.name) as tmp_stdout2: + for line in tmp_stdout2: + if line.lower().find('merge_cuff_asms v') >= 0: + stdout = line.strip() + break if stdout: - sys.stdout.write( '%s\n' % stdout ) + sys.stdout.write('%s\n' % stdout) else: raise Exception except: - sys.stdout.write( 'Could not determine Cuffmerge version\n' ) - + sys.stdout.write('Could not determine Cuffmerge version\n') + # Set/link to sequence file. if options.use_seq_data: if options.ref_file: # Sequence data from history. # Create symbolic link to ref_file so that index will be created in working directory. seq_path = "ref.fa" - os.symlink( options.ref_file, seq_path ) + os.symlink(options.ref_file, seq_path) else: - if not os.path.exists( options.index ): - stop_err( 'Reference genome %s not present, request it by reporting this error.' % options.index ) + if not os.path.exists(options.index): + stop_err('Reference genome %s not present, request it by reporting this error.' % options.index) seq_path = options.index - + # Build command. - + # Base. cmd = "cuffmerge -o cm_output " - + # Add options. if options.num_threads: - cmd += ( " -p %i " % int ( options.num_threads ) ) + cmd += (" -p %i " % int(options.num_threads)) if options.ref_annotation: cmd += " -g %s " % options.ref_annotation if options.use_seq_data: @@ -69,48 +73,39 @@ if options.min_isoform_fraction: cmd += " --min-isoform-fraction %s " % (options.min_isoform_fraction) # Add input files to a file. - inputs_file_name = tempfile.NamedTemporaryFile( dir="." ).name - inputs_file = open( inputs_file_name, 'w' ) - for arg in args: - inputs_file.write( arg + "\n" ) - inputs_file.close() - cmd += inputs_file_name + with tempfile.NamedTemporaryFile(mode='w', dir=".", delete=False) as inputs_file: + for arg in args: + inputs_file.write(arg + "\n") + cmd += inputs_file.name - # Debugging. - print cmd - # Run command. - try: - tmp_name = tempfile.NamedTemporaryFile( dir="." ).name - tmp_stderr = open( tmp_name, 'wb' ) - proc = subprocess.Popen( args=cmd, shell=True, stderr=tmp_stderr.fileno() ) - returncode = proc.wait() - tmp_stderr.close() - - # Get stderr, allowing for case where it's very large. - tmp_stderr = open( tmp_name, 'rb' ) - stderr = '' - buffsize = 1048576 - try: - while True: - stderr += tmp_stderr.read( buffsize ) - if not stderr or len( stderr ) % buffsize != 0: - break - except OverflowError: - pass - tmp_stderr.close() - - # Error checking. - if returncode != 0: - raise Exception, stderr - - if len( open( "cm_output/merged.gtf", 'rb' ).read().strip() ) == 0: - raise Exception, 'The output file is empty, there may be an error with your input file or settings.' - + try: + with tempfile.NamedTemporaryFile(dir=".") as tmp_stderr: + returncode = subprocess.call(args=cmd, stderr=tmp_stderr, shell=True) + + # Error checking. + if returncode != 0: + # Get stderr, allowing for case where it's very large. + buffsize = 1048576 + stderr = '' + with open(tmp_stderr.name, 'r') as tmp_stderr2: + try: + while True: + stderr += tmp_stderr2.read(buffsize) + if not stderr or len(stderr) % buffsize != 0: + break + except OverflowError: + pass + raise Exception(stderr) + + if len(open("cm_output/merged.gtf", 'r').read().strip()) == 0: + raise Exception('The output file is empty, there may be an error with your input file or settings.') + # Copy outputs. - shutil.copyfile( "cm_output/merged.gtf" , options.merged_transcripts ) - - except Exception, e: - stop_err( 'Error running cuffmerge. ' + str( e ) ) - -if __name__=="__main__": __main__() + shutil.move("cm_output/merged.gtf", options.merged_transcripts) + except Exception as e: + stop_err('Error running cuffmerge: %s' % e) + + +if __name__ == "__main__": + __main__() diff -r 8160c8ea4eb9 -r 1707a530e598 cuffmerge_wrapper.xml --- a/cuffmerge_wrapper.xml Wed Nov 11 12:35:04 2015 -0500 +++ b/cuffmerge_wrapper.xml Tue Feb 07 18:39:42 2017 -0500 @@ -1,33 +1,33 @@ merge together several Cufflinks assemblies - - cuff_macros.xml - - cuffmerge_wrapper.py + + + + python '$__tool_directory__/cuffmerge_wrapper.py' --num-threads="\${GALAXY_SLOTS:-4}" ## Use annotation reference? #if $annotation.use_ref_annotation == "Yes": - -g "${annotation.reference_annotation}" + -g '${annotation.reference_annotation}' #end if ## Use sequence data? #if $seq_data.use_seq_data == "Yes": -s #if $seq_data.seq_source.index_source == "history": - --ref_file="${seq_data.seq_source.ref_file}" + --ref_file '${seq_data.seq_source.ref_file}' #else: - --index="${seq_data.seq_source.index.fields.path}" + --index '${seq_data.seq_source.index.fields.path}' #end if #end if --min-isoform-fraction="${min_isoform_fraction}" ## Outputs. - --merged-transcripts="${merged_transcripts}" + --merged-transcripts '${merged_transcripts}' @CUFFLINKS_GTF_INPUTS@