Entering edit mode
6.8 years ago
Ana
▴
200
I have a table file (including 11 million SNPs) and simply I want to convert rows into columns and column into rows. something like this, this is my unput
7 2 2 0 6
0 2 0 0 0
2 2 0 0 2
this is my desired output
7 0 2
2 2 2
2 0 0
0 0 0
6 0 2
normally I can do it so easily with R by using as.data.frame(t(df)), but it does not work with my data set maybe because file is so big! I could find this little Python script but does not work as well
with open('in.txt') as f:
lis = [x.split() for x in f]
for x in zip(*lis):
for y in x:
print(y+'\t', end='')
print('\n')
when I run it I get this error message
File "./row_to_column_transposition.py", line 8
print(y+'\t', end='')
^
SyntaxError: invalid syntax
I have tried other ways like awk but it does not give me my desired format! Can someone help me to fix it, I would appreciate that.