Mercurial > repos > bgruening > column_arrange_by_header
annotate column_arrange.py @ 0:f18f67056946 draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
author | bgruening |
---|---|
date | Fri, 16 Oct 2015 14:31:13 -0400 |
parents | |
children | 6c6d26ff01ff |
rev | line source |
---|---|
0
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
1 #!/usr/bin/env python |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
2 import pandas as pd |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
3 import argparse |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
4 |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
5 parser = argparse.ArgumentParser() |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
6 parser.add_argument('-i', '--input', help='Tabular Input File Name') |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
7 parser.add_argument('-o','--output', help='Tabular Output File') |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
8 parser.add_argument('-c', '--columns', nargs='+', help='Column Headers to Sort By') |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
9 args=parser.parse_args() |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
10 |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
11 cols = args.columns |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
12 table = pd.read_csv(args.input, sep='\t') |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
13 blist = list(table.columns) |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
14 for token in cols: |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
15 blist.remove(token) |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
16 sorted_table = table[args.columns + blist] |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
17 # write without index, seperated by tabs |
f18f67056946
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/column_arrange_by_header commit 088e73e958b55dc765778641b8a84080cc289f85-dirty
bgruening
parents:
diff
changeset
|
18 sorted_table.to_csv(args.output, sep='\t', index=False) |