annotate mergeCols.py @ 2:dd40b1e9eebe draft

"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
author devteam
date Wed, 03 Jun 2020 10:22:39 -0400
parents 28ca7552e884
children ae7843d06f8f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
1 import sys
0
28ca7552e884 Uploaded merge_cols tarball.
devteam
parents:
diff changeset
2
28ca7552e884 Uploaded merge_cols tarball.
devteam
parents:
diff changeset
3
28ca7552e884 Uploaded merge_cols tarball.
devteam
parents:
diff changeset
4 def __main__():
28ca7552e884 Uploaded merge_cols tarball.
devteam
parents:
diff changeset
5 try:
2
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
6 infile = open(sys.argv[1], 'r')
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
7 outfile = open(sys.argv[2], 'w')
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
8 except Exception:
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
9 sys.exit('Cannot open or create a file\n')
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
10
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
11 if len(sys.argv) < 4:
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
12 sys.exit('No columns to merge\n')
0
28ca7552e884 Uploaded merge_cols tarball.
devteam
parents:
diff changeset
13 else:
2
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
14 cols = sys.argv[3:]
0
28ca7552e884 Uploaded merge_cols tarball.
devteam
parents:
diff changeset
15
28ca7552e884 Uploaded merge_cols tarball.
devteam
parents:
diff changeset
16 skipped_lines = 0
28ca7552e884 Uploaded merge_cols tarball.
devteam
parents:
diff changeset
17
28ca7552e884 Uploaded merge_cols tarball.
devteam
parents:
diff changeset
18 for line in infile:
2
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
19 line = line.rstrip('\r\n')
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
20 if line and not line.startswith('#'):
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
21 fields = line.split('\t')
0
28ca7552e884 Uploaded merge_cols tarball.
devteam
parents:
diff changeset
22 line += '\t'
28ca7552e884 Uploaded merge_cols tarball.
devteam
parents:
diff changeset
23 for col in cols:
28ca7552e884 Uploaded merge_cols tarball.
devteam
parents:
diff changeset
24 try:
2
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
25 line += fields[int(col) - 1]
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
26 except Exception:
0
28ca7552e884 Uploaded merge_cols tarball.
devteam
parents:
diff changeset
27 skipped_lines += 1
2
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
28
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
29 print(line, file=outfile)
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
30
0
28ca7552e884 Uploaded merge_cols tarball.
devteam
parents:
diff changeset
31 if skipped_lines > 0:
2
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
32 print('Skipped %d invalid lines' % skipped_lines)
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
33
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
34
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
35 if __name__ == "__main__":
dd40b1e9eebe "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents: 0
diff changeset
36 __main__()