| 1 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | GenOO::Data::File::GFF::Record - Object representing a record of a gff file | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # Object representing a record of a gff file | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # To initialize | ||||||||||||||||||||||||||||
| 12 | my $record = GenOO::Data::File::GFF::Record->new( | ||||||||||||||||||||||||||||
| 13 | seqname => undef, | ||||||||||||||||||||||||||||
| 14 | source => undef, | ||||||||||||||||||||||||||||
| 15 | feature => undef, | ||||||||||||||||||||||||||||
| 16 | start_1_based => undef, | ||||||||||||||||||||||||||||
| 17 | stop_1_based => undef, | ||||||||||||||||||||||||||||
| 18 | score => undef, | ||||||||||||||||||||||||||||
| 19 | strand => undef, | ||||||||||||||||||||||||||||
| 20 | frame => undef, | ||||||||||||||||||||||||||||
| 21 | attributes => undef, | ||||||||||||||||||||||||||||
| 22 | comment => undef, | ||||||||||||||||||||||||||||
| 23 | extra_info => undef, | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | This object represents a record of a gff file and offers methods for accessing the different attributes. | ||||||||||||||||||||||||||||
| 30 | It transforms original attributes into ones compatible with the rest of the framework eg 1-based to 0-based. | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head1 EXAMPLES | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # Return 1 or -1 for the strand | ||||||||||||||||||||||||||||
| 35 | my $strand = $record->strand(); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =cut | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # Let the code begin... | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | package GenOO::Data::File::GFF::Record; | ||||||||||||||||||||||||||||
| 43 | 1 | $GenOO::Data::File::GFF::Record::VERSION = '1.4.9'; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | ####################################################################### | ||||||||||||||||||||||||||||
| 46 | ####################### Load External modules ##################### | ||||||||||||||||||||||||||||
| 47 | ####################################################################### | ||||||||||||||||||||||||||||
| 48 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 1 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | ####################################################################### | ||||||||||||||||||||||||||||
| 54 | ####################### Subtypes & Coercions ###################### | ||||||||||||||||||||||||||||
| 55 | ####################################################################### | ||||||||||||||||||||||||||||
| 56 | 10958 | ▶ | subtype 'GenOO::Data::File::GFF::Record::Strand', as 'Int', where {($_ == 1) or ($_ == -1) or ($_ == 0)}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.7
Branch: 1 branch
Condition66%2/3
$_ == 1 or $_ == -1
MC/DC0%0/2
$_ == 1 or $_ == -1
$_ == 1
$_ == -1
Truth table66%2/3
A or B
A= $_ == 1B= $_ == -1
| |||||||||||||||||||||||||||||
| 57 | 10958 | ▶ | coerce 'GenOO::Data::File::GFF::Record::Strand', from 'Str', via { _sanitize_strand($_) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | ####################################################################### | ||||||||||||||||||||||||||||
| 61 | ####################### Interface attributes ###################### | ||||||||||||||||||||||||||||
| 62 | ####################################################################### | ||||||||||||||||||||||||||||
| 63 | 1 | has 'seqname' => ( | |||||||||||||||||||||||||||
| 64 | isa => 'Str', | ||||||||||||||||||||||||||||
| 65 | is => 'ro', | ||||||||||||||||||||||||||||
| 66 | required => 1 | ||||||||||||||||||||||||||||
| 67 | ); # The name of the sequence | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | has 'source' => ( | |||||||||||||||||||||||||||
| 70 | isa => 'Str', | ||||||||||||||||||||||||||||
| 71 | is => 'ro', | ||||||||||||||||||||||||||||
| 72 | required => 1 | ||||||||||||||||||||||||||||
| 73 | ); # The source of the feature | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | has 'feature' => ( | |||||||||||||||||||||||||||
| 76 | isa => 'Str', | ||||||||||||||||||||||||||||
| 77 | is => 'ro', | ||||||||||||||||||||||||||||
| 78 | required => 1 | ||||||||||||||||||||||||||||
| 79 | ); # The feature type name | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | has 'start_1_based' => ( | |||||||||||||||||||||||||||
| 82 | isa => 'Int', | ||||||||||||||||||||||||||||
| 83 | is => 'ro', | ||||||||||||||||||||||||||||
| 84 | required => 1 | ||||||||||||||||||||||||||||
| 85 | ); # 1-based | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | has 'stop_1_based' => ( | |||||||||||||||||||||||||||
| 88 | isa => 'Int', | ||||||||||||||||||||||||||||
| 89 | is => 'ro', | ||||||||||||||||||||||||||||
| 90 | required => 1 | ||||||||||||||||||||||||||||
| 91 | ); # 1-based | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | has 'score' => ( | |||||||||||||||||||||||||||
| 94 | is => 'ro', | ||||||||||||||||||||||||||||
| 95 | required => 1 | ||||||||||||||||||||||||||||
| 96 | ); # A floating point value. | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | has 'strand' => ( | |||||||||||||||||||||||||||
| 99 | isa => 'GenOO::Data::File::GFF::Record::Strand', | ||||||||||||||||||||||||||||
| 100 | is => 'ro', | ||||||||||||||||||||||||||||
| 101 | required => 1, | ||||||||||||||||||||||||||||
| 102 | coerce => 1 | ||||||||||||||||||||||||||||
| 103 | ); # One of +, - or . | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 1 | has 'frame' => ( | |||||||||||||||||||||||||||
| 106 | is => 'ro', | ||||||||||||||||||||||||||||
| 107 | required => 1 | ||||||||||||||||||||||||||||
| 108 | ); # 0, 1, 2, .. Is region in frame? | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 1 | has 'comment' => ( | |||||||||||||||||||||||||||
| 111 | isa => 'Maybe[Str]', | ||||||||||||||||||||||||||||
| 112 | is => 'ro', | ||||||||||||||||||||||||||||
| 113 | required => 1 | ||||||||||||||||||||||||||||
| 114 | ); # A comment | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | has 'attributes' => ( | ||||||||||||||||||||||||||||
| 117 | traits => ['Hash'], | ||||||||||||||||||||||||||||
| 118 | is => 'ro', | ||||||||||||||||||||||||||||
| 119 | isa => 'HashRef[Str]', | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 121 | 1 | handles => { | |||||||||||||||||||||||||||
| 122 | set_attribute => 'set', | ||||||||||||||||||||||||||||
| 123 | attribute => 'get', | ||||||||||||||||||||||||||||
| 124 | }, | ||||||||||||||||||||||||||||
| 125 | ); # Hash with attribute-value (strings) | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 1 | has 'rname' => ( | |||||||||||||||||||||||||||
| 128 | isa => 'Str', | ||||||||||||||||||||||||||||
| 129 | is => 'ro', | ||||||||||||||||||||||||||||
| 130 | builder => '_set_rname', | ||||||||||||||||||||||||||||
| 131 | lazy => 1 | ||||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 1 | has 'start' => ( | |||||||||||||||||||||||||||
| 135 | isa => 'Int', | ||||||||||||||||||||||||||||
| 136 | is => 'ro', | ||||||||||||||||||||||||||||
| 137 | builder => '_calculate_start', | ||||||||||||||||||||||||||||
| 138 | lazy => 1 | ||||||||||||||||||||||||||||
| 139 | ); | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 1 | has 'stop' => ( | |||||||||||||||||||||||||||
| 142 | isa => 'Int', | ||||||||||||||||||||||||||||
| 143 | is => 'ro', | ||||||||||||||||||||||||||||
| 144 | builder => '_calculate_stop', | ||||||||||||||||||||||||||||
| 145 | lazy => 1 | ||||||||||||||||||||||||||||
| 146 | ); | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 1 | with 'GenOO::Region'; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | ####################################################################### | ||||||||||||||||||||||||||||
| 152 | ############################ Accessors ############################ | ||||||||||||||||||||||||||||
| 153 | ####################################################################### | ||||||||||||||||||||||||||||
| 154 | sub copy_number { | ||||||||||||||||||||||||||||
| 155 | 0 | ▶ | return 1; | ||||||||||||||||||||||||||
|
Subroutine
copy_number: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | sub strand_symbol { | ||||||||||||||||||||||||||||
| 159 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
strand_symbol: called CC=5 SCAR=22.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 1 | my $strand = $self->strand; | |||||||||||||||||||||||||||
| 162 | 1 | ▶ | if (defined $strand) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 1 | ▶ | if ($strand == 1) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 164 | 1 | return '+'; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | elsif ($strand == -1) { | ||||||||||||||||||||||||||||
| 167 | 0 | return '-'; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | elsif ($strand == 0) { | ||||||||||||||||||||||||||||
| 170 | 0 | return '.'; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | else { | ||||||||||||||||||||||||||||
| 174 | 0 | return undef; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | ####################################################################### | ||||||||||||||||||||||||||||
| 179 | ######################### Private methods ########################## | ||||||||||||||||||||||||||||
| 180 | ####################################################################### | ||||||||||||||||||||||||||||
| 181 | sub _sanitize_strand { | ||||||||||||||||||||||||||||
| 182 | 10958 | ▶ | my ($value) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_sanitize_strand: called CC=4 SCAR=15.6
| |||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 10958 | ▶ | if ($value eq '+') { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 185 | 6036 | return 1; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | elsif ($value eq '-') { | ||||||||||||||||||||||||||||
| 188 | 4922 | return -1; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | elsif ($value eq '.') { | ||||||||||||||||||||||||||||
| 191 | 0 | return 0; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | sub _set_rname { | ||||||||||||||||||||||||||||
| 196 | 966 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_set_rname: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 966 | return $self->seqname; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | sub _calculate_start { | ||||||||||||||||||||||||||||
| 202 | 10747 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_calculate_start: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 10747 | return $self->start_1_based - 1; | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | sub _calculate_stop { | ||||||||||||||||||||||||||||
| 208 | 10747 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_calculate_stop: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 10747 | return $self->stop_1_based - 1; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | ####################################################################### | ||||||||||||||||||||||||||||
| 214 | ############################ Finalize ############################# | ||||||||||||||||||||||||||||
| 215 | ####################################################################### | ||||||||||||||||||||||||||||
| 216 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 1 | 1; | |||||||||||||||||||||||||||