Bio-DB-Das-Chado
view release on metacpan or search on metacpan
lib/Bio/DB/Das/Chado.pm view on Meta::CPAN
my $self = shift;
my $f_id = shift;
my @features = $self->features(-feature_id => $f_id);
return $features[0];
}
*fetch = *get_feature_by_primary_id = \&get_feature_by_feature_id;
sub _complex_search {
my $self = shift;
my $name = shift;
my $class= shift;
warn "name before wildcard subs:$name\n" if DEBUG;
$name = "\%$name" unless (0 == index($name, "%"));
$name = "$name%" unless (0 == index(reverse($name), "%"));
warn "name after wildcard subs:$name\n" if DEBUG;
my $select_part = "select ga.feature_id ";
my $from_part = "from gffatts ga ";
my $where_part = "where lower(ga.attribute) like ? ";
if ($class) {
my $type = $self->name2term($class);
return unless $type;
$from_part .= ", feature f ";
$where_part.= "and ga.feature_id = f.feature_id and "
."f.type_id = $type";
}
$where_part .= " and organism_id = ".$self->organism_id
if $self->organism_id;
my $query = $select_part . $from_part . $where_part;
return ($name, $query);
}
sub _search_name_prep {
my $self = shift;
my $name = shift;
if ($self->fulltext) {
# For full-text search, the appropriate extension wildcard
# is ':*' for prefix-matching. There are limitations to
# full-text search in that we cannot find internal parts of
# words, so wildcards can only come at the ends of phrases/
# lexemes. Internal * are converted by tsquery into & [LP]
$name =~ s/_/\\_/g; # escape underscores in name
$name =~ s/(?<=\s)\*//g; # lose prefix wildcards (word start)
$name =~ s/(?<=^)\*//g; # lose prefix wildcards (query start)
$name =~ s/\*(?=$)/:\*/g; # convert trailing * (query end) into :*
$name =~ s/\*(?=\s)/:\*/g; # convert trailing * (word end) into :*
}
else {
$name =~ s/_/\\_/g; # escape underscores in name
$name =~ s/\%/\\%/g; # ditto for percent signs
$name =~ s/\*/%/g;
}
return $name;
}
=head2 srcfeature2name
returns a srcfeature name given a srcfeature_id
=cut
sub srcfeature2name {
my $self = shift;
my $id = shift;
return $self->{'srcfeature_id'}->{$id} if $self->{'srcfeature_id'}->{$id};
my $sth = $self->dbh->prepare("select name from feature "
."where feature_id = ?");
$sth->execute($id);
my $hashref = $sth->fetchrow_hashref;
$self->{'srcfeature_id'}->{$id} = $$hashref{'name'};
$sth->finish;
return $self->{'srcfeature_id'}->{$id};
}
=head2 gff_source_db_id
Title : gff_source_db_id
Function: caches the chado db_id from the chado db table
=cut
sub gff_source_db_id {
my $self = shift;
return $self->{'gff_source_db_id'} if $self->{'gff_source_db_id'};
my $sth = $self->dbh->prepare("
select db_id from db
where name = 'GFF_source'");
$sth->execute();
my $hashref = $sth->fetchrow_hashref;
$self->{'gff_source_db_id'} = $$hashref{'db_id'};
$sth->finish;
return $self->{'gff_source_db_id'};
}
=head2 gff_source_dbxref_id
Gets dbxref_id for features that have a gff source associated
=cut
( run in 4.493 seconds using v1.01-cache-2.11-cpan-98e64b0badf )