Splitting each row of a correlation matrix into individual files
1
0
Entering edit mode
5.4 years ago
pr2009 ▴ 10

I have a correlation matrix of 22000 genes and for some analysis, I need to split each row of the matrix into a new file. Which means I need to create 22000 individual files.

I don't want to use the split command (because I want to get the output file as the gene_name.txt)

Input file (for 6 genes)

IGHD2-15    IGHD3-22    IGHD3-16    IGHD3-10    IGHD3OR15-3B    IGHD3-9
IGHD2-15    1   0.696084    0.799736    0.818788    0.03798 0.762752
IGHD3-22    0.696084    1   0.691419    0.67505 0.036993    0.658945
IGHD3-16    0.799736    0.691419    1   0.810656    0.030124    0.759392
IGHD3-10    0.818788    0.67505 0.810656    1   0.026141    0.786954
IGHD3OR15-3B    0.03798 0.036993    0.030124    0.026141    1   0.02706
gene unix commands split • 1.1k views
ADD COMMENT
0
Entering edit mode

The pasted table format is not correct. it is a matrix

ADD REPLY
0
Entering edit mode
   IGHD2-15    IGHD3-22    IGHD3-16    IGHD3-10    
   IGHD2-15 1   0.696084    0.799736    0.818788    
   IGHD3-22 0.696084    1   0.691419    0.67505
   IGHD3-16 0.799736    0.691419    1   0.810656    
   IGHD3-10 0.818788    0.67505 0.810656    1
ADD REPLY
0
Entering edit mode
5.4 years ago
pr2009 ▴ 10
awk '{print >> $1".txt"}' matrix.txt

That will print each line into a file whose name is the 1st field of that line plus a (completely optional) .txt extension. If you don't want the gene name in the file, use:

awk '{n=$1; $1="";print >> n".txt"}' matrix.txt

And, if your first line is a header, use:

awk 'NR>1{n=$1; $1="";print >> n".txt"}' matrix.txt
ADD COMMENT
0
Entering edit mode

Hello priyankaraina10 ,

Please use the formatting bar (especially the code option) to present your post better. I've done it for you this time.
code_formatting

Thank you!

ADD REPLY

Login before adding your answer.

Traffic: 1821 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6