Mercurial > repos > immport-devteam > check_headers
comparison getHeaders.py @ 1:05440ef97f8b draft default tip
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/check_headers commit 14d780f8710fb0962a85c262d0689a9551f4f8e1"
author | azomics |
---|---|
date | Tue, 14 Jul 2020 09:46:31 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:e88c99a4fb36 | 1:05440ef97f8b |
---|---|
1 #!/usr/bin/env python | |
2 ###################################################################### | |
3 # Copyright (c) 2016 Northrop Grumman. | |
4 # All rights reserved. | |
5 ###################################################################### | |
6 # | |
7 # Version 1.2 - May 2018 | |
8 # added leeway for files with different nb of headers | |
9 # | |
10 | |
11 | |
12 import sys | |
13 | |
14 from argparse import ArgumentParser | |
15 | |
16 | |
17 def print_headers(files, filenames, outfile): | |
18 header_table = {} | |
19 for i, eachfile in enumerate(files): | |
20 with open(eachfile, "r") as ef: | |
21 headers = ef.readline().strip() | |
22 header_table[filenames[i]] = headers.split("\t") | |
23 | |
24 h = 0 | |
25 for f in header_table: | |
26 j = len(header_table[f]) + 1 | |
27 if j > h: | |
28 h = j | |
29 | |
30 idx = [str(x) for x in range(1, h)] | |
31 | |
32 with open(outfile, "w") as outf: | |
33 outf.write("Index\t") | |
34 outf.write("\t".join(idx) + "\n") | |
35 for f in header_table: | |
36 if len(header_table[f]) < h: | |
37 for k in range(len(header_table[f]), h-1): | |
38 header_table[f].append("") | |
39 sys.stderr.write(str(len(header_table[f]))) | |
40 outf.write(f + "\t") | |
41 outf.write("\t".join(header_table[f]) + "\n") | |
42 return | |
43 | |
44 | |
45 if __name__ == "__main__": | |
46 parser = ArgumentParser( | |
47 prog="GetHeaders", | |
48 description="Gets the headers of all files in given set.") | |
49 | |
50 parser.add_argument( | |
51 '-i', | |
52 dest="input_files", | |
53 required=True, | |
54 action='append', | |
55 help="File location for the text files.") | |
56 | |
57 parser.add_argument( | |
58 '-n', | |
59 dest="file_names", | |
60 required=True, | |
61 action='append', | |
62 help="File names.") | |
63 | |
64 parser.add_argument( | |
65 '-o', | |
66 dest="output_file", | |
67 required=True, | |
68 help="Name of the output file.") | |
69 | |
70 args = parser.parse_args() | |
71 input_files = [f for f in args.input_files] | |
72 file_names = [fn for fn in args.file_names] | |
73 print_headers(input_files, file_names, args.output_file) |