[BioSQL-l] How to get a Seq object from Bio::DB::Persistent::Seq
Daniel Lang
daniel.lang at biologie.uni-freiburg.de
Thu Jun 3 04:01:00 EDT 2004
Thank you both for your extensive and quick answers answers...
Hilmar Lapp wrote:
>
> On Jun 2, 2004, at 2:31 AM, Marc Logghe wrote:
>
>> Hi Daniel,
>>
>>> I want to copy the object into a fresh seq object, to add new data and
>>> store it afterwarts as a new entry with a different namespace.
>>
>>
>> I don't know what will happen if you change the namespace of the
>> persistent object and store it. Probably a lot of constraints ;-)
>> (Not tested though !)
>> A route you could follow is to
>> 1. fetch the plain seq object
>
>
> You don't really need to do this even.
>
>> 2. change the namespace and add some features
>> 3. make it persistent and
>> 4. store it.
>>
>
> Right, that would be the way.
>
>> suppose you have your persistent seq in $pseq;
>> my $seq = $pseq->obj;
>> $seq->namespace('my_new_namespace')
>>
>
> Again, no real reason to get the wrapped object unless you explicitly
> need a non-persistent object.
>
> Persistent objects in bioperl-db speak are not tightly coupled to the
> database; in fact you might say they are uncoupled. What I mean is that
> you may change any attribute or property of the persistent object
> without having any effect on what is stored in the database. Only once
> you ask the object to store itself will it sync the changes to the
> database.
>
> So, you may simply do the following:
>
> while (my $pseq = $query->next_object) {
> # e.g. change namespace
> $pseq->namespace("my namespace");
> # change other things, e.g., tack on another feature
> # (which may or may not be a persistent object)
> $pseq->add_SeqFeature($myfeature);
> # ...
> # when done making changes, sync to database
> $pseq->store();
> }
>
> Note that this will update bioentries to change their namespace, not
> duplicate them in another namespace. If you wanted to duplicate a
> sequence in another namespace, possibly with some changes on the
> annotation, replace $pseq->store() with the following:
>
> ...
> # trigger insert by making the object forget
> # its primary key
> $pseq->primary_key(undef);
> # we need to duplicate dependent objects
> # (children) too, like features
> foreach my $pfea ($pseq->get_SeqFeatures) {
> $pfea->primary_key(undef)
> if $pfea->isa("Bio::DB::PersistentObjectI");
> # features have locations
> $pfea->location->primary_key(undef)
> if $pfea->location->isa("Bio::DB::PersistentObjectI");
> }
> # do the insert
> $pseq->create();
>
> You will note that this sample code actually does not cover all
> possible cases; e.g., if there are sub-features, or split locations.
> But you get the idea. Nevertheless, there is indeed a case for having a
> convenience method for de-persisting objects to better support those
> who want to duplicate them.
>
>> # do some other stuff
>>
>> my $new_pseq = $db->create_persistent($seq);
>> $new_pseq->create;
>>
>
> Note that this has problems associated as outlined above:
>
> - if you wanted to update the sequence, this would not do that
> - you will update the features though so that the original sequence
> won't have any features anymore (a feature has a foreign key to exactly
> one bioentry)
>
>>>
>>> Additionally, I'm quite confused by the mapping of bioperl objects to
>>> biosql tables(e.g. for generating a Bio:Query with datacollections):
>>> connections like bioenty<->seqI are obvious, but the rest?
>>> Is there a something like a overview list of the object mapping?
>>
>> Have a look at perldoc -m Bio::DB::BioSQL::BaseDriver, more
>> precisely at the %object_entity_map variable.
>> Examples of queries you might find in
>> http://cvs.bioperl.org/cgi-bin/viewcvs/viewcvs.cgi/bioperl-db/t/
>> query.t?rev=1.9&cvsroot=bioperl&content-type=text/vnd.viewcvs-markup
>> and also the presentation given at BOSC2003:
>> http://open-bio.org/bosc2003/slides/Persistent_Bioperl_BOSC03.pdf
>>
>
> Right. Thanks for helping Marc.
>
> -hilmar
>
--
Daniel Lang
University of Freiburg, Plant Biotechnology
Sonnenstr. 5, D-79104 Freiburg
phone: +49 761 203 6988
homepage: http://www.plant-biotech.net/
e-mail: daniel.lang at biologie.uni-freiburg.de
#################################################
>REALITY.SYS corrupted: Reboot universe? (Y/N/A)
#################################################
Join MOSS 2004 in Freiburg, Germany from September 12th - 15th:
registration and information @ http://www.plant-biotech.net/moss2004
More information about the BioSQL-l
mailing list