This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Reformat a table with awk

Hi, I have this table,

ID ref1 ref2
a   1   3
b   3   1
c   5   1
d   2   4

Tab seperated and there are n number of IDs (a,b,c,..) and references (ref1,ref2,... and so on). I want to replace the numbers with its corresponding ID if greater than 2, so the desired output will be like,

ref1 ref2
b     a
c     d

I have manged to do for single columns with awk

awk -F "\t" '{if($2>2) print $1}' filename

and

awk 'BEGIN{OFS=FS="\t"}$2>2{$2=$1}{print}' filename

But I can't use them for larger files.

Any help is much appreciated, Thank you.

Vivek

awk

Hello viv3kanand!

We believe that this post does not fit the main topic of this site.

This is not a bioinformatics question. Please search stackoverflow

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!

Hi Ram,

From TCGA I got data similar as the table I mentioned. Down below I have converted the mentioned table into real data. Please recheck the fitness of the question to be a main topic so called "bioinformatics".

input

TCGA_ID                 CEPNA     AKT1
tcga-01-01a-1245    1.677        3.531
tcga-01-01a-1243    3.765        1.433
tcga-01-01a-1242    5.311        1.234
tcga-01-01a-1241    2.153        4.5656

Desired output, so that I can do some downstream analysis.

CEPNA                   AKT1
tcga-01-01a-1243   tcga-01-01a-1245
tcga-01-01a-1242   tcga-01-01a-1241

Hope this make sense,

Vivek

I got the answer needed.

awk 'BEGIN{FS=OFS="\t"}NR>1{for(i=2;i<=NF;i++) if ($i>2) { $i=$1 } else { $i="NIL" } }1' filename

Hope this helps someone!!

I'm glad you got a solution. The data in your file alone does not make this bioinformatics. I'd also try and cut down on the sarcasm - that does not play well on online forums.

0 answers

No answers yet.

Log in to answer this question.