Mercurial > repos > mvdbeek > add_input_name_as_column
comparison add_input_name_as_column.py @ 3:c9459a7e08ff draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
author | iuc |
---|---|
date | Tue, 14 Oct 2025 17:12:53 +0000 |
parents | ea4ad41e01fc |
children |
comparison
equal
deleted
inserted
replaced
2:ea4ad41e01fc | 3:c9459a7e08ff |
---|---|
2 import io | 2 import io |
3 | 3 |
4 | 4 |
5 def Parser(): | 5 def Parser(): |
6 the_parser = argparse.ArgumentParser(description="add label to last column of file") | 6 the_parser = argparse.ArgumentParser(description="add label to last column of file") |
7 the_parser.add_argument('--input', required=True, action="store", type=str, help="input tabular file") | 7 the_parser.add_argument( |
8 the_parser.add_argument('--output', required=True, action="store", type=str, help="output file path") | 8 "--input", required=True, action="store", type=str, help="input tabular file" |
9 the_parser.add_argument('--label', required=True, action="store", type=str, help="label to add in last column") | 9 ) |
10 the_parser.add_argument('--header', action="store", type=str, help="column label for last column") | 10 the_parser.add_argument( |
11 the_parser.add_argument('--prepend', action='store_true', default=False, help='Prepend column instead of appending' ) | 11 "--output", required=True, action="store", type=str, help="output file path" |
12 ) | |
13 the_parser.add_argument( | |
14 "--label", | |
15 required=True, | |
16 action="store", | |
17 type=str, | |
18 help="label to add in last column", | |
19 ) | |
20 the_parser.add_argument( | |
21 "--header", action="store", type=str, help="column label for last column" | |
22 ) | |
23 the_parser.add_argument( | |
24 "--prepend", | |
25 action="store_true", | |
26 default=False, | |
27 help="Prepend column instead of appending", | |
28 ) | |
12 | 29 |
13 args = the_parser.parse_args() | 30 args = the_parser.parse_args() |
14 return args | 31 return args |
15 | 32 |
16 | 33 |
17 args = Parser() | 34 args = Parser() |
18 | 35 |
19 | 36 |
20 with io.open(args.input, encoding="utf-8") as input, io.open(args.output, 'w', encoding="utf-8") as output: | 37 with io.open(args.input, encoding="utf-8") as input, io.open( |
38 args.output, "w", encoding="utf-8" | |
39 ) as output: | |
21 for i, line in enumerate(input): | 40 for i, line in enumerate(input): |
22 line = line.strip('\n') | 41 line = line.strip("\n") |
23 if (i == 0) and args.header: | 42 if (i == 0) and args.header: |
24 new_entry = args.header | 43 new_entry = args.header |
25 else: | 44 else: |
26 new_entry = args.label | 45 new_entry = args.label |
27 if args.prepend: | 46 if args.prepend: |