[Bioperl-l] Re: [BioSQL-l] removing features from a sequence
Hilmar Lapp
hlapp at gnf.org
Mon Oct 3 19:59:17 EDT 2005
Yeah I guess this is one of the gotcha's that deserve better
documentation. The bioperl-db adaptors will not automatically 'sync'
the database with an object. The reason is that there are too many
flavors of what you could possibly want as a user, so instead of making
decisions for you you need to make explicit what you want; however,
doing so should be reasonably simple.
So here's what's going on and how you can fix it.
First, $dbseq->remove_SeqFeatures() is a Bio::SeqI method present for
all SeqI objects, not just persistent ones. Except in a few cases where
lazy loading is already implemented, methods from the native Bioperl
API are not overridden for persistent objects; i.e., you can manipulate
your persistent object to your heart's content and nothing will happen
to the respective row(s) in the database. You need to say
$dbseq->store() to let your changes take effect. But see below!
Second, $dbseq->store() will only store it; i.e., it will update the
object and either update or insert all attached objects (like features,
annotations, etc). If you want to delete attached objects then you need
to do so explicitly by calling $pobj->remove().
For example, in your case:
# ... find $dbseq ...
# delete all features from the database
# Note: I could use $dbseq->get_SeqFeatures() if I
# wanted to keep the features on the in-memory object
foreach my $pfeat ($dbseq->remove_SeqFeatures()) {
$pfeat->remove();
}
# now $dbseq and the object in the db don't have features
Same thing for annotation. You can check out some of the sample closure
implementations for merging objects provided in the scripts/biosql
directory of bioperl-db, for instance freshen-annot.pl deletes all
annotation (in the db) from the existing object.
Hth,
-hilmar
On Oct 3, 2005, at 10:59 AM, Amit Indap wrote:
> Hi,
>
> I was trying to remove features for sequences stored in my BioSQL
> database. Once I run the code snippet below to remove sequence
> features, I tested to see if the features really had been removed by
> running a script that reterieves seq features from bioentries.
> Unfortunately, the features are still there. I'm still learning my
> around the Bio::DB API
>
> Here is my code to attempts to remove sequence features:
>
> foreach (@accs) {
>
> my $acc = $_;
> my $adp = $dbadp->get_object_adaptor("Bio::SeqI");
>
> my $seq = Bio::Seq->new(-accession_number => $acc,
> -namespace => $namespace
> );
>
>
> my $dbseq = $adp->find_by_unique_key($seq);
> warn $acc, " not found in database $namespace" unless $dbseq;
>
> $dbseq->remove_SeqFeatures(); # remove seqfeatures
>
> $dbseq->commit();
> print LOG "removed all seq features for $acc\n";
> }
>
>
>
> --
> Amit Indap
> http://www.bscb.cornell.edu/Homepages/Amit_Indap/
>
> _______________________________________________
> BioSQL-l mailing list
> BioSQL-l at open-bio.org
> http://open-bio.org/mailman/listinfo/biosql-l
>
--
-------------------------------------------------------------
Hilmar Lapp email: lapp at gnf.org
GNF, San Diego, Ca. 92121 phone: +1-858-812-1757
-------------------------------------------------------------
More information about the Bioperl-l
mailing list