Skip to content

Commit

Permalink
More work on AmpliconSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
fangly committed Mar 3, 2012
1 parent b57b168 commit 6da2c6c
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 29 deletions.
114 changes: 86 additions & 28 deletions Bio/Tools/AmpliconSearch.pm
Expand Up @@ -9,7 +9,6 @@ package Bio::Tools::AmpliconSearch;

use strict;
use warnings;
use Bio::SeqIO;
use Bio::Tools::IUPAC;

use base qw(Bio::Root::Root);
Expand Down Expand Up @@ -82,20 +81,24 @@ methods. Internal methods are usually preceded with a _
=head2 new
Title : new
Usage :
Usage : my $search = Bio::Tools::AmpliconSearch->new( );
Function :
Args :
Args : -template
-forward_primer
-reverse_primer
-primer_file replaces -forward_primer and -reverse_primer (optional)
-want_a type of object to have next_amplicon() return: PrimarySeq, LocatableSeq, Amplicon
-attach_primers when returning amplicon objects as Amplicons, whether or not to attach primers to it
Returns :
=cut


sub new {
my ($class, @args) = @_;
my $self = $class->SUPER::new(@args);
my ($template, $primer_file, $forward_primer, $reverse_primer) =
$self->_rearrange([qw(TEMPLATE PRIMER_FILE FORWARD_PRIMER REVERSE_PRIMER)],
@args);
my ($template, $primer_file, $forward_primer, $reverse_primer, $want_a,
$attach_primers) = $self->_rearrange([qw(TEMPLATE PRIMER_FILE
FORWARD_PRIMER REVERSE_PRIMER WANT_A ATTACH_PRIMERS)], @args);

if (defined $primer_file) {
$self->_set_primers($primer_file);
Expand All @@ -105,25 +108,13 @@ sub new {
}

$self->_set_template($template) if defined $template;
$self->_set_want_a($want_a) if defined $want_a;
$self->_set_attach_primers($attach_primers) if defined $attach_primers;

return $self;
}


sub _initialize {
my ($self) = @_;
# Convert forward primer to regexp
my $re = Bio::Tools::IUPAC->new( -seq => $self->get_forward_primer() )->regexp;
$self->_set_forward_regexp( $re );
my $rev_primer = $self->get_reverse_primer;
if (defined $rev_primer) {
$rev_primer = $rev_primer->revcom;
$re = Bio::Tools::IUPAC->new( -seq => $rev_primer )->regexp;
$self->_set_reverse_regexp( $re );
}
}


sub get_template {
my ($self) = @_;
return $self->{'template'};
Expand Down Expand Up @@ -151,6 +142,7 @@ sub _set_primers {
}

# Mandatory first primer
require Bio::SeqIO;
my $in = Bio::SeqIO->newFh( -file => $primer_file );
my $primer = <$in>;
if (not defined $primer) {
Expand Down Expand Up @@ -188,6 +180,7 @@ sub _set_forward_primer {
# Not a sequence or a primer object
$self->throw("Expected a sequence or primer object as input but got a ".ref($val)."\n");
}
$self->_set_forward_regexp( Bio::Tools::IUPAC->new( -seq => $val )->regexp );
return $self->get_forward_primer;
}

Expand All @@ -205,6 +198,7 @@ sub _set_reverse_primer {
# Not a sequence or a primer object
$self->throw("Expected a sequence or primer object as input but got a ".ref($val)."\n");
}
$self->_set_reverse_regexp( Bio::Tools::IUPAC->new( -seq => $val->revcom )->regexp );
return $self->get_reverse_primer;
}

Expand Down Expand Up @@ -235,9 +229,45 @@ sub _set_reverse_regexp {
}


sub next_amplicon {
sub get_want_a {
my ($self) = @_;
$self->_initialize if not defined $self->get_forward_regexp();
return $self->{'want_a'} || 'Bio::PrimarySeq';
}


sub _set_want_a {
my ($self, $val) = @_;
$self->{'want_a'} = $val;
return $self->get_want_a;
}


sub get_attach_primers {
my ($self) = @_;
return $self->{'attach_primers'} || 0;
}


sub _set_attach_primers {
my ($self, $val) = @_;
$self->{'attach_primers'} = $val;
return $self->get_attach_primers;
}


=head2 next_amplicon
Title : next_amplicon
Usage : my $amplicon = $search->
Function : Get the next amplicon
Args : -want_a : Bio::PrimarySeq (default), Bio::LocatableSeq or Bio::SeqFeature::Amplicon
-attach_primers : 0 (no, default) or 1 (yes). Only possible is -want_a => 'Bio::SeqFeature::Amplicon'
Returns : an amplicon object
=cut

sub next_amplicon {
my ($self, @args) = @_;

my $amplicon;

Expand Down Expand Up @@ -278,12 +308,40 @@ sub next_amplicon {


sub _create_amplicon {
# Create an amplicon sequence and register its coordinates
my ($self, $start, $end, $orientation) = @_;
# Create an amplicon sequence and register its coordinates
my ($self, $start, $end, $orientation) = @_;

my $want_a = $self->want_a;

my $template = $self->get_template;
my $amplicon;
my $coord;
my $template = $self->get_template;
my $amplicon;
my $coord;

# if ($want_a eq 'Bio::PrimarySeq') {
# require Bio::PrimarySeq;
# $amplicon = Bio::PrimarySeq->new( -seq => XXX );
# } elsif ($want_a eq 'Bio::LocatableSeq') {
# require Bio::LocatableSeq;
# $amplicon = Bio::PrimarySeq->new( -seq => XXX );
# } elsif ($want_a eq 'Bio::SeqFeature::Amplicon') {
# require Bio::SeqFeature::Primer;
# $amplicon = Bio::PrimarySeq->new( -start => , -end => , -strand => );
# } else {
# $self->throw("'$want_a' is not a valid class to use to return amplicons.");
# }

#$amplicon = $want_a->new( -seq => );
# if (not $want_a eq 'Bio::PrimarySeq') {
# # add coordinates
# $amplicon->start( XXX );
# $amplicon->end( XXX );
# $amplicon->strand( XXX );
# if ( ($want_a eq 'Bio::SeqFeature::Amplicon') && ($self->attach_primers) ) {
# # add primers to
# $amplicon->fwd_primer( XXX );
# $amplicon->rev_primer( XXX );
# }
# }


#my $fwd_primer = Bio::SeqFeature::Primer(
Expand Down
1 change: 0 additions & 1 deletion t/Tools/AmpliconSearch.t
Expand Up @@ -63,7 +63,6 @@ is $search->get_template->seq, 'AAACTTAAAGGAATTGACGGaaaaaaaaaaaaaaaaaaaaaaaaaaaa
is $search->get_forward_primer->seq, 'AAACTYAAAKGAATTGRCGG';
is $search->get_reverse_primer->seq, 'ACGGGCGGTGTGTRC';


ok $search->next_amplicon;


0 comments on commit 6da2c6c

Please sign in to comment.