Hello,
I have a database style data structure, each record has several
fields.
I would like to create a nested data structure that would let me
'query' the data on the value of certain fields.
I did this by making the following type of data...
Sample PDB data...
ATOM 72 C ARG L 9 41.592 23.248 98.505 1.00 34.28
C
ATOM 73 O ARG L 9 42.467 23.303 97.634 1.00 33.66
O
ATOM 74 CB ARG L 9 40.542 25.445 99.063 1.00 32.51
C
ATOM 75 CG ARG L 9 40.415 26.641 99.989 1.00 30.92
C
ATOM 76 CD ARG L 9 39.771 27.823 99.291 0.00 47.64
C
ATOM 77 NE ARG L 9 38.331 27.672 99.123 0.00 67.84
N
package PDB;
our $pdbTemplate
= 'x6 A5 x1 A4 A1 A3 x1 A1 A4 A1 x3 A8 A8 A8 A6 A6 x6';
our @pdbDescriptive
= qw( serial name altLoc resName chainID resSeq iCode x y z
occupancy tempFactor segID element charge );
our @pdbDataIndex
= qw( serial name altLoc resName chainID resSeq iCode );
sub readPDB {
my $pdb = shift;
unless (ref($pdb) eq "GLOB"){
$pdb = openPDB($pdb);
}
# Data to return
my %pdbData;
while ( <$pdb> ){
next unless /^ATOM|^HETATM/o;
# Parse PDB file (see $pdbTemplate above)
my @atom = unpack( $pdbTemplate, $_ );
# Trim each value.
foreach ( @atom ){ s/^\s+// };
# Must be a better way? (to make a HASH).
my %atom = map { $pdbDescriptive[$_], $atom[$_] } ( 0..$#atom );
# Build up quite a complex data structure.
foreach (@pdbDataIndex){
push @{$pdbData{$_}{$atom{$_}}}, \%atom;
} push @{$pdbData{'data'}}, \%atom;
} return \%pdbData;
}
__END__
This lets me say...
use PDB;
my $data # Special data structure!
= readPDB( $pdb ); # Would be good to use Fields;
my @chainIDs # Lookup 'chain' entries
= sort keys %{ $data->{'chainID'} };
foreach my $chainID ( @chainIDs ){
my @atoms # Use 'chain' entry to get at underlying
atoms.
= @{ $data->{'chainID'}->{$chainID} };
print "$chain\t". scalar(@atoms). "\n";
}
__END__
But I would like to go one step further and for each chain return each
residue, or for each residue return each chain etc... (i.e. recursive
data structure).
How can I do this?