comparison label_encoder.py @ 37:09bfbef3dd90 draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
author bgruening
date Sat, 01 May 2021 00:53:10 +0000
parents
children 053e7f32d37e
comparison
equal deleted inserted replaced
36:cd4328a02798 37:09bfbef3dd90
1 import argparse
2 import json
3 import warnings
4
5 import numpy as np
6 import pandas as pd
7 from sklearn.preprocessing import LabelEncoder
8
9
10 def main(inputs, infile, outfile):
11 """
12 Parameter
13 ---------
14 input : str
15 File path to galaxy tool parameter
16
17 infile : str
18 File paths of input vector
19
20 outfile : str
21 File path to output vector
22
23 """
24 warnings.simplefilter('ignore')
25
26 with open(inputs, 'r') as param_handler:
27 params = json.load(param_handler)
28
29 input_header = params['header0']
30 header = 'infer' if input_header else None
31
32 input_vector = pd.read_csv(infile, sep='\t', header=header)
33
34 le = LabelEncoder()
35
36 output_vector = le.fit_transform(input_vector)
37
38 np.savetxt(outfile, output_vector, fmt="%d", delimiter='\t')
39
40
41 if __name__ == '__main__':
42 aparser = argparse.ArgumentParser()
43 aparser.add_argument("-i", "--inputs", dest="inputs", required=True)
44 aparser.add_argument("-y", "--infile", dest="infile")
45 aparser.add_argument("-o", "--outfile", dest="outfile")
46 args = aparser.parse_args()
47
48 main(args.inputs, args.infile, args.outfile)