Skip to content

Commit

Permalink
FeaturePair gets its own test file
Browse files Browse the repository at this point in the history
  • Loading branch information
fangly committed Mar 5, 2012
1 parent b2140a4 commit e192e24
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 60 deletions.
74 changes: 38 additions & 36 deletions Bio/SeqFeature/FeaturePair.pm
Expand Up @@ -17,9 +17,10 @@ Bio::SeqFeature::FeaturePair - hold pair feature information e.g. blast hits
=head1 SYNOPSIS
my $feat = Bio::SeqFeature::FeaturePair->new(-feature1 => $f1,
-feature2 => $f2,
);
my $feat = Bio::SeqFeature::FeaturePair->new(
-feature1 => $f1,
-feature2 => $f2,
);
# Bio::SeqFeatureI methods can be used
Expand All @@ -41,9 +42,10 @@ HS120G22. The genomic sequence coordinates are used to create one
sequence feature $f1 and the protein coordinates are used to create
feature $f2. A FeaturePair object can then be made
my $fp = Bio::SeqFeature::FeaturePair->new(-feature1 => $f1, # genomic
-feature2 => $f2, # protein
);
my $fp = Bio::SeqFeature::FeaturePair->new(
-feature1 => $f1, # genomic
-feature2 => $f2, # protein
);
This object can be used as a standard Bio::SeqFeatureI in which case
Expand Down Expand Up @@ -139,17 +141,17 @@ sub new {
#
my $self = $class->SUPER::new();
my ($feature1,$feature2,$featfact) =
$self->_rearrange([qw(FEATURE1
FEATURE2
FEATURE_FACTORY
)],@args);
$self->_rearrange([qw( FEATURE1
FEATURE2
FEATURE_FACTORY )],@args);

$self->_register_for_cleanup(\&cleanup_fp);
# initialize the feature object factory if not provided
if(! $featfact) {
$featfact = Bio::Factory::ObjectFactory->new(
-type => "Bio::SeqFeature::Generic",
-interface => "Bio::SeqFeatureI");
$featfact = Bio::Factory::ObjectFactory->new(
-type => "Bio::SeqFeature::Generic",
-interface => "Bio::SeqFeatureI"
);
}
$self->feature_factory($featfact);
# Store the features in the object
Expand Down Expand Up @@ -179,12 +181,12 @@ sub new {
sub feature1 {
my ($self,$arg) = @_;
if ( defined($arg) || !defined $self->{'feature1'} ) {
$self->throw("internal error: feature factory not set!")
unless $self->feature_factory;
$arg = $self->feature_factory->create_object() unless( defined $arg);
$self->throw("Argument [$arg] must be a Bio::SeqFeatureI")
unless (ref($arg) && $arg->isa("Bio::SeqFeatureI"));
$self->{'feature1'} = $arg;
$self->throw("internal error: feature factory not set!")
unless $self->feature_factory;
$arg = $self->feature_factory->create_object() unless( defined $arg);
$self->throw("Argument [$arg] must be a Bio::SeqFeatureI")
unless (ref($arg) && $arg->isa("Bio::SeqFeatureI"));
$self->{'feature1'} = $arg;
}
return $self->{'feature1'};
}
Expand All @@ -205,12 +207,12 @@ sub feature2 {
my ($self,$arg) = @_;

if ( defined($arg) || ! defined $self->{'feature2'}) {
$self->throw("internal error: feature factory not set!")
unless $self->feature_factory;
$arg = $self->feature_factory->create_object() unless( defined $arg);
$self->throw("Argument [$arg] must be a Bio::SeqFeatureI")
unless (ref($arg) && $arg->isa("Bio::SeqFeatureI"));
$self->{'feature2'} = $arg;
$self->throw("internal error: feature factory not set!")
unless $self->feature_factory;
$arg = $self->feature_factory->create_object() unless( defined $arg);
$self->throw("Argument [$arg] must be a Bio::SeqFeatureI")
unless (ref($arg) && $arg->isa("Bio::SeqFeatureI"));
$self->{'feature2'} = $arg;
}
return $self->{'feature2'};
}
Expand Down Expand Up @@ -242,7 +244,7 @@ sub start {
=cut

sub end{
sub end {
return shift->feature1->end(@_);
}

Expand All @@ -258,7 +260,7 @@ sub end{
=cut

sub strand{
sub strand {
return shift->feature1->strand(@_);
}

Expand Down Expand Up @@ -320,7 +322,7 @@ sub frame {
=cut

sub primary_tag{
sub primary_tag {
return shift->feature1->primary_tag(@_);
}

Expand All @@ -337,7 +339,7 @@ sub primary_tag{
=cut

sub source_tag{
sub source_tag {
return shift->feature1->source_tag(@_);
}

Expand All @@ -359,7 +361,7 @@ sub source_tag{
=cut

sub seq_id{
sub seq_id {
return shift->feature1->seq_id(@_);
}

Expand Down Expand Up @@ -407,7 +409,7 @@ sub hstart {
=cut

sub hend{
sub hend {
return shift->feature2->end(@_);
}

Expand All @@ -424,7 +426,7 @@ sub hend{
=cut

sub hstrand{
sub hstrand {
return shift->feature2->strand(@_);
}

Expand Down Expand Up @@ -471,7 +473,7 @@ sub hframe {
=cut

sub hprimary_tag{
sub hprimary_tag {
return shift->feature2->primary_tag(@_);
}

Expand All @@ -488,7 +490,7 @@ sub hprimary_tag{
=cut

sub hsource_tag{
sub hsource_tag {
return shift->feature2->source_tag(@_);
}

Expand All @@ -510,7 +512,7 @@ sub invert {

$self->feature1($self->feature2);
$self->feature2($tmp);
return;
return 1;
}

=head2 feature_factory
Expand All @@ -535,7 +537,7 @@ sub invert {
=cut

sub feature_factory{
sub feature_factory {
my $self = shift;

return $self->{'feature_factory'} = shift if @_;
Expand Down
62 changes: 62 additions & 0 deletions t/SeqFeature/FeaturePair.t
@@ -0,0 +1,62 @@
# -*-Perl-*- Test Harness script for Bioperl
# $Id$

use strict;

BEGIN {
use lib '.';
use Bio::Root::Test;

test_begin(-tests => 19);

use_ok('Bio::SeqFeature::Generic');
use_ok('Bio::SeqFeature::FeaturePair');
}


my ($feat, $feat2, $pair);

ok $pair = Bio::SeqFeature::FeaturePair->new();

ok $feat = Bio::SeqFeature::Generic->new(
-start => 40,
-end => 80,
-strand => 1,
-primary => 'exon',
-source => 'internal',
-display_name => 'my exon feature',
-tag => {
silly => 20,
new => 1
}
);

ok $feat2 = Bio::SeqFeature::Generic->new(
-start => 400,
-end => 440,
-strand => 1,
-primary => 'other',
-source => 'program_a',
-phase => 1,
-tag => {
silly => 20,
new => 1
}
);

ok $pair->feature1($feat);
ok $pair->feature2($feat2);

is $pair->feature1, $feat, 'feature1 of pair stored';
is $pair->feature2, $feat2, 'feature2 of pair stored';
is $pair->start, 40, 'feature start';
is $pair->end, 80, 'feature end';
is $pair->primary_tag, 'exon', 'primary tag';
is $pair->source_tag, 'internal', 'source tag';
is $pair->hstart, 400, 'hstart';
is $pair->hend, 440, 'hend';
is $pair->hprimary_tag, 'other', 'hprimary tag';
is $pair->hsource_tag, 'program_a', 'hsource tag';

ok $pair->invert;
is $pair->end, 440, 'inverted end';
27 changes: 3 additions & 24 deletions t/SeqFeature/SeqFeature.t
Expand Up @@ -7,12 +7,11 @@ BEGIN {
use lib '.';
use Bio::Root::Test;

test_begin(-tests => 245);
test_begin(-tests => 232);

use_ok('Bio::Seq');
use_ok('Bio::SeqIO');
use_ok('Bio::SeqFeature::Generic');
use_ok('Bio::SeqFeature::FeaturePair');
use_ok('Bio::SeqFeature::Gene::Transcript');
use_ok('Bio::SeqFeature::Gene::UTR');
use_ok('Bio::SeqFeature::Gene::Exon');
Expand All @@ -22,7 +21,7 @@ BEGIN {
}

# predeclare variables for strict
my ($feat, $str, $feat2, $pair, @sft);
my ($feat, $str, $feat2, $pair, @sft);

my $DEBUG = test_debug();

Expand Down Expand Up @@ -57,10 +56,7 @@ is $feat->phase, 1, 'phase is persistent';

ok $feat->gff_string();

$pair = Bio::SeqFeature::FeaturePair->new();
ok defined $pair;

$feat2 = Bio::SeqFeature::Generic->new( -start => 400,
ok $feat2 = Bio::SeqFeature::Generic->new(-start => 400,
-end => 440,
-strand => 1,
-primary => 'other',
Expand All @@ -73,23 +69,6 @@ $feat2 = Bio::SeqFeature::Generic->new( -start => 400,
);
is $feat2->phase, 1, 'set phase from constructor';

ok defined $feat2;
$pair->feature1($feat);
$pair->feature2($feat2);

is $pair->feature1, $feat, 'feature1 of pair stored';
is $pair->feature2, $feat2, 'feature2 of pair stored';
is $pair->start, 40, 'feature start';
is $pair->end, 80, 'feature end';
is $pair->primary_tag, 'exon', 'primary tag';
is $pair->source_tag, 'internal', 'source tag';
is $pair->hstart, 400, 'hstart';
is $pair->hend, 440, 'hend';
is $pair->hprimary_tag, 'other', 'hprimary tag';
is $pair->hsource_tag, 'program_a', 'hsource tag';

$pair->invert;
is $pair->end, 440, 'inverted end';

# Test attaching a SeqFeature::Generic to a Bio::Seq
{
Expand Down

0 comments on commit e192e24

Please sign in to comment.