Mercurial > repos > devteam > column_maker
changeset 8:227e82286a0e draft
"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/column_maker commit c623e4b9f6dd6ff4b88d9386f3b0a0cb497e0a0e"
author | devteam |
---|---|
date | Wed, 24 Feb 2021 05:19:12 +0000 |
parents | e7c273e8d4d6 |
children | 33b81f9ea109 |
files | column_maker.py column_maker.xml test-data/1.tab test-data/column_maker_out4.tab |
diffstat | 4 files changed, 47 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/column_maker.py Mon Jan 25 09:59:49 2021 +0000 +++ b/column_maker.py Wed Feb 24 05:19:12 2021 +0000 @@ -10,6 +10,17 @@ import json import re import sys +# functions that may be used in the compute expression +from math import ( # noqa: F401 + ceil, + exp, + floor, + log, + log10, + sqrt +) + +from numpy import format_float_positional # noqa: F401 parser = argparse.ArgumentParser() parser.add_argument('input', type=argparse.FileType('r'), help="input file") @@ -49,8 +60,8 @@ ) try: in_columns = int(argparse_dict['columns']) - if in_columns < 2: - # To be considered tabular, data must fulfill requirements of the sniff.is_column_based() method. + if in_columns < 1: + # To be considered tabular, data must have at least one column. raise ValueError except Exception: if not fh.readline(): @@ -88,6 +99,9 @@ col_str = ', '.join(cols) # 'c1, c2, c3, c4' type_cast_str = ', '.join(type_casts) # 'str(c1), int(c2), int(c3), str(c4)' assign = "%s = line.split('\\t')" % col_str +if len(cols) == 1: + # Single column, unpacking by assignment won't work + assign += '[0]' wrap = "%s = %s" % (col_str, type_cast_str) skipped_lines = 0 first_invalid_line = 0 @@ -97,17 +111,6 @@ # Read input file, skipping invalid lines, and perform computation that will result in a new column code = ''' -# import here since flake8 complains otherwise -from math import ( - ceil, - exp, - floor, - log, - log10, - sqrt -) -from numpy import format_float_positional - for i, line in enumerate(fh): total_lines += 1 line = line.rstrip('\\r\\n')
--- a/column_maker.xml Mon Jan 25 09:59:49 2021 +0000 +++ b/column_maker.xml Wed Feb 24 05:19:12 2021 +0000 @@ -1,4 +1,4 @@ -<tool id="Add_a_column1" name="Compute" version="1.5"> +<tool id="Add_a_column1" name="Compute" version="1.6"> <description>an expression on every row</description> <requirements> <requirement type="package" version="3.8">python</requirement> @@ -88,6 +88,13 @@ <output name="out_file1" file="column_maker_out3.interval"/> </test> <test> + <!-- test that single column input works --> + <param name="cond" value="c1/10"/> + <param name="input" value="1.tab" ftype="tabular"/> + <param name="round" value="no"/> + <output name="out_file1" file="column_maker_out4.tab"/> + </test> + <test> <param name="cond" value="float(.0000000000001)"/> <param name="input" value="1.bed"/> <param name="round" value="false"/> @@ -112,11 +119,11 @@ </output> </test> </tests> - <help> + <help><![CDATA[ .. class:: infomark -**TIP:** If your data is not TAB delimited, use *Text Manipulation->Convert* +**TIP:** If your data is not TAB delimited, use *Text Manipulation->Convert* ----- @@ -168,6 +175,6 @@ round | sorted | sqrt | str | sum | type | unichr | unicode | - </help> + ]]></help> <citations /> </tool>