472,142 Members | 1,244 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

database style data structure?

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
1 2036
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.

Similar topics

2 posts views Thread by Tim Mackey | last post: by
9 posts views Thread by Big Slim | last post: by
49 posts views Thread by Relaxin | last post: by
9 posts views Thread by shadow.demon | last post: by
3 posts views Thread by josh.kuo | last post: by
4 posts views Thread by raidvvan | last post: by
9 posts views Thread by Peter Duniho | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.