CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Multidimensional hash help

 



ila14
New User

Mar 4, 2014, 4:08 AM

Post #1 of 2 (712 views)
Multidimensional hash help Can't Post

Hello all,

I am sure you would have heard this all before but I shall say it again. I am a new user of perl and would like help defining my hash. I have an input text file containing 11 columns of information that I have initialized. A snippet of the file and my code are shown below.

File: ID Symbol Taxon Taxon Name Evidence GO ID GO Name + Aspect Reference With Source H1SXX9 Symbol1 12345 Homo Sapiens IEA GO:0015031 pro +tein transport Process GO_REF:0000002 InterPro:IPR027282 +InterPro H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0003824 cat +alytic activity Function GO_REF:0000002 InterPro:IPR003607 + InterPro H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0008152 met +abolic process Process GO_REF:0000002 InterPro:IPR002912 +InterPro H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0008728 GTP + diphosphokinase activity Function GO_REF:0000003 EC:2.7.6.5 + UniProt H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0015969 gua +nosine tetraphosphate metabolic process Process GO_REF:0000002 + InterPro:IPR004811|InterPro:IPR007685 InterPro H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0016301 kin +ase activity Function GO_REF:0000038 UniProtKB-KW:KW-0418 + UniProt H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0016310 pho +sphorylation Process GO_REF:0000038 UniProtKB-KW:KW-0418 +UniProt H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0016597 ami +no acid binding Function GO_REF:0000002 InterPro:IPR002912 + InterPro H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0016740 tra +nsferase activity Function GO_REF:0000038 UniProtKB-KW:KW-08 +08 UniProt H1SXZ8 Symbol3 12345 Homo Sapiens IEA GO:0006812 cat +ion transport Process GO_REF:0000002 InterPro:IPR002524 I +nterPro H1SXZ8 Symbol3 12345 Homo Sapiens IEA GO:0008324 cat +ion transmembrane transporter activity Function GO_REF:0000002 + InterPro:IPR002524 InterPro H1SXZ8 Symbol3 12345 Homo Sapiens IEA GO:0030001 met +al ion transport Process GO_REF:0000002 InterPro:IPR006121 + InterPro H1SXZ8 Symbol3 12345 Homo Sapiens IEA GO:0046872 met +al ion binding Function GO_REF:0000002 InterPro:IPR006121 + InterPro H1SXZ8 Symbol3 12345 Homo Sapiens IEA GO:0055085 tra +nsmembrane transport Process GO_REF:0000002 InterPro:IPR0025 +24 InterPro H1SY02 Symbol4 12345 Homo Sapiens IEA GO:0006810 tra +nsport Process GO_REF:0000002 InterPro:IPR002898 InterPro H1SY02 Symbol4 12345 Homo Sapiens IEA GO:0006810 tra +nsport Process GO_REF:0000038 UniProtKB-KW:KW-0813 UniPro +t H1SY02 Symbol4 12345 Homo Sapiens IEA GO:0008565 pro +tein transporter activity Function GO_REF:0000002 InterPro:I +PR002898 InterPro H1SY02 Symbol4 12345 Homo Sapiens IEA GO:0015031 pro +tein transport Process GO_REF:0000038 UniProtKB-KW:KW-0653 + UniProt H1SY06 Symbol5 12345 Homo Sapiens IEA GO:0004129 cyt +ochrome-c oxidase activity Function GO_REF:0000002 InterPro: +IPR000883|InterPro:IPR004677|InterPro:IPR023615|InterPro:IPR023616 + InterPro H1SY06 Symbol5 12345 Homo Sapiens IEA GO:0004129 cyt +ochrome-c oxidase activity Function GO_REF:0000003 EC:1.9.3. +1 UniProt H1SY06 Symbol5 12345 Homo Sapiens IEA GO:0005506 iro +n ion binding Function GO_REF:0000002 InterPro:IPR000883 +InterPro


Code
Code:  
open(IN,$annotationfile) or die "Can't open $annotationfile\n";
while(<IN>)
{ chomp;
@data = split(/\t/,$_);
$Column1 = @data[0];
$Column2 = @data[1];
$Column3 = @data[2];
$Column4 = @data[3];
$Column5 = @data[4];
$Column6 = @data[5];
$Column7 = @data[6];
$Column8 = @data[7];
$Column9 = @data[8];
$Column10 = @data[9];
$Column11 = @data[10];
print "$Column1\t$Column2....\t$Column11\n";
foreach $_ (1..$#data){ $GOHash{"$Symbols"}{"$GO_Names"} = "$IDs"; foreach $Symbols (@data) { foreach my $name (sort {$a <=> $b} (keys %GOHash) ) { foreach my $annotation (keys %{ $GOHash{$name} }) { print "$name, $annotation: $GOHash{$name}{$annotation}\n"; close(IN); } } } } }


I know that my columns are initialized because I see the correct information when I print. I am experiencing problems creating a multidimensional hash. Sorry that the syntax is not correct, I did it for simplicities sake,however this is what I would like to hash:
% hash1 = Column1 => Column 2.
%hash2 = %hash1 => Column3.
%hash3 = %hash2 => Column 4.

I would be thankful for any help/advice. Kind regards,

Ila14


FishMonger
Veteran / Moderator

Mar 4, 2014, 7:10 AM

Post #2 of 2 (706 views)
Re: [ila14] Multidimensional hash help [In reply to] Can't Post

Cross posted on devshed and perlmonks.

Answered on perlmonks http://www.perlmonks.org/?node_id=1076856

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives