Mercurial > repos > xuebing > sharplabtool
comparison tools/sr_assembly/velvetg_wrapper.py @ 0:9071e359b9a3
Uploaded
author | xuebing |
---|---|
date | Fri, 09 Mar 2012 19:37:19 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9071e359b9a3 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 """ | |
4 Classes encapsulating decypher tool. | |
5 James E Johnson - University of Minnesota | |
6 """ | |
7 import pkg_resources; | |
8 import logging, os, string, sys, tempfile, glob, shutil, types, urllib | |
9 import shlex, subprocess | |
10 from optparse import OptionParser, OptionGroup | |
11 from stat import * | |
12 | |
13 | |
14 log = logging.getLogger( __name__ ) | |
15 | |
16 assert sys.version_info[:2] >= ( 2, 4 ) | |
17 | |
18 def stop_err( msg ): | |
19 sys.stderr.write( "%s\n" % msg ) | |
20 sys.exit() | |
21 | |
22 def __main__(): | |
23 #Parse Command Line | |
24 s = 'velvetg_wrapper.py: argv = %s\n' % (sys.argv) | |
25 # print >> sys.stderr, s # so will appear as blurb for file | |
26 argcnt = len(sys.argv) | |
27 working_dir = sys.argv[1] | |
28 contigs = sys.argv[2] | |
29 stats = sys.argv[3] | |
30 LastGraph = sys.argv[4] | |
31 afgFile = sys.argv[5] | |
32 unusedReadsFile = sys.argv[6] | |
33 inputs = string.join(sys.argv[7:],' ') | |
34 cmdline = 'velvetg %s %s > /dev/null' % (working_dir, inputs) | |
35 # print >> sys.stderr, cmdline # so will appear as blurb for file | |
36 try: | |
37 proc = subprocess.Popen( args=cmdline, shell=True, stderr=subprocess.PIPE ) | |
38 returncode = proc.wait() | |
39 # get stderr, allowing for case where it's very large | |
40 stderr = '' | |
41 buffsize = 1048576 | |
42 try: | |
43 while True: | |
44 stderr += proc.stderr.read( buffsize ) | |
45 if not stderr or len( stderr ) % buffsize != 0: | |
46 break | |
47 except OverflowError: | |
48 pass | |
49 if returncode != 0: | |
50 raise Exception, stderr | |
51 except Exception, e: | |
52 stop_err( 'Error running velvetg ' + str( e ) ) | |
53 out = open(contigs,'w') | |
54 contigs_path = os.path.join(working_dir,'contigs.fa') | |
55 for line in open( contigs_path ): | |
56 out.write( "%s" % (line) ) | |
57 out.close() | |
58 out = open(stats,'w') | |
59 stats_path = os.path.join(working_dir,'stats.txt') | |
60 for line in open( stats_path ): | |
61 out.write( "%s" % (line) ) | |
62 out.close() | |
63 if LastGraph != 'None': | |
64 out = open(LastGraph,'w') | |
65 LastGraph_path = os.path.join(working_dir,'LastGraph') | |
66 for line in open( LastGraph_path ): | |
67 out.write( "%s" % (line) ) | |
68 out.close() | |
69 if afgFile != 'None': | |
70 out = open(afgFile,'w') | |
71 afgFile_path = os.path.join(working_dir,'velvet_asm.afg') | |
72 try: | |
73 for line in open( afgFile_path ): | |
74 out.write( "%s" % (line) ) | |
75 except: | |
76 logging.warn( 'error reading %s' %(afgFile_path)) | |
77 pass | |
78 out.close() | |
79 if unusedReadsFile != 'None': | |
80 out = open(unusedReadsFile,'w') | |
81 unusedReadsFile_path = os.path.join(working_dir,'UnusedReads.fa') | |
82 try: | |
83 for line in open( unusedReadsFile_path ): | |
84 out.write( "%s" % (line) ) | |
85 except: | |
86 logging.info( 'error reading %s' %(unusedReadsFile_path)) | |
87 pass | |
88 out.close() | |
89 | |
90 if __name__ == "__main__": __main__() |