[Bioperl-l] how to use BioQuery

Hilmar Lapp hlapp at gnf.org
Mon Jun 9 02:53:18 EDT 2003


On Sunday, June 8, 2003, at 08:27  PM, Juguang Xiao wrote:

>>
>> How to use BioQuery is the most undocumented piece of the story.  
>> t/query.t is probably the single most useful place to get a grasp of  
>> what the ideas are. It may also be useful to check in the  
>> Bio/DB/BioSQL directory for adaptors that implement (i.e., override)  
>> attach_children() and attach_foreign_key_objects() to how to find  
>> objects by foreign key or by association.
>>
>
> In which module the mapping from bioperl module name, say Bio::SeqI,  
> to schema table name, bioentry (I guess) is defined?
>

The base object-relational mapping is in Bio/DB/BioSQL/BaseDriver.pm,  
right at the top of the code. Note that the RDBMS-specific drivers may  
override it in Bio/DB/BioSQL/<driver>/BasePersistenceAdaptorDriver.pm.  
Currently, the one for Oracle does this.

>
>> Also, the mapping and translation code in BioQuery.pm is not very  
>> robust. I had to write it in a crunch and have since never found the  
>> time to rewrite it such that it becomes at least remotely  
>> comprehensible. There may be lots of bugs lurking, as it is not  
>> really tested beyond what t/query.t and the adaptors test.
>
> I have the similar sick code to use BioQuery. Can dear doctor help to  
> diagnose it? :-) Thanks.
>
> The scripts:
>
> use Bio::DB::BioDB;
>
> my $db = Bio::DB::BioDB->new(
>     -database => 'biosql',
>     -host => 'mysql-dev',
>     -dbname => 'juguang_biosql_embl',
>     -driver => 'mysql',
>     -user => 'root'
> );
>
> use Bio::DB::Query::BioQuery;
>
> my $query = Bio::DB::Query::BioQuery->new(
>     -datacollections => [
>         'Bio::SeqI seq', 'Bio::Species=>Bio::SeqI sp'],
>     -where => ['sp.name like ?']
                     ^^^^^

You need to use object slots here, not relational table columns. The  
mapper will deduce the latter. I.e., what you want to use here is  
sp.binomial (as defined in Bio::Species), not sp.name (Bio::Species  
doesn't have a slot named 'name').

The problem here is that if you want to query for 'house mouse', it is  
not a binomial (i.e., scientific name), but the common name. So you'd  
actually have to use 'sp.common_name'. The problem with this is that in  
the biosql taxon model this is now not just another column in the same  
table, but necessitates a different constraint on  
taxon_name.name_class. You cannot map this nicely back and forth  
between object and relational model, because Bio::Species is  
incompatible with the biosql taxon tables.

This problem may go away once Bio::Taxonomy gets fully stable and  
eventually replaces Bio::Species. In the meantime, you need to work  
with a kludge:

	-where => ["sp.binomial like ?", "sp.name_class = 'common name'"]

Be careful though to remove the second condition (or replace with  
'scientific name') if you want to search by scientific name.

Hth, -hilmar


> );
>
> my $seq_adaptor = $db->get_object_adaptor('Bio::SeqI');
> my $result = $seq_adaptor->find_by_query($query,
>     -values => ['house mouse']
> );
>
> while(my $seq = $result->next_object){
>     print ref($seq) ."\n";
> }
> ######################################
> The error message:
>
>
> ------------- EXCEPTION  -------------
> MSG: slot 'name' not mapped to column for table taxon_name
> STACK Bio::DB::Query::BioQuery::_map_slot_to_col  
> /Home_R1/juguang/src/bioperl-db//Bio/DB/Query/BioQuery.pm:487
> STACK Bio::DB::Query::BioQuery::_map_constraint_slots_to_columns  
> /Home_R1/juguang/src/bioperl-db//Bio/DB/Query/BioQuery.pm:369
> STACK Bio::DB::Query::BioQuery::translate_query  
> /Home_R1/juguang/src/bioperl-db//Bio/DB/Query/BioQuery.pm:305
> STACK Bio::DB::BioSQL::BaseDriver::translate_query  
> /Home_R1/juguang/src/bioperl-db//Bio/DB/BioSQL/BaseDriver.pm:1097
> STACK Bio::DB::BioSQL::BasePersistenceAdaptor::find_by_query  
> /Home_R1/juguang/src/bioperl-db//Bio/DB/BioSQL/ 
> BasePersistenceAdaptor.pm:1154
> STACK toplevel find_by_species.pl:22
>
>
> Juguang
>
>
-- 
-------------------------------------------------------------
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