Boulder

 view release on metacpan or  search on metacpan

Boulder/Blast.pm  view on Meta::CPAN

     Query_end=210
     Orientation=plus
     Score=65
     Subject_start=146
     Alignment=F GK   F L K    LR++      EW     S   +     T     +...
   }
 }
 =

=cut

use strict;
use Stone;
use Boulder::Stream;
use Carp;
use vars qw($VERSION @ISA);
@ISA = 'Boulder::Stream';

*get        =  \&read_record;

$VERSION = 1.01;

sub new {
  my $self = shift;
  $self = bless {},$self unless ref $self;
  $self->_open(@_);
  return $self;
}

# parse the contents of filehandle and emit a boulderio stream to stdout
sub parse {
  my $self = shift;
  $self = $self->new(shift) unless ref($self);
  $self->read_record();
}

sub _fh {
  my $self = shift;
  $self->{'fh'} = $_[0] if defined($_[0]);
  return $self->{'fh'};
}

sub read_record {
  my $self = shift;
  return if $self->done;
  my $fh = $self->_fh;
  my $stone = new Stone;
  local $/ = "\n"; # normalize input stream

  return unless defined(my $line = <$fh>);
  croak "Doesn't look like a BLAST stream to me - top line = '$_'" unless $line=~/BLAST/;
  return unless my ($program,$version,$date) = $line=~ /^(\S+) (\S+) \[([^\]]+)\]/;

  $stone->insert ( Blast_version      => $version,
		   Blast_program      => lc $program,
		   Blast_program_date => $date );

  # the date isn't part of the file, so we use the creation date of the file
  # for this purpose.  If not available, then we are reading from a pipe
  # (maybe) and we use the current time.
  my $timestamp = -f $fh ? (stat(_))[9] : time;
  $stone->insert(Blast_run_date => scalar localtime($timestamp));

  if ($version =~ /WashU/) {
    require Boulder::Blast::WU;
    bless $self,'Boulder::Blast::WU';
  } else {
    require Boulder::Blast::NCBI;
    bless $self,'Boulder::Blast::NCBI';
  }

  $self->_read_record($fh,$stone);
}

sub _read_record {
  croak "unimplemented";
}

sub _open {
  my $self = shift;
  if (@_ > 1) {
    push @ARGV,@_;
    $self->_fh(\*ARGV);
    return;
  }
  my $fh = shift;
  unless (defined $fh) {
    # if $fh is null, then set it to ARGV
    $fh ||= \*ARGV;
  } elsif (!UNIVERSAL::isa($fh,'GLOB') && !UNIVERSAL::isa($fh,'FileHandle')) {
    # if $fh isn't a filehandle, then treat it as a filename to open
    croak "File does not exist" unless -e (my $name = $fh);
    $fh = Symbol::gensym;
    open($fh,$name) or croak "Can't open $name: $!\n";
  }
  $self->_fh($fh);
}

1;



( run in 0.995 second using v1.01-cache-2.11-cpan-5a3173703d6 )