Mercurial > repos > konradpaszkiewicz > oasesoptimiser
comparison oases_optimiser.py @ 0:53e887dda799 default tip
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
author | konradpaszkiewicz |
---|---|
date | Tue, 07 Jun 2011 17:41:37 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:53e887dda799 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 """ | |
4 VelvetOptimiser Wrapper | |
5 Adapted from velveth and velvetg tools in Galaxy | |
6 Konrad Paszkiewicz University of Exeter, UK. | |
7 | |
8 """ | |
9 import pkg_resources; | |
10 import logging, os, string, sys, tempfile, glob, shutil, types, urllib | |
11 import shlex, subprocess | |
12 from optparse import OptionParser, OptionGroup | |
13 from stat import * | |
14 | |
15 | |
16 log = logging.getLogger( __name__ ) | |
17 | |
18 assert sys.version_info[:2] >= ( 2, 4 ) | |
19 | |
20 def stop_err( msg ): | |
21 sys.stderr.write( "%s\n" % msg ) | |
22 sys.exit() | |
23 | |
24 def __main__(): | |
25 #Parse Command Line | |
26 s = 'oases_optimiser.py: argv = %s\n' % (sys.argv) | |
27 #print >> sys.stderr, s # so will appear as blurb for file | |
28 argcnt = len(sys.argv) | |
29 starthash = sys.argv[1] | |
30 endhash = sys.argv[2] | |
31 inputs = sys.argv[3] | |
32 contigs = sys.argv[4] | |
33 LastGraph = sys.argv[5] | |
34 afgFile = sys.argv[6] | |
35 unused_reads_fasta = sys.argv[7] | |
36 stats = sys.argv[8] | |
37 othervelvetgoptions = sys.argv[9] | |
38 otheroasesoptions = sys.argv[10] | |
39 transcripts = sys.argv[11] | |
40 splicingevents = sys.argv[12] | |
41 contigordering = sys.argv[13] | |
42 #contigs.extra_files_path | |
43 | |
44 | |
45 working_dir = '' | |
46 | |
47 cmdline = '/users/galaxy/galaxyscripts/oases_optimiser.sh %s %s \'%s\' %s %s 2&1>/dev/null' % (starthash, endhash, inputs, othervelvetgoptions, otheroasesoptions) | |
48 #print >> sys.stderr, cmdline # so will appear as blurb for file | |
49 try: | |
50 proc = subprocess.Popen( args=cmdline, shell=True, stderr=subprocess.PIPE ) | |
51 returncode = proc.wait() | |
52 # get stderr, allowing for case where it's very large | |
53 stderr = '' | |
54 buffsize = 1048576 | |
55 try: | |
56 while True: | |
57 stderr += proc.stderr.read( buffsize ) | |
58 if not stderr or len( stderr ) % buffsize != 0: | |
59 break | |
60 except OverflowError: | |
61 pass | |
62 if returncode != 0: | |
63 raise Exception, stderr | |
64 except Exception, e: | |
65 stop_err( 'Error running oases_optimiser.py' + str( e ) ) | |
66 out = open(transcripts,'w') | |
67 transcript_path = os.path.join(working_dir,'transcripts.fa') | |
68 #print >> sys.stderr, path | |
69 for line in open(transcript_path): | |
70 out.write( "%s" % (line) ) | |
71 out.close() | |
72 | |
73 out = open(splicingevents,'w') | |
74 path = os.path.join(working_dir,'splicing_events.txt') | |
75 #print >> sys.stderr, contigs_path | |
76 for line in open(path ): | |
77 out.write( "%s" % (line) ) | |
78 out.close() | |
79 | |
80 | |
81 | |
82 out = open(contigs,'w') | |
83 contigs_path = os.path.join(working_dir,'contigs.fa') | |
84 #print >> sys.stderr, contigs_path | |
85 for line in open(contigs_path ): | |
86 out.write( "%s" % (line) ) | |
87 out.close() | |
88 out = open(stats,'w') | |
89 stats_path = os.path.join(working_dir,'stats.txt') | |
90 for line in open( stats_path ): | |
91 out.write( "%s" % (line) ) | |
92 out.close() | |
93 if LastGraph != 'None': | |
94 out = open(LastGraph,'w') | |
95 LastGraph_path = os.path.join(working_dir,'LastGraph') | |
96 for line in open( LastGraph_path ): | |
97 out.write( "%s" % (line) ) | |
98 out.close() | |
99 if afgFile != 'None': | |
100 out = open(afgFile,'w') | |
101 afgFile_path = os.path.join(working_dir,'oases_asm.afg') | |
102 try: | |
103 for line in open( afgFile_path ): | |
104 out.write( "%s" % (line) ) | |
105 except: | |
106 logging.warn( 'error reading %s' %(afgFile_path)) | |
107 pass | |
108 out.close() | |
109 if unused_reads_fasta != 'None': | |
110 out = open(unused_reads_fasta,'w') | |
111 unused_reads_fasta_path = os.path.join(working_dir,'UnusedReads.fa') | |
112 try: | |
113 for line in open( unused_reads_fasta_path ): | |
114 out.write( "%s" % (line) ) | |
115 except: | |
116 logging.info( 'error reading %s' %(unused_reads_fasta_path)) | |
117 pass | |
118 out.close() | |
119 | |
120 if __name__ == "__main__": __main__() |