Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/scatterplot/.shed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ long_description: |
name: scatterplot
owner: devteam
remote_repository_url: https://github.com/galaxyproject/tools-devteam/tree/master/tools/scatterplot
homepage_url: https://github.com/galaxyproject/tools-devteam/
type: unrestricted
53 changes: 32 additions & 21 deletions tools/scatterplot/scatterplot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
# Greg Von Kuster

# flake8: noqa

from __future__ import print_function

import sys
Expand All @@ -24,41 +26,43 @@ def main():
in_fname = sys.argv[1]
out_fname = sys.argv[2]
try:
columns = int( sys.argv[3] ) - 1, int( sys.argv[4] ) - 1
except:
stop_err( "Columns not specified, your query does not contain a column of numerical data." )
columns = int(sys.argv[3]) - 1, int(sys.argv[4]) - 1
except Exception:
stop_err(
"Columns not specified, your query does not contain a column of numerical data."
)
title = sys.argv[5]
xlab = sys.argv[6]
ylab = sys.argv[7]

matrix = []
skipped_lines = 0
first_invalid_line = 0
invalid_value = ''
invalid_value = ""
invalid_column = 0
i = 0
for i, line in enumerate( open( in_fname ) ):
for i, line in enumerate(open(in_fname)):
valid = True
line = line.rstrip( '\r\n' )
if line and not line.startswith( '#' ):
line = line.rstrip("\r\n")
if line and not line.startswith("#"):
row = []
fields = line.split( "\t" )
fields = line.split("\t")
for column in columns:
try:
val = fields[column]
if val.lower() == "na":
row.append( float( "nan" ) )
row.append(float("nan"))
else:
row.append( float( fields[column] ) )
except:
row.append(float(fields[column]))
except Exception:
valid = False
skipped_lines += 1
if not first_invalid_line:
first_invalid_line = i + 1
try:
invalid_value = fields[column]
except:
invalid_value = ''
except Exception:
invalid_value = ""
invalid_column = column + 1
break
else:
Expand All @@ -68,22 +72,29 @@ def main():
first_invalid_line = i + 1

if valid:
matrix.append( row )
matrix.append(row)

if skipped_lines < i:
try:
a = numpy2ri(array( matrix ))
r.pdf( out_fname, 8, 8 )
r.plot( a, type="p", main=title, xlab=xlab, ylab=ylab, col="blue", pch=19 )
a = numpy2ri(array(matrix))
r.pdf(out_fname, 8, 8)
r.plot(a, type="p", main=title, xlab=xlab, ylab=ylab, col="blue", pch=19)
r.dev_off()
except Exception as exc:
stop_err( "%s" % str( exc ) )
stop_err("%s" % str(exc))
else:
stop_err( "All values in both columns %s and %s are non-numeric or empty." % ( sys.argv[3], sys.argv[4] ) )
stop_err(
"All values in both columns %s and %s are non-numeric or empty."
% (sys.argv[3], sys.argv[4])
)

print("Scatter plot on columns %s, %s. " % ( sys.argv[3], sys.argv[4] ))
print("Scatter plot on columns %s, %s. " % (sys.argv[3], sys.argv[4]))
if skipped_lines > 0:
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 ))
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)
)


if __name__ == "__main__":
main()
26 changes: 23 additions & 3 deletions tools/scatterplot/scatterplot.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<tool id="scatterplot_rpy" name="Scatterplot" version="1.0.3">
<tool id="scatterplot_rpy" name="Scatterplot" version="1.0.3+galaxy0">
<description>of two numeric columns</description>
<requirements>
<requirement type="package" version="1.9">numpy</requirement>
<requirement type="package" version="2.8.5">rpy2</requirement>
<requirement type="package" version="3.0">libgfortran</requirement>
</requirements>
<!--
<environment_variables>
<environment_variable name="R_HOME">\$(R RHOME)</environment_variable>
</environment_variables> -->

<command><![CDATA[
python '$__tool_directory__/scatterplot.py'
'$input'
Expand All @@ -17,8 +23,21 @@
</command>
<inputs>
<param name="input" type="data" format="tabular" label="Dataset" help="Dataset missing? See TIP below"/>
<param name="col1" type="data_column" data_ref="input" numerical="True" label="Numerical column for x axis" />
<param name="col2" type="data_column" data_ref="input" numerical="True" label="Numerical column for y axis" />
<conditional name="cols">
<param name="header" type="select" label="Does the table have a header?" refresh_on_change="true" help="If the table has a header, columns can be selected by name instead of the index.">
<option value="yes" selected="true">yes</option>
<option value="no">no</option>
</param>
<when value="yes">
<param name="col1" type="data_column" data_ref="input" use_header_names="true" numerical="True" label="Numerical column for x axis" />
<param name="col2" type="data_column" data_ref="input" use_header_names="true" numerical="True" label="Numerical column for y axis" />
</when>
<when value="no">
<param name="col1" type="data_column" data_ref="input" numerical="True" label="Numerical column for x axis" />
<param name="col2" type="data_column" data_ref="input" numerical="True" label="Numerical column for y axis" />
</when>
</conditional>

<param name="title" type="text" value="Scatterplot" label="Plot title"/>
<param name="xlab" type="text" value="V1" label="Label for x axis"/>
<param name="ylab" type="text" value="V2" label="Label for y axis"/>
Expand Down Expand Up @@ -76,5 +95,6 @@ This tool creates a simple scatter plot between two variables containing numeric
]]>
</help>
<citations>
<citation type="doi">10.1038/s41586-020-2649-2</citation>
</citations>
</tool>