Mercurial > repos > bgruening > text_processing
annotate unfold_column.py @ 16:61b3b01662fd draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/text_processing commit 5d3a6a822897569f22f288589543562f54482418
author | bgruening |
---|---|
date | Fri, 01 Dec 2017 13:46:51 -0500 |
parents | c78b1767db2b |
children | 5fef6d08de83 |
rev | line source |
---|---|
4 | 1 #!/usr/bin/env python |
2 | |
3 import sys | |
4 | |
5 out = open(sys.argv[4], 'w+') | |
6 | |
10
c78b1767db2b
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/text_processing commit 10052765d6b712cf7d38356af4251fcc38a339b6-dirty
bgruening
parents:
4
diff
changeset
|
7 sep = sys.argv[3] |
c78b1767db2b
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/text_processing commit 10052765d6b712cf7d38356af4251fcc38a339b6-dirty
bgruening
parents:
4
diff
changeset
|
8 # un-sanitize Galaxy inputs |
c78b1767db2b
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/text_processing commit 10052765d6b712cf7d38356af4251fcc38a339b6-dirty
bgruening
parents:
4
diff
changeset
|
9 if sep == 'X': |
c78b1767db2b
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/text_processing commit 10052765d6b712cf7d38356af4251fcc38a339b6-dirty
bgruening
parents:
4
diff
changeset
|
10 sep = ';' |
c78b1767db2b
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/text_processing commit 10052765d6b712cf7d38356af4251fcc38a339b6-dirty
bgruening
parents:
4
diff
changeset
|
11 |
4 | 12 with open(sys.argv[1]) as handle: |
13 for line in handle: | |
14 cols = line.split('\t') | |
15 unfolding_column = int(sys.argv[2]) - 1 | |
16 column_content = cols[ unfolding_column ] | |
10
c78b1767db2b
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/text_processing commit 10052765d6b712cf7d38356af4251fcc38a339b6-dirty
bgruening
parents:
4
diff
changeset
|
17 for elem in column_content.split( sep ): |
4 | 18 out.write( '\t'.join( cols[:unfolding_column] + [elem] + cols[unfolding_column+1:]) ) |
19 out.close() |