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

Ok thanks! Now i have this output:

APOE

APOE

FKBP5

CRH

with this list i've to enter again in the same file and to find for a single element the different id that are associated; the file have this format:

DOID:00001 APOE IL4 RTG5

DOID:00002 FG6 CRH APOE

DOID:00003 RTG5 HUTN CRH

my output would be:

APOE DOID:00001 DOID:00002

CRH DOID:00002 DOID:00003

thanks for your help!!!! Paola

Replies are listed 'Best First'.
Re^3: Unify two files
by poj (Abbot) on Nov 10, 2014 at 13:13 UTC
    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
      Is perfect!!!! Thanks a lot!!! Paola