
Kenosis
User
Apr 5, 2013, 8:25 AM
Post #7 of 8
(1664 views)
|
Re: [FishMonger] Merge data in columns B that have same entry in column A
[In reply to]
|
Can't Post
|
|
Here's another option:
use strict; use warnings; my %hash; while (<>) { push @{ $hash{$1} }, $2 if /(\S+)\s+(\S+)/; } local $" = ','; print "$_\t@{ $hash{$_} }\n" for sort keys %hash; Usage: perl script.pl file.txt [>results.txt] The last, optional parameter will direct output to a file. Output on your dataset:
hsa-let-7a KRAS,HMGA2,integrin,caspase-3,PRDM1/Blimp-1,HMGA2,IGF-II,HMGA2,HMGA2,RAS,BCL2,RAS,MYC,CDC25A,CDK6,NF2,c-myc,RAS,RAS,NIRF hsa-let-7b Cdc34,Dicer,KRAS,CCND1,CDC25A,CDK6,HMGA2 hsa-let-7c HMGA2,HMGA2,HMGA2,BCL2,RAS,CDC25A,CDK6,RAS hsa-let-7d KRAS,HMGA2,BCL2,RAS,CDC25A,CDK6,BDNF,D3R hsa-let-7e HMGA2 hsa-let-7g KRAS,HMGA2,Ras,HMGA2,CDC25A,CDK6 hsa-miR-1 c-Met,calmodulin,Gata4,Mef2a,BCL2,Gata4,calmodulin,Mef2a,C/EBPa,FoxP1,HDAC4,MET,HCN4,FoxP1,HDAC4,MET,Cdk9,fibronectin,RasGAP,Rheb,MEF-2,nAChR,GAJ1,KCNJ2,HSP60,HSP70,Hand2,Kir2.1 hsa-miR-100 Plk1 The script captures the two columns and builds a hash of arrays (HoA). A local copy of Perl's $" variable is set to a comma, so the elements of the array are printed as comma-separated when the array is interpolated (printed within double-quotes). Hope this helps!
|