changeset 5:06061aa49527 draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
author mvdbeek
date Wed, 06 Mar 2019 09:16:29 -0500
parents b31219f26a8f
children 3284b72eef56
files add_input_name_as_column.py add_input_name_as_column.xml tool
diffstat 3 files changed, 37 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/add_input_name_as_column.py	Fri Mar 20 14:51:56 2015 +0100
+++ b/add_input_name_as_column.py	Wed Mar 06 09:16:29 2019 -0500
@@ -1,25 +1,25 @@
-import sys
+import io
 import argparse
 
+
 def Parser():
-  the_parser = argparse.ArgumentParser(description="add label to last column of file")
-  the_parser.add_argument('--input', required=True, action="store", type=str, help="input tabular file")
-  the_parser.add_argument('--output', required=True,  action="store", type=str, help="output file path")
-  the_parser.add_argument('--label', required=True, action="store", type=str, help="label to add in last column")
-  the_parser.add_argument('--header', action="store", type=str, help="column label for last column")
-  args = the_parser.parse_args()
-  return args
+    the_parser = argparse.ArgumentParser(description="add label to last column of file")
+    the_parser.add_argument('--input', required=True, action="store", type=str, help="input tabular file")
+    the_parser.add_argument('--output', required=True, action="store", type=str, help="output file path")
+    the_parser.add_argument('--label', required=True, action="store", type=str, help="label to add in last column")
+    the_parser.add_argument('--header', action="store", type=str, help="column label for last column")
+    args = the_parser.parse_args()
+    return args
 
-args=Parser()
 
-input=open(args.input)
-output=open(args.output, 'w')
-for i,line in enumerate(input):
-  line=line.strip('\n')
-  if (i==0) and (args.header!=None):
-    line=line+'\t'+args.header
-  else:
-    line=line+'\t'+args.label
-  print >>output, line
-input.close()
-output.close()
+args = Parser()
+
+
+with io.open(args.input, encoding="utf-8") as input, io.open(args.output, 'w', encoding="utf-8") as output:
+    for i, line in enumerate(input):
+        line = line.strip('\n')
+        if (i == 0) and args.header:
+            line = "%s\t%s\n" % (line, args.header)
+        else:
+            line = "%s\t%s\n" % (line, args.label)
+        output.write(line)
--- a/add_input_name_as_column.xml	Fri Mar 20 14:51:56 2015 +0100
+++ b/add_input_name_as_column.xml	Wed Mar 06 09:16:29 2019 -0500
@@ -1,26 +1,30 @@
-<tool id="addName" name="Add input name as column" version="0.1.1">
+<tool id="addName" name="Add input name as column" version="0.1.2" profile="17.09">
   <description>to an existing tabular file</description>
-  <command interpreter="python">add_input_name_as_column.py 
-    --input "$input" 
-    --label "$input.element_identifier" 
-    --output "$output"
-    #if $header.contains_header=="yes":
-      --header "$header.colname"
-    #end if
-  </command>
+  <requirements>
+    <requirement type="package" version="3.7">python</requirement>
+  </requirements>
+  <command><![CDATA[
+python '$__tool_directory__/'add_input_name_as_column.py
+--input '$input'
+--label '$input.element_identifier'
+--output '$output'
+#if $header.contains_header=="yes":
+  --header "$header.colname"
+#end if
+  ]]></command>
   <inputs>
-  <param format="tabular" name="input" type="data" label="to Dataset" help="Dataset missing? See TIP below" />
+  <param format="txt" name="input" type="data" label="to Dataset" help="Dataset missing? See TIP below" />
   <conditional name="header">
     <param name="contains_header" type="select" label="input contains a header line?" >
       <option value="yes" selected="true">Yes</option>
       <option value="no">No</option>
     </param>
-    <when value="yes"> 
+    <when value="yes">
       <param name="colname" type="text" value="sample" help="select a column header to be added in the first line">
         <validator type="empty_field" message="please add a column header"/>
       </param>
     </when>
-    <when value="no"> 
+    <when value="no">
     </when>
   </conditional>
   </inputs>
@@ -51,7 +55,7 @@
 **What it does**
 
 Adds a new column with the name of the input file as it appears in the history.
-Written by Marius van den Beek, m.vandenbeek at gmail . com
+Written by Marius van den Beek, m.vandenbeek at gmail dot com
   </help>
 </tool>
 
Binary file tool has changed