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