[BioSQL-l] find_by_query() usage ?
Hilmar Lapp
hlapp at gnf.org
Sat Jul 12 16:11:20 EDT 2003
On Friday, July 11, 2003, at 10:36 AM, albert vilella wrote:
>
> I'm in a similar situation. I find that the simplest example (from
> query.t) is not working:
I'm not sure I understand what you're trying to do. Are you trying to
run make test and it fails the query.t test? If so, can you run
$ make test_query
If that fails any of the tests, please do
$ export HARNESS_VERBOSE=1 # bash or ksh
*or*
$ setenv HARNESS_VERBOSE 1 # tcsh or csh
then
$ make test_query TEST_VERBOSE=1
capture the output into a file and send it to me. Also, make sure that
you have a recent checkout of bioperl-db installed, and at least
bioperl-1.2.1 (but bioperl-1.2.2 is much better).
If the aforementioned test run does succeed the problem is obviously
with your script or whatever you use to access bioperl-db ...
>
> <snip>
> my $sqlgen = Bio::DB::Query::SqlGenerator->new(-query => $query);
You know that you really don't need this on the client side unless you
want to print out the actual sql statement that the mapper maps this to?
> $query = Bio::DB::Query::BioQuery->new();
# the preceding stmt is OK and necessary, but:
> $mapper = Bio::DB::BioSQL::mysql::BasePersistenceAdaptorDriver->new();
Same as before. Unless you want to print out the sql statement, you
don't need this.
>
> $query->selectelts(["accession_number","version"]);
Same as before. If you do this on a query object that you pass on to
find_by_query() then the select elements will inadvertantly be
overwritten, because the adaptor needs to have control over that.
> $query->datacollections(["Bio::PrimarySeqI"]);
You don't specify a where condition, meaning you're selecting all
entries from the bioentry table. Is that what you intended?
> $tquery = $query->translate_query($mapper);
> $sql = $sqlgen->generate_sql($tquery);
Same as before, you don't need either of these in client code.
>
> my $dbadap= Bio::DB::BioDB->new(
> -database => 'biosql',
> -dbname => 'biosql',
> -user => 'root',
> -driver => 'mysql');
>
> my $objadap=$dbadap->get_object_adaptor("Bio::SeqI");
>
> my $result=$objadap->find_by_query();
You need to pass on the query object here. Otherwise you'll see the
undefined object error that you saw.
>
> foreach my $obj ($result->each_Object()) {
You know what you're doing here? each_object(), as opposed to
next_object(), will first retrieve the entire result set into an array
of objects and then return that array to you. If you get a large number
of rows returned this potentially challenges the memory.
> print "Id : $obj->display_id\n";
> }
> </snip>
>
> Can't call method "translate_query" on an undefined value at
> /usr/lib/perl5/site_perl/5.8.0/Bio/DB/BioSQL/BaseDriver.pm line 1097.
>
> Maybe I'm missing something. Any help?
>
> I find particularly tricky the mapping (as in $mapper) of the tables in
> biosql. Where can I find info about this?
In the code :) I'm actually not kidding. This is the corner where
documentation is mostly lacking.
For usual use-cases you do not have to be concerned about what $mapper
does behind the scenes. In fact, that's the whole idea here. When
constructing the query object you just stay within the object API and
don't worry about the schema (ideally at least). I.e., if you want to
constrain by Bio::Seq::display_id() you don't worry what this maps to
in the schema; you just reference the name in the object API:
$query->where("display_id = 'CALM_HUMAN'");
>
> One example is if I'm trying to get the aminoacidic sequence of a CDS
> (located as a seqfeature_qualifier_value of type 15) by it's gene
> modifier (like /gene="rpL31"). How would that query be constructed?
In this case you want to *obtain* the amino acid sequence, not
*constrain* by it, right? Assuming that rpL31 is the display_id of the
sequence object, you'd do
$query = Bio::DB::Query::BioQuery->new(
-datacollections => ["Bio::SeqI seq"],
-where => ["seq.display_id = 'rpL31'"]);
$result = $objadap->find_by_query($query);
while(my $seq = $result->next_object()) {
print $seq->accession_number,"\t",$seq->description,"\n";
foreach my $cds (grep { $_->primary_tag eq 'CDS'; }
$seq->get_SeqFeatures()) {
my $aaseq = $cds->spliced_seq->translate();
# or write to a fasta SeqIO output stream
print $aaseq->seq(),"\n";
}
}
Hth,
-hilmar
>
> Thanks in advance,
>
> Albert
>
>
> <signature.asc>_______________________________________________
> 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 BioSQL-l
mailing list