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.
How many samples do you have for your 11 million SNPs? You tried this?
You may want to deep-link relevant post in future instead of just copying/pasting the code. Use the https link that shows up in address bar after you click the "link" button in any post and paste in new post.
@genomax, when someone posts a link (instead of copy-pasting the code from other page) where the solution is already available, it gives OP a feeling that with some effort they can find solution instead of asking for help, which is very good.
Hello Ana!
Previous solutions exist and have been posted in this thread.
For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.
If you disagree please tell us why in a reply below, we'll be happy to talk about it.
Cheers!