[Bioperl-l] Searching by source in Bio::DB::SeqFeature::Store?

Sendu Bala bix at sendu.me.uk
Wed Oct 10 11:10:45 EDT 2007


Lincoln Stein wrote:
> Hi Sendu,
> 
> This may be a glaring omission on my part. Try searching for:
> 
>  @feats = $db->get_features_by_type(":$source");
> 
> Remove the colon in front of $source.

It doesn't, unfortunately, colon or not. get_features_by_type is 
implemented using _features(-type => ), just like features(). In any 
case, I'm searching for multiple things at the same time so need to use 
the features() method.


The following patch seems to do the job in my hands, allowing:

@feats = $db->features(-source => 'Z');
to work as expected.

Also, we now have:
@feats = $db->features(-type => 'X', -source => 'Z');
as a nicer (ie. matching the syntax the user used to create the feature 
in the first place) alternative to:
@feats = $db->features(-type => 'X:Y');

Of course, this patch is specific to the mysql implementation. You may 
want to check it over to see if it is sane, see if there is a cleaner 
way to do it, or see if there's a more general way to apply it to all 
implementations.


RCS file: 
/home/repository/bioperl/bioperl-live/Bio/DB/SeqFeature/Store/DBI/mysql.pm,v
retrieving revision 1.33
diff -r1.33 mysql.pm
724c724,725
<       $iterator
---
 >       $iterator,
 >       $sources
731a733
 >             ['SOURCE','SOURCES']
760c762,785
<
---
 >
 >   if (defined($sources)) {
 >     my @sources = ref($sources) eq 'ARRAY' ? @{$sources} : ($sources);
 >     if (defined($types)) {
 >         my @types = ref($types) eq 'ARRAY' ? @{$types} : ($types);
 >         my @final_types;
 >         foreach my $type (@types) {
 >             # *** not sure what to do if user supplies both -source
 >             #     and -type where the type includes a source!
 >             if ($type =~ /:/) {
 >                 push(@final_types, $type);
 >             }
 >             else {
 >                 foreach my $source (@sources) {
 >                     push(@final_types, $type.':'.$source);
 >                 }
 >             }
 >         }
 >         $types = \@final_types;
 >     }
 >     else {
 >         $types = [map { ':'.$_ } @sources];
 >     }
 >   }
939,940c964,971
<       push @matches,"tl.tag=?";
<       push @args,"$primary_tag:$source_tag";
---
 >       if (length($primary_tag)) {
 >         push @matches,"tl.tag=?";
 >         push @args,"$primary_tag:$source_tag";
 >       }
 >       else {
 >         push @matches,"tl.tag LIKE ?";
 >         push @args,"%:$source_tag";
 >       }


More information about the Bioperl-l mailing list