By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,659 Members | 910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,659 IT Pros & Developers. It's quick & easy.

database style data structure?

P: n/a
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?
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
dm*******@hotmail.com (dmb000006) wrote in message news:<93*************************@posting.google.c om>...

# Build up quite a complex data structure.
foreach (@pdbDataIndex){
push @{$pdbData{$_}{$atom{$_}}}, \%atom;
}
push @{$pdbData{'data'}}, \%atom;
} return \%pdbData;

= @{ $data->{'chainID'}->{$chainID} }; 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).
I'm not familar with the term "residue" in this context.

Is it just another field in the record? (Was it perhaps the one
called resName?)

So I'm figuring you are asking how given one chainID you can get the
list of corresponding resName values.

my @resNames = keys %{{ map { $_->{resName}, undef } @{
$data->{'chainID'}{$chainID} }};

This newsgroup does not exist (see FAQ). Please do not start threads
here.

How can I do this?

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.