[Bioperl-l] Re: should Bio::PrimarySeq be storage-independent after bioperl-db appear?

Hilmar Lapp hlapp at gnf.org
Sun May 18 23:51:36 EDT 2003


On Sunday, May 18, 2003, at 08:40  PM, Juguang Xiao wrote:

>
> my $seq = Bio::Seq->new(
>     -namespace => 'juguang'
>     -id => 'id1'
> );
>
> my $seq_adaptor = $db->get_object_adaptor('Bio::SeqI');
>
> my $pseq = $seq_adaptor->find_by_unique_key($seq);
> $seq = $pseq->obj;
> ; # break point.
>
> And now, $seq is of a Bio::PrimarySeq, not a Bio::Seq, that i cannot 
> control.
>

It should be a Bio::Seq object. I ran your code snippet and what I find 
is that it is. If at your breakpoint you say

	DB<nn> print $pseq->obj

what does it print?

Generally speaking there are a couple of ways you can control what will 
happen if the matching entry is found. I haven't documented those on 
the interface, but the following is mostly documented on the abstract 
base implementation, Bio::DB::BioSQL::BasePersistenceAdaptor. So, this 
is what is going to happen, iff a matching entry is found (if none is 
found, the method just returns undef).

	1) If you pass an object factory as named parameter -obj_factory, then 
that will be used to instantiate a new object. Otherwise the following 
will operate on the object you passed in.
	2) The object will be made persistent by a call to 
$self->create_persistent($obj) ($self is the persistence adaptor) 
unless it is already a persistent object.
	3) The (now persistent) object will be populated with the values found 
in the database record, and its primary key attribute will be set.
	4) The (now persistent) object is returned to the caller (if the 
object was persistent, it is the same as the one passed in, otherwise 
$pobj->obj will return the object originally passed in, unless you 
specified an object factory).

Passing in an object factory is particularly useful (in fact necessary) 
if

	- you don't want the object you used to represent the unique key to be 
populated (and hence possibly partially overwritten) by the column 
values in the database, or
	- you want a different object type to be created than the one 
represented by the unique key query object. E.g., you could do

	$seq = Bio::PrimarySeq->new(-namespace => 'bla', -accession_number => 
'x1234');
	$adp = $db->get_object_adaptor("Bio::SeqI");
	$dbseq = $adp->find_by_unique_key($seq, -obj_factory => 
Bio::Seq::SeqFactory->new(-type => "Bio::Seq::RichSeq"));
	print ref($dbseq->obj),"\n"; # will print Bio::Seq::RichSeq

Basically all find_by_XXX() methods accept an object factory to be 
passed in.


>> If you remove the adaptor, you are removing the persistence 
>> implementation by delegation. What is your proposal to maintain 
>> persistence instead? Through a naming context?
>>
>
> Even if adaptor is removed from Bio::PrimarySeq, NOT 
> Bio::DB::Persistence::PrimarySeq, we can use above code to re-generate 
> a same persistence, no?

The adaptor is not stored in the Bio::PrimarySeq object. The debugger 
output may look like it is, but as a matter of fact it isn't. If you 
look closely at what 'primary_seq' (in the Bio::Seq blessed hash) 
points to you will see that it is a Bio::DB::Persistent::PrimarySeq 
object. That one does hold the adaptor, as it is a persistent object. 
So, if $pseq is a persistent Bio::Seq object, do the following:

	print ref($pseq), "\n";                   # Bio::DB::Persistent::Seq
	print ref($pseq->obj), "\n";              # Bio::Seq
	print ref($pseq->obj->primary_seq), "\n"; # 
Bio::DB::Persistent::PrimarySeq
	print ref($pseq->primary_seq), "\n";      # (same as before)
	print $pseq->primary_seq == $pseq->obj->primary_seq ? "same 
instance\n" : "bummer!\n";
	                                          # same instance
	print ref($pseq->primary_seq->obj), "\n"; # Bio::PrimarySeq

I hope this helps.

	-hilmar


>
> Thanks.
>
> Juguang
>
> ------------ATGCCGAGCTTNNNNCT--------------
> Juguang Xiao
> Temasek Life Sciences Laboratory, National University of Singapore
> 1 Research Link,  Singapore 117604
> juguang at tll.org.sg
>
>
-- 
-------------------------------------------------------------
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