| 1 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | GenOO::TranscriptCollection::Factory::GTF - Factory to create TranscriptCollection from a GTF file | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | Creates GenOO::TranscriptCollection containing transcripts from a GTF file | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | Preferably use it through the generic GenOO::TranscriptCollection::Factory | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | my $factory = GenOO::TranscriptCollection::Factory->new('GTF',{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | file => 'sample.gtf' | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | An instance of this class is a concrete factory for the creation of a | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | L<GenOO::TranscriptCollection> containing transcripts from a GTF file. It offers the method | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | "read_collection" (as the consumed role requires) which returns the actual | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | L<GenOO::TranscriptCollection> object in the form of | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | L<GenOO::RegionCollection::Type::DoubleHashArray>. The latter is the implementation | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | of the L<GenOO::RegionCollection> class based on the complex data structure | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | L<GenOO::Data::Structure::DoubleHashArray>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | =head1 EXAMPLES | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # Create a concrete factory | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | my $factory_implementation = GenOO::TranscriptCollection::Factory->new('GTF',{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | file => 'sample.gtf' | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # Return the actual GenOO::TranscriptCollection object | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | my $collection = $factory_implementation->read_collection; | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | print ref($collection) # GenOO::TranscriptCollection::Type::DoubleHashArray | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # Let the code begin... | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | package GenOO::TranscriptCollection::Factory::GTF; | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | $GenOO::TranscriptCollection::Factory::GTF::VERSION = '1.4.9'; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | ####################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ####################### Load External modules ##################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ####################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | use Modern::Perl; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ####################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ####################### Load GenOO modules ##################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ####################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | use GenOO::RegionCollection::Factory; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | use GenOO::Transcript; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | use GenOO::Gene; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | use GenOO::Data::File::GFF; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ####################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ####################### Interface attributes ###################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ####################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | has 'file' => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | is => 'ro' | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ####################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ########################## Consumed Roles ######################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ####################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | with 'GenOO::RegionCollection::Factory::Requires'; | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ####################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ######################## Interface Methods ######################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ####################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | sub read_collection { | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 9 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_collection: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 9 | my @transcripts = $self->_read_gtf_with_transcripts($self->file); | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 9 | return GenOO::RegionCollection::Factory->create('RegionArray', { | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | array => \@transcripts | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | })->read_collection; | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | ####################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | ######################### Private methods ########################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | ####################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | sub _read_gtf_with_transcripts { | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 9 | ▶ | my ($self, $file)=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_gtf_with_transcripts: called CC=23 SCAR=34.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 9 | my %transcripts; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | my %transcript_splice_starts; | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 9 | my %transcript_splice_stops; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 9 | my %genes; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 9 | my $gff = GenOO::Data::File::GFF->new(file => $file); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 9 | ▶ | while (my $record = $gff->next_record){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 4936 | ▶ | my $transcript_id = $record->attribute('transcript_id') or die "transcript_id attribute must be defined\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 4936 | ▶ | if ($record->strand == 0){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | warn "Skipping transcript $transcript_id: strand symbol". $record->strand_symbol." not accepted\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # Get transcript with id or create a new one. Update coordinates if required | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 4936 | my $transcript = $transcripts{$transcript_id}; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 4936 | ▶ | if (not defined $transcript) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 618 | $transcript = GenOO::Transcript->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | id => $transcript_id, | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | chromosome => $record->rname, | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | strand => $record->strand, | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | start => $record->start, | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | stop => $record->stop, | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | splice_starts => [$record->start], # will be re-written later | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | splice_stops => [$record->stop], # will be re-written later | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 618 | $transcripts{$transcript_id} = $transcript; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 618 | $transcript_splice_starts{$transcript_id} = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | 618 | $transcript_splice_stops{$transcript_id} = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 4318 | ▶ | $transcript->start($record->start) if ($record->start < $transcript->start); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 4318 | ▶ | $transcript->stop($record->stop) if ($record->stop > $transcript->stop); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 4936 | ▶ | if ($record->feature eq 'exon') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 3369 | push @{$transcript_splice_starts{$transcript_id}}, $record->start; | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 3369 | push @{$transcript_splice_stops{$transcript_id}}, $record->stop; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | elsif ($record->feature eq 'start_codon') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 197 | ▶ | if ($record->strand == 1 and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
$record->strand == 1 and !defined($transcript->coding_start) || $record->start < $transcript->coding_start
not defined $transcript->coding_start or $record->start < $transcript->coding_start
MC/DC33%1/3
$record->strand == 1 and !defined($transcript->coding_start) || $record->start < $transcript->coding_start
$record->strand == 1
not defined $transcript->coding_start
$record->start < $transcript->coding_start
Truth table50%2/4
A and not(B) or C
A= $record->strand == 1B= not defined $transcript->coding_startC= $record->start < $transcript->coding_start
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | (!defined $transcript->coding_start or | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | $record->start < $transcript->coding_start)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 116 | $transcript->coding_start($record->start); | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | ▶ | elsif ($record->strand == -1 and | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$record->strand == -1 and !defined($transcript->coding_stop) || $record->stop > $transcript->coding_stop
not defined $transcript->coding_stop or $record->stop > $transcript->coding_stop
MC/DC0%0/3
$record->strand == -1 and !defined($transcript->coding_stop) || $record->stop > $transcript->coding_stop
$record->strand == -1
not defined $transcript->coding_stop
$record->stop > $transcript->coding_stop
Truth table25%1/4
A and not(B) or C
A= $record->strand == -1B= not defined $transcript->coding_stopC= $record->stop > $transcript->coding_stop
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | (!defined $transcript->coding_stop or | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | $record->stop > $transcript->coding_stop)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 81 | $transcript->coding_stop($record->stop); | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | elsif ($record->feature eq 'stop_codon') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 197 | ▶ | if ($record->strand == 1 and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
$record->strand == 1 and !defined($transcript->coding_stop) || $record->stop > $transcript->coding_stop
not defined $transcript->coding_stop or $record->stop > $transcript->coding_stop
MC/DC33%1/3
$record->strand == 1 and !defined($transcript->coding_stop) || $record->stop > $transcript->coding_stop
$record->strand == 1
not defined $transcript->coding_stop
$record->stop > $transcript->coding_stop
Truth table50%2/4
A and not(B) or C
A= $record->strand == 1B= not defined $transcript->coding_stopC= $record->stop > $transcript->coding_stop
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | (!defined $transcript->coding_stop or | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | $record->stop > $transcript->coding_stop)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 116 | $transcript->coding_stop($record->stop); | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | ▶ | elsif ($record->strand == -1 and | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$record->strand == -1 and !defined($transcript->coding_start) || $record->start < $transcript->coding_start
not defined $transcript->coding_start or $record->start < $transcript->coding_start
MC/DC0%0/3
$record->strand == -1 and !defined($transcript->coding_start) || $record->start < $transcript->coding_start
$record->strand == -1
not defined $transcript->coding_start
$record->start < $transcript->coding_start
Truth table25%1/4
A and not(B) or C
A= $record->strand == -1B= not defined $transcript->coding_startC= $record->start < $transcript->coding_start
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | (!defined $transcript->coding_start or | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | $record->start < $transcript->coding_start)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 81 | $transcript->coding_start($record->start); | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 9 | foreach my $transcript_id (keys %transcripts) { | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | 618 | $transcripts{$transcript_id}->set_splice_starts_and_stops($transcript_splice_starts{$transcript_id}, $transcript_splice_stops{$transcript_id}); | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 9 | return values %transcripts; | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||