Skip to content
Snippets Groups Projects
Commit 43fd0e0a authored by Andy Yates's avatar Andy Yates
Browse files

Very basic gff serialiser test

parent 1f81b7f3
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,7 @@ use Bio::EnsEMBL::Utils::Exception;
use Bio::EnsEMBL::Utils::BiotypeMapper;
use URI::Escape;
use Bio::EnsEMBL::Utils::IO::FeatureSerializer;
use Bio::EnsEMBL::Utils::Scalar qw/check_ref/;
use base qw(Bio::EnsEMBL::Utils::IO::FeatureSerializer);
......@@ -63,7 +64,7 @@ sub new {
filehandle => shift,
};
bless $self, $class;
if ( ref($self->{'ontology_adaptor'}) ne "Bio::EnsEMBL::DBSQL::OntologyTermAdaptor" ) {
if ( ! check_ref($self->{'ontology_adaptor'}, "Bio::EnsEMBL::DBSQL::OntologyTermAdaptor" )) {
throw("GFF format requires an instance of Bio::EnsEMBL::DBSQL::OntologyTermAdaptor to function. See also Bio::EnsEMBL::Utils::BiotypeMapper");
}
$self->{'mapper'} = new Bio::EnsEMBL::Utils::BiotypeMapper($self->{'ontology_adaptor'});
......
package Test::SO::Term;
sub new {
my ($class) = @_;
return bless({}, ref($class) || $class);
}
sub name {
my ($self) = @_;
return 'feature';
}
package Test::SO;
use base qw/Bio::EnsEMBL::DBSQL::OntologyTermAdaptor/;
sub new {
my ($class) = @_;
return bless({}, ref($class) || $class);
}
sub fetch_by_accession {
my ($self) = @_;
return Test::SO::Term->new();
}
package main;
use strict;
use warnings;
use Test::More;
use Bio::EnsEMBL::Test::MultiTestDB;
use Bio::EnsEMBL::Utils::IO::GFFSerializer;
use IO::String;
my $db = Bio::EnsEMBL::Test::MultiTestDB->new();
my $dba = $db->get_DBAdaptor('core');
my $id = 'ENSG00000131044';
my $ga = $dba->get_GeneAdaptor();
my $gene = $ga->fetch_by_stable_id($id);
{
my $ota = Test::SO->new();
my $fh = IO::String->new();
my $ser = Bio::EnsEMBL::Utils::IO::GFFSerializer->new($ota, $fh);
$ser->print_main_header([$gene->feature_Slice()]);
$ser->print_feature($gene);
my $expected = <<'OUT';
##gff-version 3
##sequence-region 20 30274334 30300924
OUT
#Have to do this outside of the HERETO thanks to tabs
$expected .= join("\t",
qw/20 EnsEMBL feature 30274334 30300924 . + ./,
'ID=ENSG00000131044;logic_name=ensembl;external_name=C20orf125;description=DJ310O13.1.2 (NOVEL PROTEIN SIMILAR DROSOPHILA PROTEIN CG7474%2C ISOFORM 2 ) (FRAGMENT). [Source:SPTREMBL%3BAcc:Q9BR18];biotype=protein_coding'
);
$expected .= "\n";
is(${$fh->string_ref()}, $expected, 'Gene serialises to GFF3 as expected');
}
done_testing();
\ No newline at end of file
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