view 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
line wrap: on
line source

#!/usr/bin/env python 
import pandas as pd
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', help='Tabular Input File Name')
parser.add_argument('-o','--output', help='Tabular Output File')
parser.add_argument('-c', '--columns', nargs='+', help='Column Headers to Sort By')
args=parser.parse_args()

cols = args.columns
table = pd.read_csv(args.input, sep='\t')
blist = list(table.columns)
for token in cols:
    blist.remove(token)
sorted_table = table[args.columns + blist]
# write without index, seperated by tabs
sorted_table.to_csv(args.output, sep='\t', index=False)