Mercurial > repos > bgruening > text_processing
annotate unfold_column.py @ 11:e6d48dc4e6ba draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/text_processing commit d48f42b1c267c8ebfc50161ea764baed8ee66701-dirty
author | bgruening |
---|---|
date | Fri, 18 Mar 2016 15:18:21 -0400 |
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() |