in reply to Re^2: Unify two files
in thread Unify two files

I'm guessing you are looking for the genes for a certain id, and then a looking for all the id's that have those genes. If so try this
#!perl use strict; use warnings; my $match = 'DOID:2055'; my $filename = 'do_human_mapping.gmt'; open (my $fh, '<', $filename) or die "open: $!"; my @genes=(); my %gene2id=(); while (<$fh>){ my ($name,$id,@temp) = split /\s+/; if ($id eq $match) { @genes = @temp; } else { for my $gene (@temp){ push @{$gene2id{$gene}},$id } } } for my $gene (@genes){ if (exists $gene2id{$gene}){ print join ' ',$gene,@{$gene2id{$gene}},"\n"; } } __DATA__ DOID:00001 APOE IL4 RTG5 DOID:00002 FG6 CRH APOE DOID:00003 RTG5 HUTN CRH DOID:2055 APOE FKBP5 CRH
poj

Replies are listed 'Best First'.
Re^4: Unify two files
by pabla23 (Novice) on Nov 10, 2014 at 14:01 UTC
    Is perfect!!!! Thanks a lot!!! Paola