Skip to content
Snippets Groups Projects
Unverified Commit 27b82aca authored by Matthew Laird's avatar Matthew Laird Committed by GitHub
Browse files

Merge pull request #248 from Ensembl/feature/biotype_methods

ENSCORESW-2695: expand methods for REST support
parents 7bb26054 e69b49d8
No related branches found
No related tags found
2 merge requests!273Master,!273Master
......@@ -199,6 +199,38 @@ sub fetch_all_by_object_type {
return \@biotypes;
}
=head2 fetch_all_by_name
Arg [1] : String $name
The name of the biotype to retrieve
Arg [2] : (optional) String $object_type
The object_type of the biotypes to retrieve (gene or transcript).
Example : $biotypes = $biotype_adaptor->fetch_all_by_name('lincRNA');
Description: Retrieves an array reference of biotype objects from the database.
Returntype : arrayref of Bio::EnsEMBL::Biotype objects or empty arrayref
Warning : If empty arrayref is to be returned
Exceptions : none
=cut
sub fetch_all_by_name{
my ($self, $name, $object_type) = @_;
my $constraint = "b.name = ?";
$self->bind_param_generic_fetch($name, SQL_VARCHAR);
if (defined $object_type) {
$constraint .= "AND b.object_type = ?";
$self->bind_param_generic_fetch($object_type, SQL_VARCHAR);
}
my @biotypes = @{$self->generic_fetch($constraint)};
if ( !@biotypes ) {
warning("No objects retrieved. Check if name '$name' is correct.")
}
return \@biotypes;
}
=head2 fetch_all_by_group_object_db_type
Arg [1] : String $biotype_group
......@@ -222,10 +254,13 @@ sub fetch_all_by_group_object_db_type {
$db_type //= 'core';
$db_type = '%' . $db_type . '%';
my $constraint = "b.biotype_group = ? AND b.object_type = ? AND b.db_type LIKE ? ";
my $constraint = "b.biotype_group = ? AND b.db_type LIKE ? ";
$self->bind_param_generic_fetch($biotype_group, SQL_VARCHAR);
$self->bind_param_generic_fetch($object_type, SQL_VARCHAR);
$self->bind_param_generic_fetch($db_type, SQL_VARCHAR);
if (defined $object_type) {
$constraint .= " AND b.object_type = ?";
$self->bind_param_generic_fetch($object_type, SQL_VARCHAR);
}
my @biotypes = @{$self->generic_fetch($constraint)};
if ( !@biotypes ) {
......@@ -235,4 +270,4 @@ sub fetch_all_by_group_object_db_type {
return \@biotypes;
}
1;
\ No newline at end of file
1;
......@@ -112,4 +112,24 @@ like( $warning2,
"Got a warning from fetch_all_by_group_object_db_type",
) or diag 'Got warning: ', explain($warning2);
# Test fetching by biotype name
debug("fetch biotypes by name");
my $biotypes3 = $biotype_adaptor->fetch_all_by_name('protein_coding');
is(ref $biotypes3, 'ARRAY', 'Got an array');
cmp_ok(scalar(@$biotypes3), ">", "0", 'Array is not empty');
is_deeply($biotypes3, [$biotype1, $biotype2], 'with the correct objects');
my $warning3 = warning {
$biotypes3 = $biotype_adaptor->fetch_all_by_name('none') };
like( $warning3,
qr/No objects retrieved. Check if name 'none' is correct./,
"Got a warning from fetch_all_by_name",
) or diag 'Got warning: ', explain($warning3);
is(ref $biotypes3, 'ARRAY', 'Got an array');
is(scalar @{$biotypes3}, '0', 'of size 0');
is_deeply($biotypes3, [], 'totally empty');
my $biotypes4 = $biotype_adaptor->fetch_all_by_name('protein_coding', 'gene');
my $biotypes5 = $biotype_adaptor->fetch_by_name_object_type('protein_coding', 'gene');
is_deeply($biotypes4->[0], $biotypes5, "fetch_all_by_name with an object type is identical to fetch_by_name_object_type");
done_testing();
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment