Mercurial > repos > jpayne > table_ops
changeset 14:1af2524f48b7 tip
planemo upload
author | jpayne |
---|---|
date | Tue, 30 Oct 2018 16:18:02 -0400 |
parents | 746091a78780 |
children | |
files | table-union.py table-union.xml test-data/combined.tsv test-data/no_union.tsv |
diffstat | 4 files changed, 43 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/table-union.py Fri Mar 09 11:14:02 2018 -0500 +++ b/table-union.py Tue Oct 30 16:18:02 2018 -0400 @@ -4,7 +4,7 @@ -def main(files): +def main(unionize=True, *files): header = [] items = [] possible_identity_headers = None @@ -15,6 +15,8 @@ for field in reader.fieldnames: if field not in set(header): header.append(field) + + #try to find identity columns in the files, to use to join if possible_identity_headers is None: possible_identity_headers = set(reader.fieldnames) @@ -30,7 +32,7 @@ # possible_identity_headers = set((possible_identity_headers.pop(), )) #if we found an identity column, then try to join rows - if possible_identity_headers: + if possible_identity_headers and unionize: key_column = possible_identity_headers.pop() keys = set([r[key_column] for r in items]) merged_rows = [] @@ -47,4 +49,4 @@ if __name__ == '__main__': - main(sys.argv[1:]) \ No newline at end of file + main(*sys.argv[1:]) \ No newline at end of file
--- a/table-union.xml Fri Mar 09 11:14:02 2018 -0500 +++ b/table-union.xml Tue Oct 30 16:18:02 2018 -0400 @@ -4,14 +4,32 @@ <!-- <requirement type="package" version="3.4">python</requirement> --> </requirements> <command detect_errors="exit_code"><![CDATA[ - python $__tool_directory__/table-union.py + #if $input_type.source_select == 'two' + #set tables=($table_1, $table_2) + #else + #set tables=$input_type.tables + #end if + python $__tool_directory__/table-union.py "$union" #for $table in $tables $table #end for > $combined_table ]]></command> <inputs> - <param name="tables" type="data_collection" format="tsv" collection_type="list" /> + <param name="union" type="boolean" label="Attempt to unionize on an autodetected key column" checked="false" falsevalue="" /> + <conditional name="input_type"> + <param name="source_select" type="select" label="Mode"> + <option value="two">Combine two tables</option> + <option value="collection">Combine a collection of tables</option> + </param> + <when value="collection"> + <param name="tables" type="data_collection" format="tabular,tsv" collection_type="list" /> + </when> + <when value="two"> + <param name="table_1" type="data" format="tabular,tsv" /> + <param name="table_2" type="data" format="tabular,tsv" /> + </when> + </conditional> </inputs> <outputs> <data name="combined_table" format="tsv" label="Combined table" /> @@ -19,6 +37,8 @@ <tests> <test> + <param name="source_select" value="collection" /> + <param name="union" value="true" /> <param name="tables"> <collection type="list"> <element name="1" value="dingbat.tsv" /> @@ -27,6 +47,13 @@ </param> <output name="combined_table" value="combined.tsv" /> </test> + <test> + <param name="source_select" value="two" /> + <param name="union" value="false" /> + <param name="table_1" value="dingbat.tsv" /> + <param name="table_2" value="loki.tsv" /> + <output name="combined_table" value="no_union.tsv" /> + </test> </tests> <help><![CDATA[ Concatenate a collection of TSV files wile preserving and unionizing headers.
--- a/test-data/combined.tsv Fri Mar 09 11:14:02 2018 -0500 +++ b/test-data/combined.tsv Tue Oct 30 16:18:02 2018 -0400 @@ -1,4 +1,4 @@ -name flavor size color -Dingbat strawberry red -Dunston strawberry massive blue -Loki chocolate massive +name flavor color size +Dingbat strawberry red +Dunston strawberry blue massive +Loki chocolate massive