Bio::EnsEMBL::Pipeline::SeqFetcher
Pfetch
Toolbar
Summary
Bio::EnsEMBL::Pipeline::SeqFetcher::Pfetch
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
my $obj = Bio::EnsEMBL::Pipeline::SeqFetcher::Pfetch->new(
-executable => $exe
);
my $seq = $obj->get_Seq_by_acc($acc);
Description
Object to retrieve sequences as Bio::Seq, using pfetch.
Methods
Methods description
Title : batch_fetch Usage : $self->batch_retrieval(@accession_list); Function: Retrieves multiple sequences via pfetch Returns : reference to a list of Bio::Seq objects Args : array of accession strings |
Title : executable Usage : $self->executable('/path/to/executable'); Function: Get/set for the path to the executable being used by the module. If not set, the executable is looked for in $PATH. Returns : string Args : string |
Title : get_Seq_by_acc Usage : $self->get_eq_by_acc($accession); Function: Does the sequence retrieval via pfetch Returns : Bio::Seq Args : |
Title : options Usage : $self->options('tc'); Function: Get/set for options to pfetch Returns : string Args : string |
Methods code
sub batch_fetch
{ my $self = shift @_;
my @sequence_list;
unless (scalar @_) {
$self->throw("No accession input");
}
my $accession_concatenation;
my @accession_list;
while (my $acc = shift @_) {
push (@accession_list, $acc);
$accession_concatenation .= $acc . ' ';
}
my $pfetch = $self->executable;
my $options = $self->options;
if (defined($options)) { $options = '-' . $options unless $options =~ /^-/; }
my $command = "$pfetch -q ";
if (defined $options){
$command .= "$options ";
}
$command .= $accession_concatenation;
open(IN,"$command |") or $self->throw("Error opening pipe to pfetch : $pfetch");
my $seq_placemarker = -1;
SEQ:
while (my $seqstr = <IN>) {
$seq_placemarker++;
chomp($seqstr);
my $seq;
unless (defined $seqstr && $seqstr eq 'no match') {
eval{
if(defined $seqstr && $seqstr ne "no match") {
$seq = new Bio::Seq('-seq' => $seqstr,
'-accession_number' => $accession_list[$seq_placemarker],
'-display_id' => $accession_list[$seq_placemarker]);
}
};
if($@){
print STDERR "$@\n";
}
}
unless (defined $seq){
$self->warn("PFetch Error : Could not pfetch sequence for " .
$accession_list[$seq_placemarker] . "\n");
next SEQ;
}
push (@sequence_list, $seq);
}
close IN or $self->throw("Error running pfetch : $pfetch");
return\@ sequence_list;
}
1; } |
sub executable
{ my ($self, $exe) = @_;
if ($exe)
{
$self->{'_exe'} = $exe;
}
return $self->{'_exe'}; } |
sub get_Seq_by_acc
{ my ($self, $acc) = @_;
if (!defined($acc)) {
$self->throw("No accession input");
}
if ( defined ( $self->{_seq_cache}{$acc})) {
return $self->{_seq_cache}{$acc};
}
my $seqstr;
my $seq;
my $pfetch = $self->executable;
my $options = $self->options;
if (defined($options)) { $options = '-' . $options unless $options =~ /^-/; }
my $command = "$pfetch -q ";
if (defined $options){
$command .= "$options ";
}
$command .= $acc;
open(IN,"$command |") or $self->throw("Error opening pipe to pfetch for accession [$acc]: $pfetch");
$seqstr = <IN>;
close IN or $self->throw("Error running pfetch for accession [$acc]: $pfetch");
chomp($seqstr);
eval{
if(defined $seqstr && $seqstr ne "no match") {
$seq = new Bio::Seq('-seq' => $seqstr,
'-accession_number' => $acc,
'-display_id' => $acc);
}
};
if($@){
print STDERR "$@\n";
}
$self->throw("Could not pfetch sequence for [$acc]\n") unless defined $seq;
$self->{_seq_cache}{$acc}=$seq;
return $seq; } |
sub new
{ my ($class, @args) = @_;
my $self = bless {}, $class;
my ($exe, $options) = rearrange(['EXECUTABLE', 'OPTIONS'], @args);
if (!defined $exe) {
$exe = 'pfetch';
}
$self->executable($exe);
if (defined $options) {
$self->options($options);
}
$self->{_seq_cache}={};
return $self;
} |
sub options
{
my ($self, $options) = @_;
if ($options)
{
$self->{'_options'} = $options;
}
return $self->{'_options'}; } |
General documentation
Describe contact details here
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
Method Bio::EnsEMBL::Root::_rearrange is deprecated.
use Bio::EnsEMBL::Utils::Argument qw(rearrange);
rearrange(order, list); #instead