Mercurial > repos > devteam > scatterplot
comparison scatterplot.py @ 2:53eb2c412783 draft
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/scatterplot commit de7140295cce07e1bc1697e51dab4271c8d7a8a6
| author | devteam |
|---|---|
| date | Fri, 18 Dec 2015 19:14:12 -0500 |
| parents | c30eeaaac86d |
| children | 1dacc8aeb452 |
comparison
equal
deleted
inserted
replaced
| 1:4afd68392187 | 2:53eb2c412783 |
|---|---|
| 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 from rpy import r | |
| 8 | |
| 6 | 9 |
| 7 def stop_err(msg): | 10 def stop_err(msg): |
| 8 sys.stderr.write(msg) | 11 sys.stderr.write(msg) |
| 9 sys.exit() | 12 sys.exit() |
| 13 | |
| 10 | 14 |
| 11 def main(): | 15 def main(): |
| 12 | 16 |
| 13 in_fname = sys.argv[1] | 17 in_fname = sys.argv[1] |
| 14 out_fname = sys.argv[2] | 18 out_fname = sys.argv[2] |
| 27 invalid_column = 0 | 31 invalid_column = 0 |
| 28 i = 0 | 32 i = 0 |
| 29 for i, line in enumerate( file( in_fname ) ): | 33 for i, line in enumerate( file( in_fname ) ): |
| 30 valid = True | 34 valid = True |
| 31 line = line.rstrip( '\r\n' ) | 35 line = line.rstrip( '\r\n' ) |
| 32 if line and not line.startswith( '#' ): | 36 if line and not line.startswith( '#' ): |
| 33 row = [] | 37 row = [] |
| 34 fields = line.split( "\t" ) | 38 fields = line.split( "\t" ) |
| 35 for column in columns: | 39 for column in columns: |
| 36 try: | 40 try: |
| 37 val = fields[column] | 41 val = fields[column] |
| 38 if val.lower() == "na": | 42 if val.lower() == "na": |
| 39 row.append( float( "nan" ) ) | 43 row.append( float( "nan" ) ) |
| 40 else: | 44 else: |
| 41 row.append( float( fields[column] ) ) | 45 row.append( float( fields[column] ) ) |
| 42 except: | 46 except: |
| 43 valid = False | 47 valid = False |
| 52 break | 56 break |
| 53 else: | 57 else: |
| 54 valid = False | 58 valid = False |
| 55 skipped_lines += 1 | 59 skipped_lines += 1 |
| 56 if not first_invalid_line: | 60 if not first_invalid_line: |
| 57 first_invalid_line = i+1 | 61 first_invalid_line = i + 1 |
| 58 | 62 |
| 59 if valid: | 63 if valid: |
| 60 matrix.append( row ) | 64 matrix.append( row ) |
| 61 | 65 |
| 62 if skipped_lines < i: | 66 if skipped_lines < i: |
| 63 try: | 67 try: |
| 64 r.pdf( out_fname, 8, 8 ) | 68 r.pdf( out_fname, 8, 8 ) |
| 65 r.plot( array( matrix ), type="p", main=title, xlab=xlab, ylab=ylab, col="blue", pch=19 ) | 69 r.plot( array( matrix ), type="p", main=title, xlab=xlab, ylab=ylab, col="blue", pch=19 ) |
| 66 r.dev_off() | 70 r.dev_off() |
| 67 except Exception, exc: | 71 except Exception, exc: |
| 68 stop_err( "%s" %str( exc ) ) | 72 stop_err( "%s" % str( exc ) ) |
| 69 else: | 73 else: |
| 70 stop_err( "All values in both columns %s and %s are non-numeric or empty." % ( sys.argv[3], sys.argv[4] ) ) | 74 stop_err( "All values in both columns %s and %s are non-numeric or empty." % ( sys.argv[3], sys.argv[4] ) ) |
| 71 | 75 |
| 72 print "Scatter plot on columns %s, %s. " % ( sys.argv[3], sys.argv[4] ) | 76 print "Scatter plot on columns %s, %s. " % ( sys.argv[3], sys.argv[4] ) |
| 73 if skipped_lines > 0: | 77 if skipped_lines > 0: |
