Mercurial > repos > devteam > scatterplot
comparison scatterplot.py @ 2:4f8b9e70fda0 draft
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/scatterplot commit 93df3895fbf2fa44ff279303093fb89b79081687
author | devteam |
---|---|
date | Thu, 15 Sep 2016 11:14:37 -0400 |
parents | c12b0759203b |
children | efda9a4a50e7 |
comparison
equal
deleted
inserted
replaced
1:d243056b22ed | 2:4f8b9e70fda0 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 #Greg Von Kuster | 2 # Greg Von Kuster |
3 | 3 |
4 import sys | 4 import sys |
5 from rpy import * | 5 |
6 from numpy import array | |
7 import rpy2.rpy_classic as rpy | |
8 from rpy2.robjects.numpy2ri import numpy2ri | |
9 | |
10 | |
11 rpy.set_default_mode(rpy.NO_CONVERSION) | |
12 r = rpy.r | |
13 | |
6 | 14 |
7 def stop_err(msg): | 15 def stop_err(msg): |
8 sys.stderr.write(msg) | 16 sys.stderr.write(msg) |
9 sys.exit() | 17 sys.exit() |
18 | |
10 | 19 |
11 def main(): | 20 def main(): |
12 | 21 |
13 in_fname = sys.argv[1] | 22 in_fname = sys.argv[1] |
14 out_fname = sys.argv[2] | 23 out_fname = sys.argv[2] |
27 invalid_column = 0 | 36 invalid_column = 0 |
28 i = 0 | 37 i = 0 |
29 for i, line in enumerate( file( in_fname ) ): | 38 for i, line in enumerate( file( in_fname ) ): |
30 valid = True | 39 valid = True |
31 line = line.rstrip( '\r\n' ) | 40 line = line.rstrip( '\r\n' ) |
32 if line and not line.startswith( '#' ): | 41 if line and not line.startswith( '#' ): |
33 row = [] | 42 row = [] |
34 fields = line.split( "\t" ) | 43 fields = line.split( "\t" ) |
35 for column in columns: | 44 for column in columns: |
36 try: | 45 try: |
37 val = fields[column] | 46 val = fields[column] |
38 if val.lower() == "na": | 47 if val.lower() == "na": |
39 row.append( float( "nan" ) ) | 48 row.append( float( "nan" ) ) |
40 else: | 49 else: |
41 row.append( float( fields[column] ) ) | 50 row.append( float( fields[column] ) ) |
42 except: | 51 except: |
43 valid = False | 52 valid = False |
52 break | 61 break |
53 else: | 62 else: |
54 valid = False | 63 valid = False |
55 skipped_lines += 1 | 64 skipped_lines += 1 |
56 if not first_invalid_line: | 65 if not first_invalid_line: |
57 first_invalid_line = i+1 | 66 first_invalid_line = i + 1 |
58 | 67 |
59 if valid: | 68 if valid: |
60 matrix.append( row ) | 69 matrix.append( row ) |
61 | 70 |
62 if skipped_lines < i: | 71 if skipped_lines < i: |
63 try: | 72 try: |
73 a = numpy2ri(array( matrix )) | |
64 r.pdf( out_fname, 8, 8 ) | 74 r.pdf( out_fname, 8, 8 ) |
65 r.plot( array( matrix ), type="p", main=title, xlab=xlab, ylab=ylab, col="blue", pch=19 ) | 75 r.plot( a, type="p", main=title, xlab=xlab, ylab=ylab, col="blue", pch=19 ) |
66 r.dev_off() | 76 r.dev_off() |
67 except Exception, exc: | 77 except Exception, exc: |
68 stop_err( "%s" %str( exc ) ) | 78 stop_err( "%s" % str( exc ) ) |
69 else: | 79 else: |
70 stop_err( "All values in both columns %s and %s are non-numeric or empty." % ( sys.argv[3], sys.argv[4] ) ) | 80 stop_err( "All values in both columns %s and %s are non-numeric or empty." % ( sys.argv[3], sys.argv[4] ) ) |
71 | 81 |
72 print "Scatter plot on columns %s, %s. " % ( sys.argv[3], sys.argv[4] ) | 82 print "Scatter plot on columns %s, %s. " % ( sys.argv[3], sys.argv[4] ) |
73 if skipped_lines > 0: | 83 if skipped_lines > 0: |
74 print "Skipped %d lines starting with line #%d, value '%s' in column %d is not numeric." % ( skipped_lines, first_invalid_line, invalid_value, invalid_column ) | 84 print "Skipped %d lines starting with line #%d, value '%s' in column %d is not numeric." % ( skipped_lines, first_invalid_line, invalid_value, invalid_column ) |
75 | 85 |
76 r.quit( save="no" ) | |
77 | |
78 if __name__ == "__main__": | 86 if __name__ == "__main__": |
79 main() | 87 main() |