1

In Python, we can use iterator(generator function) on the file and finally use zip() which maps similarly indexed columns and write those columns as rows in a new file. Here is an example:

f=open('inp.tsv')
lines = (line.strip().split('\t') for line in list(f))

with open('out.tsv', 'a') as fo:
    for line in zip(*lines):
        print(*line, sep = '\t', file = fo)

f.close()

say the file has the following content:

Xkr4    0   0   0   0
Gm1992  0   0   0   0
Gm37381 0   0   0   0
Rp1 0   0   0   0
Rp1.1   0   0   0   0
Sox17   0   0   0   0

Result:

Xkr4    Gm1992  Gm37381 Rp1 Rp1.1   Sox17
0   0   0   0   0   0
0   0   0   0   0   0
0   0   0   0   0   0
0   0   0   0   0   0

How can we perform a similar task in java?

money
  • 11
  • 2

0 Answers0