Next changeset 1:19558df43589 (2015-01-14) |
Commit message:
Imported from capsule None |
added:
add_input_name_as_column.py add_input_name_as_column.xml test-data/signature.tab test-data/signature_with_header.tab test-data/signature_without_header.tab |
b |
diff -r 000000000000 -r 3a1f8302302d add_input_name_as_column.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/add_input_name_as_column.py Tue Jan 13 12:05:08 2015 -0500 |
b |
@@ -0,0 +1,25 @@ +import sys +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 + +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() |
b |
diff -r 000000000000 -r 3a1f8302302d add_input_name_as_column.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/add_input_name_as_column.xml Tue Jan 13 12:05:08 2015 -0500 |
b |
@@ -0,0 +1,57 @@ +<tool id="addName" name="Add input name as column" version="0.1"> + <description>to an existing tabular file</description> + <command interpreter="python">add_input_name_as_column.py + --input "$input" + --label "$input.name" + --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" /> + <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"> + <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> + </conditional> + </inputs> + <outputs> + <data name="output" format="tabular" /> + </outputs> + <tests> + <test> + <param name="input" value="signature.tab" ftype="tabular" /> + <param name="contains_header" value="yes" /> + <param name="colname" value="sample" /> + <output name="output" file="signature_with_header.tab" ftype="tabular"/> + </test> + <test> + <param name="input" value="signature.tab" ftype="tabular" /> + <param name="contains_header" value="no" /> + <output name="output" file="signature_without_header.tab" ftype="tabular"/> + </test> + </tests> + <help> + +.. class:: infomark + +**TIP:** If your data is not TAB delimited, use *Text Manipulation->Convert* + +----- + +**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 + </help> +</tool> + |
b |
diff -r 000000000000 -r 3a1f8302302d test-data/signature.tab --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/signature.tab Tue Jan 13 12:05:08 2015 -0500 |
b |
@@ -0,0 +1,27 @@ +overlap num of pairs probability +1 8 0.000028 +2 7 0.000019 +3 9 0.000034 +4 6 0.000014 +5 8 0.000020 +6 10 0.000086 +7 6 0.000030 +8 9 0.000038 +9 12 0.000058 +10 24 0.000094 +11 11 0.000071 +12 9 0.000058 +13 8 0.000029 +14 11 0.000042 +15 13 0.000112 +16 8 0.000070 +17 11 0.000066 +18 12 0.000697 +19 13 0.000085 +20 5 0.000015 +21 18 0.000540 +22 9 0.000030 +23 8 0.000036 +24 7 0.000037 +25 14 0.000058 +26 12 0.000050 |
b |
diff -r 000000000000 -r 3a1f8302302d test-data/signature_with_header.tab --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/signature_with_header.tab Tue Jan 13 12:05:08 2015 -0500 |
b |
@@ -0,0 +1,27 @@ +overlap num of pairs probability sample +1 8 0.000028 signature.tab +2 7 0.000019 signature.tab +3 9 0.000034 signature.tab +4 6 0.000014 signature.tab +5 8 0.000020 signature.tab +6 10 0.000086 signature.tab +7 6 0.000030 signature.tab +8 9 0.000038 signature.tab +9 12 0.000058 signature.tab +10 24 0.000094 signature.tab +11 11 0.000071 signature.tab +12 9 0.000058 signature.tab +13 8 0.000029 signature.tab +14 11 0.000042 signature.tab +15 13 0.000112 signature.tab +16 8 0.000070 signature.tab +17 11 0.000066 signature.tab +18 12 0.000697 signature.tab +19 13 0.000085 signature.tab +20 5 0.000015 signature.tab +21 18 0.000540 signature.tab +22 9 0.000030 signature.tab +23 8 0.000036 signature.tab +24 7 0.000037 signature.tab +25 14 0.000058 signature.tab +26 12 0.000050 signature.tab |
b |
diff -r 000000000000 -r 3a1f8302302d test-data/signature_without_header.tab --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/signature_without_header.tab Tue Jan 13 12:05:08 2015 -0500 |
b |
@@ -0,0 +1,27 @@ +overlap num of pairs probability signature.tab +1 8 0.000028 signature.tab +2 7 0.000019 signature.tab +3 9 0.000034 signature.tab +4 6 0.000014 signature.tab +5 8 0.000020 signature.tab +6 10 0.000086 signature.tab +7 6 0.000030 signature.tab +8 9 0.000038 signature.tab +9 12 0.000058 signature.tab +10 24 0.000094 signature.tab +11 11 0.000071 signature.tab +12 9 0.000058 signature.tab +13 8 0.000029 signature.tab +14 11 0.000042 signature.tab +15 13 0.000112 signature.tab +16 8 0.000070 signature.tab +17 11 0.000066 signature.tab +18 12 0.000697 signature.tab +19 13 0.000085 signature.tab +20 5 0.000015 signature.tab +21 18 0.000540 signature.tab +22 9 0.000030 signature.tab +23 8 0.000036 signature.tab +24 7 0.000037 signature.tab +25 14 0.000058 signature.tab +26 12 0.000050 signature.tab |