GenOO

 view release on metacpan or  search on metacpan

lib/GenOO/TranscriptCollection/Factory/GTF.pm  view on Meta::CPAN

# POD documentation - main docs before the code

=head1 NAME

GenOO::TranscriptCollection::Factory::GTF - Factory to create TranscriptCollection from a GTF file

=head1 SYNOPSIS

Creates GenOO::TranscriptCollection containing transcripts from a GTF file 
Preferably use it through the generic GenOO::TranscriptCollection::Factory

    my $factory = GenOO::TranscriptCollection::Factory->new('GTF',{
        file => 'sample.gtf'
    });

=head1 DESCRIPTION

    An instance of this class is a concrete factory for the creation of a 
    L<GenOO::TranscriptCollection> containing transcripts from a GTF file. It offers the method 
    "read_collection" (as the consumed role requires) which returns the actual
    L<GenOO::TranscriptCollection> object in the form of 
    L<GenOO::RegionCollection::Type::DoubleHashArray>. The latter is the implementation
    of the L<GenOO::RegionCollection> class based on the complex data structure
    L<GenOO::Data::Structure::DoubleHashArray>.

=head1 EXAMPLES

    # Create a concrete factory
    my $factory_implementation = GenOO::TranscriptCollection::Factory->new('GTF',{
        file => 'sample.gtf'
    });
    
    # Return the actual GenOO::TranscriptCollection object
    my $collection = $factory_implementation->read_collection;
    print ref($collection) # GenOO::TranscriptCollection::Type::DoubleHashArray

=cut

# Let the code begin...

package GenOO::TranscriptCollection::Factory::GTF;
$GenOO::TranscriptCollection::Factory::GTF::VERSION = '1.5.2';
#######################################################################
#######################   Load External modules   #####################
#######################################################################
use Modern::Perl;
use autodie;
use Moose;
use namespace::autoclean;


#######################################################################
#######################   Load GenOO modules      #####################
#######################################################################
use GenOO::RegionCollection::Factory;
use GenOO::Transcript;
use GenOO::Gene;
use GenOO::Data::File::GFF;


#######################################################################
#######################   Interface attributes   ######################
#######################################################################
has 'file' => (
	isa => 'Str', 
	is  => 'ro'
);


#######################################################################
##########################   Consumed Roles   #########################
#######################################################################
with 'GenOO::RegionCollection::Factory::Requires';


#######################################################################
########################   Interface Methods   ########################
#######################################################################
sub read_collection {
	my ($self) = @_;
	
	my @transcripts = $self->_read_gtf_with_transcripts($self->file);
	
	return GenOO::RegionCollection::Factory->create('RegionArray', {
		array => \@transcripts
	})->read_collection;
}

#######################################################################
#########################   Private methods  ##########################
#######################################################################
sub _read_gtf_with_transcripts {
	my ($self, $file)=@_;
	
	my %transcripts;
	my %transcript_splice_starts;
	my %transcript_splice_stops;
	my %genes;
	
	my $gff = GenOO::Data::File::GFF->new(file => $file);

	while (my $record = $gff->next_record){
		my $transcript_id = $record->attribute('transcript_id') or die "transcript_id attribute must be defined\n";
	
		if ($record->strand == 0){
			warn "Skipping transcript $transcript_id: strand symbol". $record->strand_symbol." not accepted\n";



( run in 0.561 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )