Bio::EnsEMBL::Compara::Graph
CGObject
Toolbar
Summary
CGObject - DESCRIPTION of Object
Package variables
No package variables defined.
Included modules
Synopsis
Description
Abstract superclass to mimic some of the functionality of Foundation/NSObject
Implements a 'reference count' system based on the OpenStep retain/release design.
Implements a metadata tagging system.
Is used as the Root class for the Compara::Graph system (Node and Link) which is
the foundation on which Compara::Graph (Node/Link) and Compara::NestedSet are built
Methods
Methods description
Arg [1] : (opt.) subcalss of Bio::EnsEMBL::DBSQL::BaseAdaptor Example : my $object_adaptor = $object->adaptor(); Example : $object->adaptor($object_adaptor); Description: Getter/Setter for the adaptor this object uses for database interaction. Returntype : subclass of Bio::EnsEMBL::DBSQL::BaseAdaptor Exceptions : none Caller : general |
Description: adds metadata tags to a node. Both tag and value are added as metdata with the added ability to retreive the value given the tag (like a perl hash). In case of one to many relation i.e. one tag and different values associated with it, the values are returned in a array reference. Arg [1] : <string> tag Arg [2] : (optional)<string> value Arg [3] : (optional) <int> allows overloading the tag with different values default is 0 (no overloading allowed, one tag points to one value) Example : $ns_node->add_tag('scientific name', 'Mammalia'); $ns_node->add_tag('mammals_rosette'); Returntype : none Exceptions : none Caller : general |
Overview : copies object content but not identity copies tags, but not objc_id and adaptor Example : my $clone = $self->copy; Returntype : Bio::EnsEMBL::Compara::Graph::CGObject Exceptions : none Caller : general |
Example : my $nsetID = $object->obj_id(); Description: returns the unique identifier of this object. Returntype : <string> uuid Exceptions : none Caller : general |
Methods code
sub DESTROY
{ my $self = shift;
if(defined($self->{'_refcount'}) and $self->{'_refcount'}>0) {
printf("WARNING DESTROY refcount:%d (%s)%s %s\n",
$self->refcount, $self->node_id, $self->get_tagvalue('name'), $self);
}
$self->SUPER::DESTROY if $self->can("SUPER::DESTROY"); } |
sub _load_tags
{ my $self = shift;
return if(defined($self->{'_tags'}));
$self->{'_tags'} = {};
if($self->adaptor and $self->adaptor->can("_load_tagvalues")) {
$self->adaptor->_load_tagvalues($self);
} } |
sub adaptor
{ my $self = shift;
$self->{'_adaptor'} = shift if(@_);
return $self->{'_adaptor'}; } |
sub add_tag
{ my $self = shift;
my $tag = shift;
my $value = shift;
my $allow_overloading = shift;
unless (defined $allow_overloading) {
$allow_overloading = 0;
}
unless(defined($self->{'_tags'})) { $self->{'_tags'} = {}; }
return unless(defined($tag));
$value='' unless (defined $value);
if ( ! defined $self->{'_tags'}->{$tag} || ! $allow_overloading ) {
$self->{'_tags'}->{$tag} = $value;
} elsif ( ref($self->{'_tags'}->{$tag}) eq 'ARRAY' ) {
push @{$self->{'_tags'}->{$tag}}, $value;
} else {
$self->{'_tags'}->{$tag} = [ $self->{'_tags'}->{$tag}, $value ];
} } |
sub alloc
{ my ($class, @args) = @_;
my $self = {};
bless $self,$class;
return $self; } |
sub dealloc
{ my $self = shift;
} |
sub get_all_tags
{ my $self = shift;
$self->_load_tags;
return keys(%{$self->{'_tags'}}); } |
sub get_tagvalue
{ my $self = shift;
my $tag = shift;
return '' unless($self->has_tag($tag));
return $self->{'_tags'}->{$tag}; } |
sub get_tagvalue_hash
{ my $self = shift;
$self->_load_tags;
return $self->{'_tags'}; } |
sub has_tag
{ my $self = shift;
my $tag = shift;
$self->_load_tags;
return 1 if(defined($self->{'_tags'}->{$tag}));
return 0 } |
sub init
{ my $self = shift;
$self->{'_node_id'} = undef;
$self->{'_adaptor'} = undef;
$self->{'_refcount'} = 0;
return $self; } |
sub name
{ my $self = shift;
my $value = shift;
if(defined($value)) { $self->add_tag('name', $value); }
else { $value = $self->get_tagvalue('name'); }
return $value;
}
1; } |
sub new
{ my ($class, @args) = @_;
$class = ref($class) if (ref($class));
my $self = $class->alloc(@args);
$self->init;
return $self; } |
sub obj_id
{ my $self = shift;
return $self;
unless(defined($self->{'_cgobject_id'})) {
$self->{'_cgobject_id'} = $self;
}
return $self->{'_cgobject_id'}; } |
sub refcount
{ my $self = shift;
return $self->{'_refcount'};
}
} |
sub release
{ my $self = shift;
$self->dealloc;
return $self;
throw("calling release on object which hasn't been retained")
unless(defined($self->{'_refcount'}));
$self->{'_refcount'}--;
return $self if($self->refcount > 0);
$self->dealloc;
return undef; } |
sub retain
{ my $self = shift;
return $self;
$self->{'_refcount'}=0 unless(defined($self->{'_refcount'}));
$self->{'_refcount'}++;
return $self; } |
sub store
{ my $self = shift;
throw("adaptor must be defined") unless($self->adaptor);
$self->adaptor->store($self) if $self->adaptor->can("store");
}
} |
sub store_tag
{ my $self = shift;
my $tag = shift;
my $value = shift;
$self->add_tag($tag, $value);
if($self->adaptor and $self->adaptor->can("_store_tagvalue")) {
$self->adaptor->_store_tagvalue($self->node_id, $tag, $value);
} } |
General documentation
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _