database style data structure?

From: dmb000006 (dmb000006_at_hotmail.com)
Date: 03/26/04


Date: 26 Mar 2004 03:57:22 -0800

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?



Relevant Pages

  • Re: Database style hash?
    ... > I would like to create a nested data structure that would let me ... > Sample PDB data... ... A residue is identified by the chain it is in, ...
    (comp.lang.perl.misc)
  • Database style hash?
    ... I would like to create a nested data structure that would let me ... Sample PDB data... ... But I would like to go one step further and for each chain return each ... residue, or for each residue return each chain etc... ...
    (comp.lang.perl.misc)
  • Re: Data structure for finding min of set intersection
    ... in minimizing the space requirements of the data structure; ... The hard part appears to be to verify that 2 such sets in fact are disjunct ... contained values into a small finite set of residue classes, ... That way we have a really small set telling us, from which residue ...
    (comp.theory)
  • Re: Circular data structures
    ... > the chain will stop and proceed to the next message. ... if I let got that way the Map will reach its max size. ... > So I want to make it circular is there a way... ... A circular data structure will by definition overwrite older data. ...
    (comp.lang.java.programmer)
  • Re: Ordering python sets
    ... As Python becomes accepted for more and more "serious" projects some ... - Bidict: a unordered dict that allows Oretrieval ... a directed unsorted data structure like mine may be acceptable ... A problem with the Chain data structure is how to represent iterators ...
    (comp.lang.python)