[Bioperl-l] comparing data between hashes

Brian Osborne brian_osborne at cognia.com
Sun Oct 24 17:16:56 EDT 2004


Perhaps instead of appending to a string ($class{$position} .= "$pos" . "
,") you could make each position a secondary key:

 $class{$position}{$pos} = 1;

Then comparing 2 species is a matter of looping over the secondary keys and
asking if a given key is defined in both species.

Brian O.

-----Original Message-----
From: bioperl-l-bounces at portal.open-bio.org
[mailto:bioperl-l-bounces at portal.open-bio.org]On Behalf Of Michael S.
Robeson II
Sent: Saturday, October 23, 2004 10:22 PM
To: bioperl-l at portal.open-bio.org
Subject: [Bioperl-l] comparing data between hashes

I have a several "hash of a hashes" that look like this (sorry if my
formating is a little off):

Human => {                      # HoH for human
        1  => [1,32,54,67]      # numbers in [ ] is a string delimited by
not separate hash values
        2  => [14,52,74,87]
        5  => [33,44,64,107]
Chimp => {                      # HoH for Chimp
        1  => [1,32,67]
        2  => [14,74,87]
        5  => [33,44]

Note: The numbers in between the [ ] is a STRING delimited by commas
and NOT separate hash values. I already have a working script that
appends these numbers to the appropriate hash separated by a comma or
newline like this:
                $class{$position} .= "$pos" . " ,";             #to get:  5
=> [33,44,64,107]

And I am having trouble trying to compare data. I want to compare each
number (i.e. 1, 2, & 5) and its data with e the same number in the
other species. For example, I would like to print out a table (see
below) that compares the data between the group "1" in each species.

Alleles for set: 1
Allele: 1       32      54      67
Human   1       1       1       1               # 1 = present
Chimp   1       1       0       1               # 0 = absent

And so on for 2 and 5.

I can most likely do the print formating for the table myself so I do
not need help with that. I just need help with being able to compare
the data within each Hash of a Hash (HoH). I do not know if I should
read this data into yet another Hash (which would be very busy) or an
array somehow? I have been trying to figure this out all week to no

Any ideas or suggestions?

- Thanks
- Mike

Bioperl-l mailing list
Bioperl-l at portal.open-bio.org

More information about the Bioperl-l mailing list