Skip to content

Commit

Permalink
Moving to Bio::Tools::Run::Alignment Namespace
Browse files Browse the repository at this point in the history
svn path=/bioperl-run/trunk/; revision=13434
  • Loading branch information
shawnh committed May 16, 2003
1 parent 7e50f2a commit 495b639
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 40 deletions.
53 changes: 24 additions & 29 deletions Bio/Tools/Run/Blat.pm → Bio/Tools/Run/Alignment/Blat.pm
Expand Up @@ -15,7 +15,7 @@ Bio::Tools::Run::Blat
# Pass the factory a Bio::Seq object
# @feats is an array of Bio::SeqFeature::Generic objects
my @feats = $factory->align($seq,$DB);
my @feats = $factory->run($seq,$DB);
=head1 DESCRIPTION
Expand Down Expand Up @@ -52,21 +52,23 @@ Bio::Tools::Run::Blat
=cut

package Bio::Tools::Run::Blat;
package Bio::Tools::Run::Alignment::Blat;

use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR
$PROGRAMNAME @BLAT_PARAMS %OK_FIELD);
use strict;
use Bio::SeqIO;
use Bio::Root::Root;
use Bio::Factory::ApplicationFactoryI;
use Bio::Tools::Blat;
use Bio::SearchIO;
use Bio::Tools::Run::WrapperBase;

@ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);

BEGIN {
@BLAT_PARAMS=qw(DB PROGRAM OPTIONS VERBOSE);
@BLAT_PARAMS=qw(DB PROGRAM OOC DB_TYPE QUERY_TYPE TILESIZE ONEOFF MINMATCH
MINSCORE MINIDENTITY MAXGAP MAKEOOC REPMATCH MASK QMASK
MINREPDIV TRIMT NOTRIMA VERBOSE);
foreach my $attr ( @BLAT_PARAMS)
{ $OK_FIELD{$attr}++; }
}
Expand Down Expand Up @@ -136,35 +138,36 @@ sub new {
return $self;
}

=head2 align
=head2 run
Title : align()
Usage : $obj->align($query)
Title : run()
Usage : $obj->run($query)
Function: Runs Blat and creates an array of featrues
Returns : An array of Bio::SeqFeature::Generic objects
Args : A Bio::PrimarySeqI
=cut

sub align {
sub run {
my ($self,$query) = @_;
my @feats;

if (ref($query) ) { # it is an object
if (ref($query) =~ /GLOB/) {
$self->throw("cannot use filehandle");
}
my $infile1 = $self->_writeSeqFile($query);
$self->_input($infile1);
@feats = $self->_run();
unlink $infile1;
if (ref($query) =~ /GLOB/) {
$self->throw("cannot use filehandle");
}
my $infile1 = $self->_writeSeqFile($query);
$self->_input($infile1);
return $self->_run();
}
else {
$self->_input($query);
@feats = $self->_run();
return $self->_run();
}
}

return @feats;
sub align {
return shift->run(@_);
}

=head2 _input
Expand Down Expand Up @@ -218,7 +221,7 @@ sub _run {
my ($tfh,$outfile) = $self->io->tempfile(-dir=>$self->tempdir);
my $str= $self->executable;

$str.=' '.$self->DB .' '.$self->_input.' '.$outfile;
$str.=' -out=blast '.$self->DB .' '.$self->_input.' '.$outfile;


my $status = system($str);
Expand All @@ -232,19 +235,11 @@ sub _run {
else {
$filehandle = $outfile;
}
my $blat_parser = Bio::Tools::Blat->new(-fh=>$filehandle);
my @blat_feat;

while(my $blat_feat = $blat_parser->next_result){
push @blat_feat, $blat_feat;
}

my $blat_obj= Bio::SearchIO->new(-format=>'blast',-fh=>$filehandle);


$self->cleanup();
close($tfh);
undef $tfh;
unlink $outfile;
return @blat_feat;
return $blat_obj;
}


Expand Down
36 changes: 25 additions & 11 deletions t/Blat.t
Expand Up @@ -10,7 +10,7 @@ BEGIN {
}
use Test;
use vars qw($NTESTS);
$NTESTS = 7;
$NTESTS = 12;
plan tests => $NTESTS;
}

Expand All @@ -20,7 +20,7 @@ END {
}
}
ok(1);
use Bio::Tools::Run::Blat;
use Bio::Tools::Run::Alignment::Blat;
use Bio::Root::IO;
use Bio::SeqIO;
use Bio::Seq;
Expand All @@ -29,8 +29,8 @@ my $db = Bio::Root::IO->catfile("t","data","blat_dna.fa");

my $query = Bio::Root::IO->catfile("t","data","blat_dna.fa");

my $factory = Bio::Tools::Run::Blat->new("DB"=>$db);
ok $factory->isa('Bio::Tools::Run::Blat');
my $factory = Bio::Tools::Run::Alignment::Blat->new("DB"=>$db);
ok $factory->isa('Bio::Tools::Run::Alignment::Blat');

my $blat_present = $factory->executable();

Expand All @@ -39,15 +39,29 @@ unless ($blat_present) {
exit 0;
}

my @feat = $factory->align($query);
my $searchio = $factory->align($query);
my $result = $searchio->next_result;
my $hit = $result->next_hit;
my $hsp = $hit->next_hsp;
ok $hsp->isa("Bio::Search::HSP::HSPI");
ok ($hsp->feature1->start,1);
ok ($hsp->feature1->end,1775);
ok ($hsp->feature2->start,1);
ok ($hsp->feature2->end,1775);
my $sio = Bio::SeqIO->new(-file=>$query,-format=>'fasta');

ok $feat[0]->isa('Bio::SeqFeatureI');
my @sub_feat = $feat[0]->get_SeqFeatures;
my $seq = $sio->next_seq ;

$searchio = $factory->align($seq);
$result = $searchio->next_result;
$hit = $result->next_hit;
$hsp = $hit->next_hsp;
ok $hsp->isa("Bio::Search::HSP::HSPI");
ok ($hsp->feature1->start,1);
ok ($hsp->feature1->end,1775);
ok ($hsp->feature2->start,1);
ok ($hsp->feature2->end,1775);

ok ($sub_feat[0]->feature1->start,1);
ok ($sub_feat[0]->feature1->end,1775);
ok ($sub_feat[0]->feature2->start,1);
ok ($sub_feat[0]->feature2->end,1775);

1;

0 comments on commit 495b639

Please sign in to comment.