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