BioPerl-DB

 view release on metacpan or  search on metacpan

lib/Bio/DB/BioSQL/TermAdaptor.pm  view on Meta::CPAN

		(index($dbl->primary_id," ") > 0));
	# now make persistent and serialize if necessary
	if(!($dbl->isa("Bio::DB::PersistentObjectI") && $dbl->primary_key())){
	    $dbl = $dbladp->create($dbl);
	}
	$ok = $dbl && $ok;
	# add the association between term and dbxref
	$dbl->adaptor->add_association(-objs => [$obj, $dbl]) if $dbl;
    }
    # done
    $obj->foreign_key_slot($saved_foreign_key_slot);
    return $ok;
}

=head2 attach_children

 Title   : attach_children
 Usage   :
 Function: Possibly retrieve and attach child objects of the given object.

           This is needed when whole object trees are supposed to be
           built when a base object is queried for and returned. An
           example would be Bio::SeqI objects and all the annotation
           objects that hang off of it.

           This is called by the find_by_XXXX() methods once the base
           object has been built.

           An ontology term has synonyms and dbxrefs as children.

 Example :
 Returns : TRUE on success, and FALSE otherwise.
 Args    : The object for which to find and to which to attach the child
           objects.


=cut

sub attach_children{
    my ($self,$obj) = @_;
    my $ok = 1;

    # get and attach the dbxrefs
    my $dbladp = $self->db->get_object_adaptor("Bio::Annotation::DBLink");
    my $qres = $dbladp->find_by_association(-objs => [$obj,$dbladp]);
    while(my $dbl = $qres->next_object()) {
      # terms store dblinks as objects
      $obj->add_dbxref([$dbl]);
    }
    # retrieve the synonyms (synonyms aren't objects in their own right
    # in bioperl - although they could be)
    $ok = $self->get_synonyms($obj) && $ok;
    # done
    return $ok;
}

=head2 remove_children

 Title   : remove_children
 Usage   :
 Function: This method is to cascade deletes in maintained objects.


 Example :
 Returns : TRUE on success and FALSE otherwise
 Args    : The persistent object that was just removed from the database.
           Additional (named) parameter, as passed to remove().


=cut

sub remove_children{
    return 1;
}

=head2 instantiate_from_row

 Title   : instantiate_from_row
 Usage   :
 Function: Instantiates the class this object is an adaptor for, and populates
           it with values from columns of the row.

           This implementation calls populate_from_row() to do the
           real job.

 Example :
 Returns : An object, or undef, if the row contains no values
 Args    : A reference to an array of column values. The first column is the
           primary key, the other columns are expected to be in the order 
           returned by get_persistent_slots().

           Optionally, the object factory to be used for instantiating
           the proper class. The adaptor must be able to instantiate a
           default class if this value is undef.


=cut

sub instantiate_from_row{
    my ($self,$row,$fact) = @_;
    my $obj;

    if($row && @$row) {
	if($fact) {
	    $obj = $fact->create_object();
	} else {
	    $obj = Bio::Ontology::Term->new();
	}
        # in order to store rank we need a persistent object - sooner or later
        # it will be turned into one anyway
        if (!$obj->isa("Bio::DB::PersistentObjectI")) {
            $obj = $self->create_persistent($obj);
        }
        # now populate
	$self->populate_from_row($obj, $row);
    }
    return $obj;
}

=head2 populate_from_row



( run in 2.372 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )