Question: Splitting each row of a correlation matrix into individual files
0
gravatar for priyankaraina10
7 months ago by
priyankaraina1010 wrote:

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
commands split unix gene • 259 views
ADD COMMENTlink modified 7 months ago by finswimmer11k • written 7 months ago by priyankaraina1010

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

ADD REPLYlink modified 7 months ago • written 7 months ago by priyankaraina1010
   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 REPLYlink modified 7 months ago • written 7 months ago by priyankaraina1010
0
gravatar for priyankaraina10
7 months ago by
priyankaraina1010 wrote:
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 COMMENTlink modified 7 months ago by finswimmer11k • written 7 months ago by priyankaraina1010

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 REPLYlink written 7 months ago by finswimmer11k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 828 users visited in the last hour