Bio-AutomatedAnnotation

 view release on metacpan or  search on metacpan

lib/Bio/AutomatedAnnotation/ParseGenesFromGFFs.pm  view on Meta::CPAN

package Bio::AutomatedAnnotation::ParseGenesFromGFFs;
$Bio::AutomatedAnnotation::ParseGenesFromGFFs::VERSION = '1.182770';
# ABSTRACT: Parse GFF files and efficiency extract the gene sequence.


use Moose;
use Bio::AutomatedAnnotation::ParseGenesFromGFF;
use Bio::SeqIO;

has 'gff_files'         => ( is => 'ro', isa => 'ArrayRef', required => 1 );
has 'search_query'      => ( is => 'ro', isa => 'Str',      required => 1 );
has 'search_qualifiers' => ( is => 'ro', isa => 'ArrayRef', required => 1 );
has 'codontable_id'     => ( is => 'ro', isa => 'Int',      default  => 11 );
has 'amino_acids'       => ( is => 'ro', isa => 'Bool',     default  => 0 );
has 'output_file'       => ( is => 'ro', isa => 'Str',      lazy     => 1, builder => '_build_output_file' );
has 'output_base'       => ( is => 'rw', isa => 'Str',      default  => 'output' );
has '_parser_objects'   => ( is => 'ro', isa => 'ArrayRef', lazy     => 1, builder => '_build__parser_objects' );

has 'files_with_hits'    => ( is => 'rw', isa => 'Int',     default  => 0 );
has 'files_without_hits' => ( is => 'rw', isa => 'Int',     default  => 0 );

sub _build_output_file {
    my ($self) = @_;
    my $file_suffix = $self->search_query;
    $file_suffix =~ s!\W!!gi;
    return join( '.', ( $self->output_base, $file_suffix, 'fa' ) );
}

sub _build__parser_objects {
    my ($self) = @_;
    my @parser_objects;
    for my $gff_file ( @{ $self->gff_files } ) {
        push(
            @parser_objects,
            Bio::AutomatedAnnotation::ParseGenesFromGFF->new(
                gff_file          => $gff_file,
                search_query      => $self->search_query,
                search_qualifiers => $self->search_qualifiers
            )
        );
    }
    return \@parser_objects;
}

sub create_fasta_file {
    my ($self) = @_;

    my $output_fh = Bio::SeqIO->new(
        -format => 'Fasta',
        -file   => ">" . $self->output_file
    );
    for my $parser_obj ( @{ $self->_parser_objects } ) {
        if ( !defined( $parser_obj->_bio_seq_objects ) || @{ $parser_obj->_bio_seq_objects } == 0 )
        {
          $self->files_without_hits($self->files_without_hits() +1 );
          next;
        }
        else
        {
          $self->files_with_hits($self->files_with_hits() +1);
        }
        
        for my $seq_obj ( @{ $parser_obj->_bio_seq_objects } ) {
            next if ( !defined($seq_obj) );

            if ( $self->amino_acids ) {
                $output_fh->write_seq( $seq_obj->translate( -codontable_id => $self->codontable_id ) );
            }
            else {
                $output_fh->write_seq($seq_obj);
            }
        }
    }
    1;
}

no Moose;



( run in 2.528 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )