Bio-ViennaNGS

 view release on metacpan or  search on metacpan

lib/Bio/ViennaNGS/Fasta.pm  view on Meta::CPAN

# -*-CPerl-*-
# Last changed Time-stamp: <2017-06-10 19:01:14 michl>

=head1 NAME

Bio::ViennaNGS::Fasta - Moose wrapper for Bio::DB::Fasta

=head1 SYNOPSIS

  use Bio::ViennaNGS::Fasta;

  my $f = Bio::ViennaNGS::Fasta->new(fasta => "data/foo.fa", );

  # get all FASTA IDs
  my @ids = $f->fastaids;

  # get a reference to a hash of Bio::PrimarySeq::Fasta objects whose
  # keys are the Fasta IDs seen in the input file
  my $ps = $f->primaryseqH;

  # get the strand-specific genomic sequence for a certain Fasta ID
  my $id = "chr1";
  my $start = 287;
  my $end = 1289;
  my $strand = "+";
  my $seq = $f->stranded_subsequence($id,$start,$end,$strand);

=head1 DESCRIPTION

L<Bio::ViennaNGS::Fasta> provides a L<Moose> interface to
L<Bio::DB::Fasta>, spiced up with a few convenience methods for easy
sequence data retrieval.

=head2 ATTRIBUTES

=over 3

=item fasta (required)

Upcon object construction, this attribute expects an input fasta file,
which is transparently coerced into a L<Bio::DB::Fasta> object and
hitherto available via the C<fasta> attribute.

=item fastaids (auto-computed)

Arrary reference to the Fasta IDs found in the input file

=item primaryseqH (auto-computed)

Hash reference to L<Bio::PrimarySeq::Fasta> objects whose keys are the
Fasta IDs found in the input file

=back

=cut

package Bio::ViennaNGS::Fasta;

use Bio::ViennaNGS;
use Moose;
use Bio::ViennaNGS::Subtypes;
use Bio::Perl;
use Carp;
use Data::Dumper;
use namespace::autoclean;
use version; our $VERSION = version->declare("$Bio::ViennaNGS::VERSION");

has 'fasta' => (
		is => 'ro',
		isa => 'Bio::ViennaNGS::MyFasta',
		required => 1,
		predicate => 'has_fasta',
		coerce => 1,
	    );


has 'fastaids' => (
		   is => 'rw',
		   isa => 'ArrayRef',
		   predicate => 'has_ids',
		   init_arg => undef,
		  );

has 'primaryseqH' => (
		     is => 'rw',
		     isa => 'HashRef',
		     predicate => 'has_primaryseq',
		     init_arg => undef,
		    );


sub BUILD {
  my $self = shift;
  my $this_function = (caller(0))[3];
  $self->fastaids([$self->fasta->ids]);
  confess "ERROR [$this_function] \$self->fastsids not available"
    unless ($self->has_ids);
  my %ps = ();
  foreach my $id (@{$self->fastaids}){
    $ps{$id} = $self->fasta->get_Seq_by_id($id);
  }



( run in 1.056 second using v1.01-cache-2.11-cpan-5511b514fd6 )