pabla23 has asked for the wisdom of the Perl Monks concerning the following question:
The output of this script is:use strict; use warnings; my ($mio, $mio2); my @array_with_all_fields=(); my $match = 'DOID:2055'; unlink ("myoutputfilename6.txt"); unlink ("myoutputfilename7.txt"); open(my $file, '<', 'do_human_mapping.gmt') or die "open: $!"; open my $out_file3, '>', 'myoutputfilename6.txt' or die "$!"; open my $out_file4, '>', 'myoutputfilename7.txt' or die "$!"; while (<$file>){ my ($name,$id,@genes) = split /\t/; if ($id eq $match) { $mio= join("\n",@genes); print $mio."\n"; print $out_file3 $mio."\n"; # print on file } if (grep/^$match$/, @genes){ $mio2=$id; print $mio2."\n"; print $out_file4 $mio2."\n"; # print on file } }
APOE
FKBP5
CRH
IL2
The second script is the following:
the output of this script is FOR ONLY "APOE":use strict; use warnings; sub trim { my $s=shift; $s=~ s/^\s+$//g; return $s }; my $mio2; my $match = 'APOE'; unlink ("myoutputfilename4.txt"); open(my $file, '<', 'do_human_mapping.gmt') or die "open: $!"; while (<$file>){ my ($name,$id,@genes) = split /\t/; if (grep/^$match$/, @genes){ $mio2=$id; #print $mio2."\n"; open my $out_file, '>>', 'myoutputfilename4.txt' or die "$!"; print $out_file $mio2."\n"; # print sul file } } open (FILE2, 'HumanDO.obo'); my %hash_value = (); my $Key=''; my $Val=''; while (my $line = <FILE2>) { if ($line=~/^id:\s/) { my @splitted_string=split(' ',$line); $Key=$splitted_string[1]; } if ($line=~/^name:\s/) { my @splitted_string=split(':',$line); $Val=$splitted_string[1]; } if ( defined $Key and defined $Val){ $hash_value{trim($Key)}=$Val; $Key=undef; $Val=undef; } } close FILE2; open(FILE,'myoutputfilename4.txt'); while ( my $line =<FILE>){ my @splitted_string=split(' ',$line); foreach my $key (@splitted_string){ if (exists $hash_value{$key}){ print "$key name:$hash_value{trim($key)}"; } } } close FILE;
DOID:2055
DOID:3453
DOID:4532
I want that the second script takes in input the list from first script and print out for EACH name (APOE, FKB5, CRH,...) the associated "DOID". Every name has more than one "DOID".Thanks for help Paola
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: list in input
by roboticus (Chancellor) on Dec 11, 2014 at 12:49 UTC | |
|
Re: list in input
by RonW (Parson) on Dec 11, 2014 at 23:51 UTC |