changeset 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 d243056b22ed
children efda9a4a50e7
files scatterplot.py scatterplot.xml tool_dependencies.xml
diffstat 3 files changed, 94 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/scatterplot.py	Fri Oct 09 17:17:55 2015 -0400
+++ b/scatterplot.py	Thu Sep 15 11:14:37 2016 -0400
@@ -1,13 +1,22 @@
 #!/usr/bin/env python
-#Greg Von Kuster
+# Greg Von Kuster
 
 import sys
-from rpy import *
+
+from numpy import array
+import rpy2.rpy_classic as rpy
+from rpy2.robjects.numpy2ri import numpy2ri
+
+
+rpy.set_default_mode(rpy.NO_CONVERSION)
+r = rpy.r
+
 
 def stop_err(msg):
     sys.stderr.write(msg)
     sys.exit()
 
+
 def main():
 
     in_fname = sys.argv[1]
@@ -29,13 +38,13 @@
     for i, line in enumerate( file( in_fname ) ):
         valid = True
         line = line.rstrip( '\r\n' )
-        if line and not line.startswith( '#' ): 
+        if line and not line.startswith( '#' ):
             row = []
             fields = line.split( "\t" )
             for column in columns:
                 try:
                     val = fields[column]
-                    if val.lower() == "na": 
+                    if val.lower() == "na":
                         row.append( float( "nan" ) )
                     else:
                         row.append( float( fields[column] ) )
@@ -54,18 +63,19 @@
             valid = False
             skipped_lines += 1
             if not first_invalid_line:
-                first_invalid_line = i+1
+                first_invalid_line = i + 1
 
         if valid:
             matrix.append( row )
 
     if skipped_lines < i:
         try:
+            a = numpy2ri(array( matrix ))
             r.pdf( out_fname, 8, 8 )
-            r.plot( array( matrix ), type="p", main=title, xlab=xlab, ylab=ylab, col="blue", pch=19 )
+            r.plot( a, type="p", main=title, xlab=xlab, ylab=ylab, col="blue", pch=19 )
             r.dev_off()
         except Exception, 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] ) )
 
@@ -73,7 +83,5 @@
     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 )
 
-    r.quit( save="no" )
-
 if __name__ == "__main__":
     main()
--- a/scatterplot.xml	Fri Oct 09 17:17:55 2015 -0400
+++ b/scatterplot.xml	Thu Sep 15 11:14:37 2016 -0400
@@ -1,71 +1,69 @@
-<tool id="scatterplot_rpy" name="Scatterplot" version="1.0.0">
-  <description>of two numeric columns</description>
-  <requirements>
-    <requirement type="package" version="1.0.3">rpy</requirement>
-  </requirements>
-  <command interpreter="python">scatterplot.py $input $out_file1 $col1 $col2 "$title" "$xlab" "$ylab"</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" />
-    <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"/>
-  </inputs>
-  <outputs>
-    <data format="pdf" name="out_file1" />
-  </outputs>
-  <!-- TODO: uncomment the following test when we have tools.update_state() working for 
-       multiple dependents with the same dependency.
-  <tests>
-    <test>
-      <param name="input" value="scatterplot_in1.tabular" ftype="tabular"/>
-      <param name="col1" value="2"/>
-      <param name="col2" value="3"/>
-      <param name="title" value="Scatterplot"/>
-      <param name="xlab" value="V1"/>
-      <param name="ylab" value="V2"/>
-      <output name="out_file1" file="scatterplot_out1.pdf" />
-    </test>
-  </tests>
-  -->
-  <help>
-
-.. class:: infomark
-
-**TIP:** If your data is not TAB delimited, use *Text Manipulation-&gt;Convert*
-
------
-
-**Syntax**
-
-This tool creates a simple scatter plot between two variables containing numeric values of a selected dataset. 
-
-- All invalid, blank and comment lines in the dataset are skipped.  The number of skipped lines is displayed in the resulting history item.
-
-- **Plot title** The scatterplot title
-- **Label for x axis** and **Label for y axis** The labels for x and y axis of the scatterplot.
-
------
-
-**Example**
-
-- Input file::
-
-    1   68  4.1
-    2   71  4.6
-    3   62  3.8
-    4   75  4.4
-    5   58  3.2
-    6   60  3.1
-    7   67  3.8
-    8   68  4.1
-    9   71  4.3
-    10  69  3.7 
-
-- Create a simple scatterplot between the variables in column 2 and column 3 of the above dataset.
-
-.. image:: scatterplot.png
-
-</help>
-</tool>
+<tool id="scatterplot_rpy" name="Scatterplot" version="1.0.2">
+  <description>of two numeric columns</description>
+  <requirements>
+    <requirement type="package" version="1.9">numpy</requirement>
+    <!-- explicit R requirement is necessary for toolshed package, conda rpy2 comes with R -->
+    <requirement type="package" version="3.2.1">R</requirement>
+    <requirement type="package" version="2.7.8">rpy2</requirement>
+  </requirements>
+  <command interpreter="python">scatterplot.py $input $out_file1 $col1 $col2 "$title" "$xlab" "$ylab"</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" />
+    <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"/>
+  </inputs>
+  <outputs>
+    <data format="pdf" name="out_file1" />
+  </outputs>
+  <tests>
+    <test>
+      <param name="input" value="scatterplot_in1.tabular" ftype="tabular"/>
+      <param name="col1" value="2"/>
+      <param name="col2" value="3"/>
+      <param name="title" value="Scatterplot"/>
+      <param name="xlab" value="V1"/>
+      <param name="ylab" value="V2"/>
+      <output name="out_file1" file="scatterplot_out1.pdf" compare="sim_size" />
+    </test>
+  </tests>
+  <help>
+.. class:: infomark
+
+**TIP:** If your data is not TAB delimited, use *Text Manipulation-&gt;Convert*
+
+-----
+
+**Syntax**
+
+This tool creates a simple scatter plot between two variables containing numeric values of a selected dataset. 
+
+- All invalid, blank and comment lines in the dataset are skipped.  The number of skipped lines is displayed in the resulting history item.
+
+- **Plot title** The scatterplot title
+- **Label for x axis** and **Label for y axis** The labels for x and y axis of the scatterplot.
+
+-----
+
+**Example**
+
+- Input file::
+
+    1   68  4.1
+    2   71  4.6
+    3   62  3.8
+    4   75  4.4
+    5   58  3.2
+    6   60  3.1
+    7   67  3.8
+    8   68  4.1
+    9   71  4.3
+    10  69  3.7 
+
+- Create a simple scatterplot between the variables in column 2 and column 3 of the above dataset.
+
+.. image:: scatterplot.png
+</help>
+</tool>
--- a/tool_dependencies.xml	Fri Oct 09 17:17:55 2015 -0400
+++ b/tool_dependencies.xml	Thu Sep 15 11:14:37 2016 -0400
@@ -1,6 +1,12 @@
 <?xml version="1.0"?>
 <tool_dependency>
-  <package name="rpy" version="1.0.3">
-      <repository changeset_revision="82170c94ca7c" name="package_rpy_1_0_3" owner="devteam" toolshed="https://toolshed.g2.bx.psu.edu" />
+    <package name="numpy" version="1.9">
+        <repository changeset_revision="f24fc0b630fc" name="package_python_2_7_numpy_1_9" owner="iuc" toolshed="https://toolshed.g2.bx.psu.edu" />
+    </package>
+    <package name="R" version="3.2.1">
+        <repository changeset_revision="d9f7d84125b7" name="package_r_3_2_1" owner="iuc" toolshed="https://toolshed.g2.bx.psu.edu" />
+    </package>
+    <package name="rpy2" version="2.7.8">
+        <repository changeset_revision="304bc0447631" name="package_rpy2_2_7_8" owner="iuc" toolshed="https://toolshed.g2.bx.psu.edu" />
     </package>
 </tool_dependency>