Mercurial > repos > devteam > merge_cols
annotate mergeCols.py @ 1:26d0d9bdbafc 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 14:22:15 +0000 |
parents | 11de536c87b1 |
children | 4576d639d805 |
rev | line source |
---|---|
1
26d0d9bdbafc
"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
11de536c87b1
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff
changeset
|
2 |
11de536c87b1
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff
changeset
|
3 |
11de536c87b1
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff
changeset
|
4 def __main__(): |
11de536c87b1
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff
changeset
|
5 try: |
1
26d0d9bdbafc
"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') |
26d0d9bdbafc
"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') |
26d0d9bdbafc
"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: |
26d0d9bdbafc
"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') |
26d0d9bdbafc
"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents:
0
diff
changeset
|
10 |
26d0d9bdbafc
"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: |
26d0d9bdbafc
"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
11de536c87b1
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff
changeset
|
13 else: |
1
26d0d9bdbafc
"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
11de536c87b1
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff
changeset
|
15 |
11de536c87b1
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff
changeset
|
16 skipped_lines = 0 |
11de536c87b1
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff
changeset
|
17 |
11de536c87b1
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff
changeset
|
18 for line in infile: |
1
26d0d9bdbafc
"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') |
26d0d9bdbafc
"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('#'): |
26d0d9bdbafc
"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
11de536c87b1
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff
changeset
|
22 line += '\t' |
11de536c87b1
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff
changeset
|
23 for col in cols: |
11de536c87b1
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff
changeset
|
24 try: |
1
26d0d9bdbafc
"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] |
26d0d9bdbafc
"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
11de536c87b1
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff
changeset
|
27 skipped_lines += 1 |
1
26d0d9bdbafc
"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents:
0
diff
changeset
|
28 |
26d0d9bdbafc
"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) |
26d0d9bdbafc
"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents:
0
diff
changeset
|
30 |
0
11de536c87b1
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff
changeset
|
31 if skipped_lines > 0: |
1
26d0d9bdbafc
"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) |
26d0d9bdbafc
"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents:
0
diff
changeset
|
33 |
26d0d9bdbafc
"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents:
0
diff
changeset
|
34 |
26d0d9bdbafc
"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__": |
26d0d9bdbafc
"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/merge_cols commit dc2e3b631f515e905d5645baa4fb49df8e8cc0d5"
devteam
parents:
0
diff
changeset
|
36 __main__() |