comparison assembly_stats_txt.py @ 0:ad2b274663f8 draft

planemo upload for repository https://github.com/phac-nml/galaxy_tools commit 3f9ae719338c7c8db81d645b8ee09727e2d9ce23
author nml
date Tue, 07 Nov 2017 12:28:31 -0500
parents
children 7556309ffbaf
comparison
equal deleted inserted replaced
-1:000000000000 0:ad2b274663f8
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # Version 1.01 - bugs kindly corrected by Jan van Haarst
5 # Modified by Matthew Gopez October 13th, 2017
6
7 import logging
8 import os
9 import subprocess
10 import sys
11
12
13 log = logging.getLogger(__name__)
14
15 assert sys.version_info[:2] >= (2, 4)
16
17
18 def stop_err(msg):
19 sys.stderr.write('%s\n' % msg)
20 sys.exit()
21
22
23 def __main__():
24
25 # Parse Command Line
26
27 working_dir = sys.argv[2]
28 type = sys.argv[3]
29 bucket = sys.argv[4]
30 input = sys.argv[5]
31 stats = sys.argv[6]
32 sortedcontigs = sys.argv[7]
33 histogrampng = sys.argv[8]
34 summedcontigspng = sys.argv[9]
35 histogramdata = sys.argv[10]
36 summedcontigdata = sys.argv[11]
37 try: # for test - needs this done
38 os.makedirs(working_dir)
39 except Exception, e:
40 stop_err('Error running assembly_stats_txt.py ' + str(e))
41
42 cmdline = '%s/fasta_summary.pl -i %s -t %s %s -o %s > /dev/null' \
43 % (os.path.dirname(sys.argv[0]), input, type, bucket,
44 working_dir)
45 try:
46 proc = subprocess.Popen(args=cmdline, shell=True,
47 stderr=subprocess.PIPE)
48 returncode = proc.wait()
49
50 # get stderr, allowing for case where it's very large
51
52 stderr = ''
53 buffsize = 1048576
54 try:
55 while True:
56 stderr += proc.stderr.read(buffsize)
57 if not stderr or len(stderr) % buffsize != 0:
58 break
59 except OverflowError:
60 pass
61 if returncode != 0:
62 raise Exception
63 except Exception, e:
64 stop_err('Error running assembly_stats.py ' + str(e))
65
66 stats_path = os.path.join(working_dir, 'stats.txt')
67 sorted_contigs_path = os.path.join(working_dir, 'sorted_contigs.fa')
68 histogram_png_path = os.path.join(working_dir,
69 'histogram_bins.dat.png')
70 summed_contigs_path = os.path.join(working_dir,
71 'summed_contig_lengths.dat.png')
72 histogram_data_path = os.path.join(working_dir, 'histogram_bins.dat')
73 summed_contigs_data_path = os.path.join(working_dir,
74 'summed_contig_lengths.dat')
75
76 out = open(stats, 'w')
77 for line in open(stats_path):
78 out.write('%s' % line)
79 out.close()
80
81 out = open(sortedcontigs, 'w')
82 for line in open(sorted_contigs_path):
83 out.write('%s' % line)
84 out.close()
85
86 out = open(histogrampng, 'w')
87 for line in open(histogram_png_path):
88 out.write('%s' % line)
89 out.close()
90
91 out = open(summedcontigspng, 'w')
92 for line in open(summed_contigs_path):
93 out.write('%s' % line)
94 out.close()
95
96 out = open(histogramdata, 'w')
97 for line in open(histogram_data_path):
98 out.write('%s' % line)
99 out.close()
100
101 out = open(summedcontigdata, 'w')
102 for line in open(summed_contigs_data_path):
103 out.write('%s' % line)
104 out.close()
105
106
107 if __name__ == '__main__':
108 __main__()