Bio::EnsEMBL::Pipeline::SeqFetcher FetchFromBlastDB
Included librariesPackage variablesGeneral documentationMethods
Toolbar
WebCvsRaw content
Package variables
No package variables defined.
Included modules
Bio::EnsEMBL::Root
Bio::Seq
Inherit
Bio::EnsEMBL::Root
Synopsis
No synopsis!
Description
No description!
Methods
_fetch
No description
Code
batch_fetch
No description
Code
db
No description
Code
fetch
No description
Code
get_Seq_by_acc
No description
Code
new
No description
Code
Methods description
None available.
Methods code
_fetchdescriptionprevnextTop
sub _fetch {
  my ($self, $id) = @_;

  my $command;

  if (ref $id eq 'ARRAY') {
    for (my $i = 0; $i < scalar @$id; $i++){
      $id->[$i] =~ s/(\S+).*/$1/;
    }

    $command = $self->db->seqfetch_command . " @$id";
  } else {
    $id =~ s/(\S+).*/$1/;
    $command = $self->db->seqfetch_command . " " . $id;
  }

  open(CMD, "$command |") or die "Can't execute fetch command";

  my %seqs;
  my %descs;
  my $id_line;
  my $desc;

  while (<CMD>){

    if (/^>/){
      $id_line = $_;
      $id_line =~ s/^>//;

      if ($self->db->index_type =~ /wu/){
	$id_line =~ s/([\w\_\.]+)\s*(.*)\n/$1/;
	$desc = $2;
      }
      if ($self->db->index_type eq 'ncbi'){
	$id_line =~ s/[^\|]+\|([\w\_\.]+)\s*(.*)\n/$1/;
	$desc = $2;
      }

      $desc =~ s/\t/ /g;

      $descs{$id_line} = $desc;

      next
    }

    $seqs{$id_line} .= $_;
  }

  close CMD;

  my @bioseqs;

  foreach my $seq_id (keys %seqs) {

    $seqs{$seq_id} =~ s/\n//g;

    my $bioseq = Bio::Seq->new(-display_id => $seq_id,
			       -seq        => $seqs{$seq_id},
			       -desc       => $descs{$seq_id}
			      );

    push (@bioseqs, $bioseq)
  }

  return\@ bioseqs;
}

### Some aliae
}
batch_fetchdescriptionprevnextTop
sub batch_fetch {
  my ($self, $ids) = @_;

  return $self->_fetch($ids);
}
dbdescriptionprevnextTop
sub db {
  my $self = shift;

  if (@_) {
    
    my $value = shift;
    
    unless ($value->isa("Bio::EnsEMBL::Pipeline::Runnable::BlastDB")){
      $self->throw("Blast database object is not a "
		   ."Bio::EnsEMBL::Pipeline::Runnable::BlastDB.\n")
    }
    
    $self->{_db} = $value;
  }
  
  return $self->{_db}
}
fetchdescriptionprevnextTop
sub fetch {
  my ($self, $id) = @_;

  my $seqs = $self->_fetch($id);

  return shift @$seqs
}
get_Seq_by_accdescriptionprevnextTop
sub get_Seq_by_acc {
  my ($self, $id) = @_;

  return $self->fetch($id)
}
newdescriptionprevnextTop
sub new {
  my ($class, @args) = @_;

  my $self = bless {},$class;
  
  my ($db) = $self->_rearrange([qw(DB)],@args);

  $self->db($db) if $db;

  return $self
}
General documentation
No general documentation available.