BioPerl-DB

 view release on metacpan or  search on metacpan

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

           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.

           For Bio::SeqFeatureIs, we need to get the location,
           tag/value pairs and other annotation, and possibly
           sub-seqfeatures. The latter is not implemented yet.

 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;

    # look up the location(s) for this feature by FK
    my $query = Bio::DB::Query::BioQuery->new(
                                   -datacollections => ["Bio::LocationI t1"],
		                   -where => ["t1.Bio::SeqFeatureI = ?"]);
    my $qres = $self->_loc_adaptor()->find_by_query(
				   $query,
				   -name => "FIND LOCATION BY FEATURE",
				   -values => [$obj->primary_key()]);
    my $locs = $qres->each_Object();
    if(@$locs == 1) {
	$obj->location($locs->[0]);
    } elsif(@$locs > 1) {
	$obj->location(Bio::Location::Split->new(-locations => $locs));
    }
    $ok = @$locs > 0;
    #
    # look up annotation for this feature by association
    #
    my $annadp = $self->_anncoll_adaptor();
    # we use an adaptor to transparently add all annotation through the
    # AnnotationCollectionI interface
    my $ac = $self->_featann_adaptor();
    $ac->feature($obj);
    # now have the adaptor find by association
    $qres = $annadp->find_by_association(-objs => [$ac,$obj]);
    # no need to attach the annotation collection to the feature - the
    # annotation adaptor added everything to the feature transparently
    $qres->next_object(); # remove it from the stack, just to be sure
    # done
    return $ok;
}

=head2 remove_children

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

           We need to undefine the primary keys of location objects
           here.

 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{
    my $self = shift;
    my $obj = shift;
    my $loc = $obj->location();
    my @locs = 
	$loc->isa("Bio::Location::SplitLocationI") ?
	$loc->sub_Location() : ($loc);
    foreach (@locs) {
	$_->primary_key(undef) if $_->isa("Bio::DB::PersistentObjectI");
    }
    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,
           a Bio::Factory::SequenceFactoryI compliant object to be
           used for creating the object.


=cut

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

    if($row && @$row) {
	if($fact) {
	    $obj = $fact->create_object();
	} else {
	    $obj = Bio::DB::Persistent::SeqFeature->new(
                                 -object => Bio::SeqFeature::Generic->new(),
				 -adaptor => $self);
	}
	$self->populate_from_row($obj, $row);
    }
    return $obj;
}



( run in 0.859 second using v1.01-cache-2.11-cpan-39bf76dae61 )