view unfold_column.py @ 21:86755160afbf draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/text_processing commit c2b1677d1c94433f777c2dc28ac8eec0a99cc6a7
author bgruening
date Fri, 16 Aug 2024 10:41:54 +0000
parents f46f0e4f75c4
children
line wrap: on
line source

#!/usr/bin/env python

import sys

out = open(sys.argv[4], "w+")

sep = sys.argv[3]
# un-sanitize Galaxy inputs
if sep == "X":
    sep = ";"

with open(sys.argv[1]) as handle:
    for line in handle:
        cols = line.split("\t")
        unfolding_column = int(sys.argv[2]) - 1
        column_content = cols[unfolding_column]
        for elem in column_content.split(sep):
            out.write(
                "\t".join(
                    cols[:unfolding_column] + [elem] + cols[unfolding_column + 1:]
                )
            )
out.close()