0
|
1 #!/usr/bin/env python
|
|
2 #Version 1.01 - bugs kindly corrected by Jan van Haarst
|
|
3 import pkg_resources
|
|
4 import logging, os, string, sys, tempfile, glob, shutil, types, urllib
|
|
5 import shlex, subprocess
|
|
6 from optparse import OptionParser, OptionGroup
|
|
7 from stat import *
|
|
8
|
|
9
|
|
10 log = logging.getLogger( __name__ )
|
|
11
|
|
12 assert sys.version_info[:2] >= ( 2, 4 )
|
|
13
|
|
14 def stop_err( msg ):
|
|
15 sys.stderr.write( "%s\n" % msg )
|
|
16 sys.exit()
|
|
17
|
|
18 def __main__():
|
|
19 #Parse Command Line
|
|
20 s = 'assembly_stats_txt.py: argv = %s\n' % (sys.argv)
|
|
21 argcnt = len(sys.argv)
|
|
22 html_file = sys.argv[1]
|
|
23 working_dir = sys.argv[2]
|
|
24 type = sys.argv[3]
|
|
25 bucket = sys.argv[4]
|
|
26 input = sys.argv[5]
|
|
27 stats = sys.argv[6]
|
|
28 sortedcontigs = sys.argv[7]
|
|
29 histogrampng = sys.argv[8]
|
|
30 summedcontigspng = sys.argv[9]
|
|
31 histogramdata = sys.argv[10]
|
|
32 summedcontigdata = sys.argv[11]
|
|
33 try: # for test - needs this done
|
|
34 os.makedirs(working_dir)
|
|
35 except Exception, e:
|
|
36 stop_err( 'Error running assembly_stats_txt.py ' + str( e ) )
|
|
37
|
|
38
|
|
39 cmdline = '%s/fasta_summary.pl -i %s -t %s %s -o %s > /dev/null' % (os.path.dirname(sys.argv[0]),input, type, bucket, working_dir)
|
|
40 try:
|
|
41 proc = subprocess.Popen( args=cmdline, shell=True, stderr=subprocess.PIPE )
|
|
42 returncode = proc.wait()
|
|
43 # get stderr, allowing for case where it's very large
|
|
44 stderr = ''
|
|
45 buffsize = 1048576
|
|
46 try:
|
|
47 while True:
|
|
48 stderr += proc.stderr.read( buffsize )
|
|
49 if not stderr or len( stderr ) % buffsize != 0:
|
|
50 break
|
|
51 except OverflowError:
|
|
52 pass
|
|
53 if returncode != 0:
|
|
54 raise Exception, stderr
|
|
55 except Exception, e:
|
|
56 stop_err( 'Error running assembly_stats.py ' + str( e ) )
|
|
57
|
|
58 stats_path = os.path.join(working_dir,'stats.txt')
|
|
59 sorted_contigs_path = os.path.join(working_dir,'sorted_contigs.fa')
|
|
60 histogram_png_path = os.path.join(working_dir,'histogram_bins.dat.png')
|
|
61 summed_contigs_path = os.path.join(working_dir,'summed_contig_lengths.dat.png')
|
|
62 histogram_data_path = os.path.join(working_dir,'histogram_bins.dat')
|
|
63 summed_contigs_data_path = os.path.join(working_dir,'summed_contig_lengths.dat')
|
|
64
|
|
65 out = open(stats,'w')
|
|
66 for line in open( stats_path ):
|
|
67 out.write( "%s" % (line) )
|
|
68 out.close()
|
|
69
|
|
70 out = open(sortedcontigs,'w')
|
|
71 for line in open(sorted_contigs_path ):
|
|
72 out.write( "%s" % (line) )
|
|
73 out.close()
|
|
74
|
|
75 out = open(histogrampng,'w')
|
|
76 for line in open(histogram_png_path ):
|
|
77 out.write( "%s" % (line) )
|
|
78 out.close()
|
|
79
|
|
80 out = open(summedcontigspng,'w')
|
|
81 for line in open(summed_contigs_path ):
|
|
82 out.write( "%s" % (line) )
|
|
83 out.close()
|
|
84
|
|
85
|
|
86 out = open(histogramdata,'w')
|
|
87 for line in open(histogram_data_path ):
|
|
88 out.write( "%s" % (line) )
|
|
89 out.close()
|
|
90
|
|
91 out = open(summedcontigdata,'w')
|
|
92 for line in open(summed_contigs_data_path ):
|
|
93 out.write( "%s" % (line) )
|
|
94 out.close()
|
|
95
|
|
96
|
|
97
|
|
98
|
|
99
|
|
100
|
|
101
|
|
102
|
|
103
|
|
104 # rval = ['<html><head><title>Assembly stats Galaxy Composite Dataset </title></head><p/>']
|
|
105 # rval.append('<div>%s<p/></div>' % (cmdline) )
|
|
106 # rval.append('<div>This composite dataset is composed of the following files:<p/><ul>')
|
|
107 # rval.append( '<li><a href="%s" type="text/plain">%s </a>%s</li>' % (stats_path,'stats.txt','stats.txt' ) )
|
|
108 # rval.append( '<li><a href="%s" type="text/plain">%s </a>%s</li>' % (sorted_contigs_path,'sorted_contigs.fa','sorted_contigs.fa' ) )
|
|
109 # rval.append( '<li><a href="%s" type="image/png">%s </a>%s</li>' % (histogram_png_path,'histogram_bins.dat.png','histogram_bins.dat.png' ) )
|
|
110 # rval.append( '<li><a href="%s" type="image/png">%s </a>%s</li>' % (summed_contigs_path,'summed_contig_lengths.dat.png','summed_contig_lengths.dat.png' ) )
|
|
111 # rval.append( '<li><a href="%s" type="text/plain">%s </a>%s</li>' % (histogram_data_path,'histogram_bins.dat','histogram_bins.dat' ) )
|
|
112 # rval.append( '<li><a href="%s" type="text/plain">%s </a>%s</li>' % (summed_contigs_data_path,'summed_contig_lengths.dat','summed_contig_lengths.dat' ) )
|
|
113
|
|
114
|
|
115 #
|
|
116 # rval.append( '</ul></div></html>' )
|
|
117 # f = file(html_file,'w')
|
|
118 # f.write("\n".join( rval ))
|
|
119 # f.write('\n')
|
|
120 # f.close()
|
|
121
|
|
122 if __name__ == "__main__": __main__()
|