Mercurial > repos > crs4 > edge_pro
view edge_pro.py @ 1:f77ce4f92b46 draft
Use $GALAXY_SLOTS instead of $EDGE_PRO_SITE_OPTIONS. Add dependency on bowtie2. Add readme.rst .
author | crs4 |
---|---|
date | Fri, 31 Jan 2014 05:44:03 -0500 |
parents | 7af33315bc5e |
children | bad8a51514dd |
line wrap: on
line source
# -*- coding: utf-8 -*- """ Wrapper for EDGE - Gene expression in Prokaryotes Author: Paolo Uva paolo dot uva at crs4 dot it Date: March 18, 2013 """ import glob import optparse import os import shutil import subprocess import tempfile import sys def __main__(): # Parse Command Line parser = optparse.OptionParser() # Input parser.add_option('-g', '--genome', dest="genome") parser.add_option('-p', '--ptt', dest="ptt") parser.add_option('-r', '--rnt', dest="rnt") parser.add_option('-u', '--input1', dest="input1") parser.add_option('-v', '--input2', dest="input2") parser.add_option('-t', '--num-threads', dest="num_threads", type='int') parser.add_option('-m', '--minInsertSize', dest="minInsertSize", type='int') parser.add_option('-M', '--maxInsertSize', dest="maxInsertSize", type='int') parser.add_option('-w', '--window', dest="window", type='int') parser.add_option('-i', '--utrSize', dest="utrSize", type='int') parser.add_option('-x', '--similarity', dest="similarity", type='float') parser.add_option('-c', '--minCoverage', dest="minCoverage", type='int') parser.add_option('-l', '--readLength', dest="readLength", type='int') # Output parser.add_option('--out-aln', dest="out_aln") parser.add_option('--out-rpkm', dest="out_rpkm") parser.add_option('--out-log', dest="out_log") (options, args) = parser.parse_args() if len(args) > 0: parser.error('Wrong number of arguments') # Build command input2_flag = '-v %s' % (options.input2) if options.input2 else '' num_threads_flag = '-t %d' % options.num_threads if options.num_threads is not None else '' minInsertSize_flag = '-m %d' % options.minInsertSize if options.minInsertSize is not None else '' maxInsertSize_flag = '-M %d' % options.maxInsertSize if options.maxInsertSize is not None else '' window_flag = '-w %d' % options.window if options.window is not None else '' utrSize_flag = '-i %d' % options.utrSize if options.utrSize is not None else '' similarity_flag = '-x %s' % options.similarity if options.similarity is not None else '' readLength_flag = '-l %d' % (options.readLength) if options.readLength is not None else '' minCoverage_flag = '-c %d' % options.minCoverage if options.minCoverage is not None else '' wd = tempfile.mkdtemp() try: prefix = os.path.join(wd, 'out') cl = 'edge.pl -g %s -p %s -r %s -u %s -o %s %s %s %s %s %s %s %s %s %s' % (options.genome, options.ptt, options.rnt, options.input1, prefix, input2_flag, num_threads_flag, minInsertSize_flag, maxInsertSize_flag, window_flag, utrSize_flag, similarity_flag, readLength_flag, minCoverage_flag) print "EDGE-pro command to be executed:\n %s" % (cl) sout = open(options.out_log, 'w') if options.out_log else sys.stdout try: subprocess.check_call(cl, stdout=sout, stderr=subprocess.STDOUT, shell=True) # need to redirect stderr because edge.pl calls bowtie2 and count which write some logging info there finally: if sout != sys.stdout: sout.close() # Move alignment file shutil.move(prefix + '.alignments', options.out_aln) # Concatenate multiple RPKM files together with open(options.out_rpkm, 'wb') as destination: for filename in glob.iglob(prefix + '.rpkm_*'): with open(filename, 'rb') as source: shutil.copyfileobj(source, destination) finally: shutil.rmtree(wd) if __name__ == "__main__": __main__()