Bio::Structure
Entry
Toolbar
Summary
Bio::Structure::Entry - Bioperl structure Object, describes the whole entry
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
Description
This object stores a whole Bio::Structure entry. It can consist of one or
more models (Bio::Structure::Model), which in turn consist of one or more
chains (Bio::Structure::Chain). A chain is composed of residues
(Bio::Structure::Residue) and a residue consists of atoms (Bio::Structure::Atom)
If no specific model or chain is chosen, the first one is choosen.
Methods
Methods description
Title : _child Usage : This is an internal function only. It is used to have one place that keeps track of which object has which other object as child. Thus allowing the underlying modules (Atom, Residue,...) to have no knowledge about all this (and thus removing the possibility to have no knowledge about all this (and thus removing the possibility of reference cycles). This method hides the details of manipulating references to an anonymous hash. Function: To get/set an object's child(ren) Returns : a reference to an array of child(ren) if it exist, undef otherwise. Args : |
Title : _create_default_chain Usage : Function: Creates a default Chain for this Model. Typical situation in an X-ray structure where there is only one chain Returns : Args : |
Title : _create_default_model Usage : Function: Creates a default Model for this Entry. Typical situation in an X-ray structure where there is only one model Returns : Args : |
Title : _parent Usage : This is an internal function only. It is used to have one place that keeps track of which object has which other object as parent. Thus allowing the underlying modules (Atom, Residue,...) to have no knowledge about all this (and thus removing the possibility of reference cycles). This method hides the details of manipulating references to an anonymous hash. Function: To get/set an objects parent Returns : a reference to the parent if it exist, undef otherwise. In the current implementation each node should have a parent (except Entry). Args : |
Title : _remove_from_graph Usage : This is an internal function only. It is used to remove from the parent/child graph. We only remove the links from object to his parent. Not the ones from object to its children. Function: To remove an object from the parent/child graph Returns : Args : the object to be orphaned |
Title : _remove_models Usage : Function: Removes the models attached to an Entry. Tells the models they don't belong to this Entry any more Returns : Args : |
Title : add_atom Usage : @atoms = $structure->add_atom($residue,$atom); Function: Adds a (or a list of) Atom objects to a Bio::Structure::Residue. Returns : list of Bio::Structure::Atom objects Args : a residue and an atom |
Title : add_chain Usage : @chains = $structure->add_chain($add_chain); Function: Adds a (or a list of) Chain objects to a Bio::Structure::Entry. Returns : Args : |
Title : add_model Usage : $structure->add_model($model); Function: Adds a (or a list of) Model objects to a Bio::Structure::Entry. Returns : Args : One Model or a reference to an array of Model objects |
Title : add_residue Usage : @residues = $structure->add_residue($residue); Function: Adds a (or a list of) Residue objects to a Bio::Structure::Entry. Returns : list of Bio::Structure::Residue objects Args : One Residue or a reference to an array of Residue objects |
Title : annotation Usage : $obj->annotation($seq_obj) Function: Example : Returns : value of annotation Args : newvalue (optional) |
Title : chain Usage : @chains = $structure->chain($chain); Function: Connects a (or a list of) Chain objects to a Bio::Structure::Entry. Returns : list of Bio::Structure::Residue objects Args : One Residue or a reference to an array of Residue objects |
Title : conect Usage : $structure->conect($source); Function: get/set method for conect Returns : a list of serial numbers for atoms connected to source (together with $entry->get_atom_by_serial($model, $serial) this should be OK for now) Args : the serial number for the source atom |
Title : get_all_conect_source Usage : @sources = $structure->get_all_conect_source; Function: get all the sources for the conect records Returns : a list of serial numbers for atoms connected to source (together with $entry->get_atom_by_serial($model, $serial) this should be OK for now) Args : Description : This is a bit of a kludge, but it's the best for now. Conect info might need to go in a sepearte object |
Title : get_atom_by_serial Usage : $structure->get_atom_by_serial($module, $serial); Function: get the Atom for a for get_atom_by_serial Returns : the Atom object with this serial number in the model Args : Model on which to work, serial number for atom (if only a number is supplied, the first model is chosen) |
Title : get_atoms Usage : $structure->get_atoms($residue); Function: general get method for atoms attached to a Residue Returns : a list of atoms attached to this residue Args : a residue |
Title : get_chains Usage : $entry->get_chains($model); Function: general get method for chains attached to a Model Returns : a list of chains attached to this model Args : a Model |
Title : get_models Usage : $structure->get_models($structure); Function: general get method for models attached to an Entry Returns : a list of models attached to this entry Args : an Entry |
Title : get_residues Usage : $structure->get_residues($chain); Function: general get method for residues attached to a Chain Returns : a list of residues attached to this chain Args : a chain |
Title : id Usage : $entry->id("identity"); Function: Gets/sets the ID Returns : Args : |
Title : master Usage : $structure->master($source); Function: get/set method for master Returns : the master line Args : the master line for this entry |
Title : model Function: Connects a (or a list of) Model objects to a Bio::Structure::Entry. To add a Model (and keep the existing ones) use add_model() It returns a list of Model objects. Returns : list of Bio::Structure::Model objects Args : One Model or a reference to an array of Model objects |
Title : new() Usage : $struc = Bio::Structure::Entry->new( -id => 'structure_id', );
Function: Returns a new Bio::Structure::Entry object from basic
constructors. Probably most called from Bio::Structure::IO.
Returns : a new Bio::Structure::Model object |
Title : parent Usage : $structure->parent($residue); Function: returns the parent of the argument Returns : the parent of the argument Args : a Bio::Structure object |
Title : residue Usage : @residues = $structure->residue($residue); Function: Connects a (or a list of) Residue objects to a Bio::Structure::Entry. Returns : list of Bio::Structure::Residue objects Args : One Residue or a reference to an array of Residue objects |
Title : seqres Usage : $seqobj = $structure->seqres("A"); Function: gets a sequence object containing the sequence from the SEQRES record. if a chain-ID is given , the sequence for this chain is given, if none is provided the first chain is choosen Returns : a Bio::PrimarySeq Args : the chain-ID of the chain you want the sequence from |
Methods code
sub DESTROY
{ my $self = shift;
%{ $self->{'p_c'} } = ();
%{ $self->{'c_p'} } = ();
}
} |
sub _child
{ my ($self, $key, $value) = @_;
if ( (!defined $key) || (ref($key) !~ /^Bio::/) ) {
$self->throw("First argument to _child needs to be a reference to a Bio:: object\n");
}
if ( (defined $value) && (ref($value) !~ /^Bio::/) ) {
$self->throw("Second argument to _child needs to be a reference to a Bio:: object\n");
}
if (defined $value) {
if ( !exists(${$self->{'p_c'}}{$key}) || ref(${$self->{'p_c'}}{$key}) !~ /^ARRAY/ ) {
${$self->{'p_c'}}{$key} = [];
}
push @{ ${$self->{'p_c'}}{$key} }, $value;
}
return ${$self->{'p_c'}}{$key}; } |
sub _create_default_chain
{ my ($self) = shift;
my $chain = Bio::Structure::Chain->new(-id => "default");
return $chain; } |
sub _create_default_model
{ my ($self) = shift;
my $model = Bio::Structure::Model->new(-id => "default");
return $model; } |
sub _parent
{ no strict "refs";
my ($self, $key, $value) = @_;
if ( (!defined $key) || (ref($key) !~ /^Bio::/) ) {
$self->throw("First argument to _parent needs to be a reference to a Bio:: object ($key)\n");
}
if ( (defined $value) && (ref($value) !~ /^Bio::/) ) {
$self->throw("Second argument to _parent needs to be a reference to a Bio:: object\n");
}
if (defined $value) {
if (defined ( $self->{'c_p'}->{$key}) &&
exists ( $self->{'c_p'}->{$key})
) {
$self->throw("_parent: $key already has a parent ${$self->{'c_p'}}{$key}\n");
}
${$self->{'c_p'}}{$key} = $value;
}
return ${$self->{'c_p'}}{$key}; } |
sub _print_stats_pc
{ my ($self) =@_;
my $pc = scalar keys %{$self->{'p_c'}};
my $cp = scalar keys %{$self->{'c_p'}};
my $now_time = Time::HiRes::time();
$self->debug("pc stats: P_C $pc C_P $cp $now_time\n");
}
1; } |
sub _remove_from_graph
{ my ($self, $object) = @_;
if ( !defined($object) && ref($object) !~ /^Bio::/) {
$self->throw("_remove_from_graph needs a Bio object as argument");
}
if ( $self->_parent($object) ) {
my $dad = $self->_parent($object);
for my $k (0 .. $#{$self->_child($dad)}) {
if ($object eq ${$self->{'p_c'}{$dad}}[$k]) {
splice(@{$self->{'p_c'}{$dad}}, $k,1);
}
}
delete( $self->{'c_p'}{$object});
} } |
sub _remove_models
{ my ($self) = shift;
; } |
sub add_atom
{ my($self,$residue,$atom) = @_;
if (ref($residue) !~ /^Bio::Structure::Residue/) {
$self->throw("add_atom: first argument needs to be a Residue object\n");
}
if (defined $atom) {
if (ref($atom) eq "ARRAY") {
for my $a ( @{$atom} ) {
if( ! $a->isa('Bio::Structure::Atom') ) {
$self->throw("$a is not an Atom\n");
}
if ( $self->_parent($a) ) {
$self->throw("$a already belongs to a parent\n");
}
$self->_parent($a, $residue);
$self->_child($residue, $a);
}
}
elsif ( ref($atom) =~ /^Bio::Structure::Atom/ ) {
if ( $self->_parent($atom) ) {
$self->throw("$atom already belongs to a parent\n");
}
$self->_parent($atom, $residue);
$self->_child($residue, $atom);
}
}
my $array_ref = $self->_child($residue);
return $array_ref ? @{$array_ref} : (); } |
sub add_chain
{ my($self, $model, $chain) = @_;
if (ref($model) !~ /^Bio::Structure::Model/) {
$self->throw("add_chain: first argument needs to be a Model object ($model)\n");
}
if (defined $chain) {
if (ref($chain) eq "ARRAY") {
for my $c ( @{$chain} ) {
if( ! $c->isa('Bio::Structure::Chain') ) {
$self->throw("$c is not a Chain\n");
}
if ( $self->_parent($c) ) {
$self->throw("$c already assigned to a parent\n");
}
$self->_parent($c, $model);
$self->_child($model, $c);
}
}
elsif ( $chain->isa('Bio::Structure::Chain') ) {
if ( $self->_parent($chain) ) { $self->throw("$chain already assigned to a parent\n");
}
$self->_parent($chain,$model);
$self->_child($model, $chain);
}
else {
$self->throw("Supplied a $chain to add_chain, we want a Chain or list of Chains\n");
}
}
my $array_ref = $self->_child($model);
return $array_ref ? @{$array_ref} : (); } |
sub add_model
{ my($self,$entry,$model) = @_;
if ( !defined $model && ref($entry) =~ /^Bio::Structure::Model/) {
$model = $entry;
$entry = $self;
}
if ( !defined($entry) || ref($entry) !~ /^Bio::Structure::Entry/) {
$self->throw("first argument to add_model needs to be a Bio::Structure::Entry object\n");
}
if (defined $model) {
if (ref($model) eq "ARRAY") {
for my $m ( @{$model} ) {
if( ! $m->isa('Bio::Structure::Model') ) {
$self->throw("$m is not a Model\n");
}
if ( $self->_parent($m) ) {
$self->throw("$m already assigned to a parent\n");
}
push @{$self->{'model'}}, $m;
}
}
elsif ( $model->isa('Bio::Structure::Model') ) {
if ( $self->_parent($model) ) { $self->throw("$model already assigned\n");
}
push @{$self->{'model'}}, $model;
}
else {
$self->throw("Supplied a $model to add_model, we want a Model or list of Models\n");
}
}
my $array_ref = $self->{'model'};
return $array_ref ? @{$array_ref} : (); } |
sub add_residue
{ my($self,$chain,$residue) = @_;
if (ref($chain) !~ /^Bio::Structure::Chain/) {
$self->throw("add_residue: first argument needs to be a Chain object\n");
}
if (defined $residue) {
if (ref($residue) eq "ARRAY") {
for my $r ( @{$residue} ) {
if( ! $r->isa('Bio::Structure::Residue') ) {
$self->throw("$r is not a Residue\n");
}
if ( $self->_parent($r) ) {
$self->throw("$r already belongs to a parent\n");
}
$self->_parent($r, $chain);
$self->_child($chain, $r);
my $str_ref = "$self";
$r->_grandparent($str_ref);
}
}
elsif ( $residue->isa('Bio::Structure::Residue') ) {
if ( $self->_parent($residue) ) {
$self->throw("$residue already belongs to a parent\n");
}
$self->_parent($residue, $chain);
$self->_child($chain, $residue);
my $str_ref = "$self";
$residue->_grandparent($str_ref);
}
else {
$self->throw("Supplied a $residue to add_residue, we want a Residue or list of Residues\n");
}
}
my $array_ref = $self->_child($chain);
return $array_ref ? @{$array_ref} : (); } |
sub annotation
{ my ($obj,$value) = @_;
if( defined $value) {
$obj->{'annotation'} = $value;
}
return $obj->{'annotation'};
}
} |
sub chain
{ my ($self, $chain) = @_;
if ( ! $self->model ) {
$self->_create_default_model;
}
my @models = $self->model;
my $first_model = $models[0];
if ( defined $chain) {
if( (ref($chain) eq "ARRAY") ||
($chain->isa('Bio::Structure::Chain')) ) {
my @obj = $self->get_chains($first_model);
if (@obj) {
for my $c (@obj) {
$self->_remove_from_graph($c);
}
}
$self->add_chain($first_model,$chain);
}
else {
$self->throw("Supplied a $chain to chain, we want a Bio::Structure::Chain or a list of these\n");
}
}
$self->get_chains($first_model); } |
sub conect
{ my ($self, $source, $serial, $type) = @_;
if ( !defined $source ) {
$self->throw("You need to supply at least a source to conect");
}
if ( defined $serial && defined $type ) {
if ( !exists(${$self->{'conect'}}{$source}) || ref(${$self->{'conect'}}{$source} !~ /^ARRAY/ ) ) {
${$self->{'conect'}}{$source} = [];
}
my $c = $serial . "_" . $type;
push @{ ${$self->{'conect'}}{$source} }, $c;
}
return @{ ${$self->{'conect'}}{$source} }; } |
sub get_all_conect_source
{ my ($self) = shift;
my (@sources);
for my $source (sort {$a<=>$b} keys %{$self->{'conect'}}) {
push @sources, $source;
}
return @sources; } |
sub get_atom_by_serial
{ my ($self, $model, $serial) = @_;
if ($model =~ /^\d+$/ && !defined $serial) { $serial = $model;
my @m = $self->get_models($self);
$model = $m[0];
}
if ( !defined $model || ref($model) !~ /^Bio::Structure::Model/ ) {
$self->throw("Could not find (first) model\n");
}
if ( !defined $serial || ($serial !~ /^\d+$/) ) {
$self->throw("The serial number you provided looks fishy ($serial)\n");
}
for my $chain ($self->get_chains($model) ) {
for my $residue ($self->get_residues($chain) ) {
for my $atom ($self->get_atoms($residue) ) {
next unless ($atom->serial == $serial);
return $atom;
}
}
} } |
sub get_atoms
{ my ($self, $residue) = @_;
if ( !defined $residue) {
$self->throw("get_atoms needs a Residue as argument");
}
$self->add_atom($residue); } |
sub get_chains
{ my ($self, $model) = @_;
if (! defined $model) {
$model = ($self->get_models)[0];
}
$self->add_chain($model); } |
sub get_models
{ my ($self, $entry) = @_;
if ( !defined $entry) {
$entry = $self;
}
$self->add_model($entry); } |
sub get_residues
{ my ($self, $chain) = @_;
if ( !defined $chain) {
$self->throw("get_residues needs a Chain as argument");
}
$self->add_residue($chain); } |
sub id
{ my ($self, $value) = @_;
if (defined $value) {
$self->{'id'} = $value;
}
return $self->{'id'}; } |
sub master
{ my ($self, $value) = @_;
if (defined $value) {
$self->{'master'} = $value;
}
return $self->{'master'}; } |
sub model
{ my ($self, $model) = @_;
if( defined $model) {
if( (ref($model) eq "ARRAY") ||
($model->isa('Bio::Structure::Model')) ) {
my @obj = $self->model;
if (@obj) {
for my $m (@obj) {
$self->_remove_from_graph($m);
$self->{'model'} = [];
}
}
$self->add_model($self,$model);
}
else {
$self->throw("Supplied a $model to model, we want a Bio::Structure::Model or a list of these\n");
}
}
$self->get_models($self); } |
sub new
{ my ($class, @args) = @_;
my $self = $class->SUPER::new(@args);
my($id, $model, $chain, $residue ) =
$self->_rearrange([qw(
ID
MODEL
CHAIN
RESIDUE
)],
@args);
$self->{'p_c'} = ();
tie %{ $self->{'p_c'} } , "Tie::RefHash";
$self->{'c_p'} = ();
tie %{ $self->{'c_p'} } , "Tie::RefHash";
$id && $self->id($id);
$self->{'model'} = [];
$model && $self->model($model);
if($chain) {
if ( ! defined($self->model) ) { $self->_create_default_model;
}
for my $m ($self->model) { $m->chain($chain);
}
}
$residue && $self->residue($residue);
my $ann = Bio::Annotation::Collection->new;
$self->annotation($ann);
return $self; } |
sub parent
{ my ($self, $obj) = @_;
if ( !defined $obj) {
$self->throw("parent: you need to supply an argument to get the parent from\n");
}
$self->_parent($obj); } |
sub residue
{ my ($self, $residue) = @_;
if ( ! $self->model ) {
my $m = $self->_create_default_model;
$self->add_model($self,$m);
}
my @models = $self->model;
my $first_model = $models[0];
if ( ! $self->get_chains($first_model) ) {
my $c = $self->_create_default_chain;
$self->add_chain($first_model, $c);
}
my @chains = $self->get_chains($first_model);
my $first_chain = $chains[0];
if( defined $residue) {
if( (ref($residue) eq "ARRAY") ||
($residue->isa('Bio::Structure::Residue')) ) {
my @obj = $self->get_residues($first_chain);
if (@obj) {
for my $r (@obj) {
$self->_remove_from_graph($r);
}
}
$self->add_residue($first_chain,$residue);
}
else {
$self->throw("Supplied a $residue to residue, we want a Bio::Structure::Residue or a list of these\n");
}
}
$self->get_residues($first_chain); } |
sub seqres
{ my ($self, $chainid) = @_;
my $s_u = "x3 A1 x7 A3 x1 A3 x1 A3 x1 A3 x1 A3 x1 A3 x1 A3 x1 A3 x1 A3 x1 A3 x1 A3 x1 A3 x1 A3";
my (%seq_ch);
if ( !defined $chainid) {
my $m = ($self->get_models($self))[0];
my $c = ($self->get_chains($m))[0];
$chainid = $c->id;
}
my $seqres = ($self->annotation->get_Annotations("seqres"))[0];
my $seqres_string = $seqres->as_text;
$self->debug("seqres : $seqres_string\n");
$seqres_string =~ s/^Value: //;
my @l = unpack("A62" x (length($seqres_string)/62), $seqres_string); for my $line (@l) {
my ($chid, $seq) = unpack("x3 a1 x7 A51", $line);
if ($chid eq " ") {
$chid = "default";
}
$seq =~ s/(\w+)/\u\L$1/g; $seq =~ s/\s//g; $seq_ch{$chid} .= $seq;
$self->debug("seqres : $chid $seq_ch{$chid}\n");
}
if(! exists $seq_ch{$chainid} ) {
$self->warn("There is no SEQRES known for chainid\" $chainid\"");
return undef;
}
my $pseq = Bio::PrimarySeq->new(-alphabet => 'protein');
$pseq = Bio::SeqUtils->seq3in($pseq,$seq_ch{$chainid});
my $id = $self->id . "_" . $chainid;
$pseq->id($id);
return $pseq; } |
General documentation
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to one
of the Bioperl mailing lists. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bio.perl.org/MailList.html - About the mailing lists
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via email
or the web:
bioperl-bugs@bio.perl.org
http://bugzilla.bioperl.org/
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _