perl - how to merge rows that share unique IDs into a comma separated table -


i ask hints in how merge rows share unique ids comma separated table. hints in perl, sed or awk appreciated.

this how table have looks now:

protein_id go_id 4102    go:0003676 4125    go:0003676 4125    go:0008270 4139    go:0008270 

this how converted to:

protein_id  go_id 4102    go:0003676 4125    go:0003676, go:0008270 4139    go:0008270 

using perl hash of arrays...

#!/usr/bin/perl use warnings; use strict;  %data; $header;  while(<data>){     chomp;      if ($. == 1){         $header = $_;         next;     }     push @{ $data{(split)[0]} }, (split)[1]; }  print "$header\n";  $k (sort {$a<=>$b} keys %data){      print "$k\t";     print join(', ', @{ $data{$k} });     print "\n"; }  __data__ protein_id go_id 4102    go:0003676 4125    go:0003676 4125    go:0008270 4139    go:0008270 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -