GenOO/Gene.pm

filter: Statementstmt 72.1% 140 / 194 Branchbran 47.8% 22 / 46 Conditioncond 83.3% 15 / 18 MC/DCmcdc 66.6% 8 / 12 Subroutinesub 73.9% 17 / 23 Podpod 0.0% 0 / 10 totaltotal 66.6% 202 / 303 CC 54 SCAR 21.9
CC
54
Cov
69%
_build_utr5_exonic_regions
30.0
_build_utr3_exonic_regions
30.0
_build_cds_exonic_regions
20.0
CRAP 9.0
« GenOO/Module/Search/Binary.pm ↑ Summary GenOO/GeneCollection/Factory/FromTranscriptCollection.pm »
1 # POD documentation - main docs before the code
2  
3 =head1 NAME
4  
5 GenOO::Gene - Gene object
6  
7 =head1 SYNOPSIS
8  
9 # This object represents a gene (collection of transcripts)
10 # It extends the L<GenOO::GenomicRegion> object
11
12 # To initialize
13 my $gene = GenOO::Gene->new(
14 name => undef, #required
15 species => undef,
16 strand => undef, #can be inferred from transcripts
17 chromosome => undef, #can be inferred from transcripts
18 start => undef, #can be inferred from transcripts
19 stop => undef, #can be inferred from transcripts
20 copy_number => undef, #defaults to 1
21 sequence => undef,
22 description => undef,
23 transcripts => reference to an array of L<GenOO::Transcript> objects
24 );
25  
26 =head1 DESCRIPTION
27  
28 GenOO::Gene describes a gene. A gene is defined as a genomic region (it has the strand, chromosome, start and stop
29 attributes required by L<GenOO::GenomicRegion>) as well as collection of L<GenOO::Transcript> objects. The genomic
30 location attributes can be inferred by the locations of the contained transcripts. The start position of the gene
31 will be the smallest coordinate of all the contained transcripts etc.
32 Whenever a transcript is added to a gene object the genomic coordinates of the gene are automatically updated.
33 It is a good idea NOT to set the genomic location of the gene directly but to let it be inferred by the transcripts.
34  
35 =head1 EXAMPLES
36 # Create a new gene object
37 my $gene = GenOO::Gene->new(
38 name => '2310016C08Rik',
39 description => 'hypoxia-inducible gene 2 protein isoform 2',
40 transcripts => [
41 GenOO::Transcript->new(
42 id => 'uc012eiw.1',
43 strand => 1,
44 chromosome => 'chr6',
45 start => 29222487,
46 stop => 29225448,
47 coding_start => 29222571,
48 coding_stop => 29224899,
49 biotype => 'coding',
50 splice_starts => [29222487,29224649],
51 splice_stops => [29222607,29225448]
52 ),
53 GenOO::Transcript->new(
54 id => 'uc009bdd.2',
55 strand => 1,
56 chromosome => 'chr6',
57 start => 29222625,
58 stop => 29225448,
59 coding_start => 29224705,
60 coding_stop => 29224899,
61 biotype => 'coding',
62 splice_starts => [29222625,29224649],
63 splice_stops => [29222809,29225448]
64 )
65 ],
66 );
67
68 # Get gene information
69 $gene->strand; # 1
70 $gene->chromosome; # chr6
71 $gene->start; # 29222487
72 $gene->stop; # 29225448
73  
74 =cut
75  
76 # Let the code begin...
77  
78 package GenOO::Gene;
79 1 $GenOO::Gene::VERSION = '1.4.9';
80 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 1 extends 'GenOO::GenomicRegion';
84  
85 1 has 'name' => (
86 isa => 'Str',
87 is => 'rw',
88 required => 1
89 );
90  
91 1 has 'description' => (
92 isa => 'Str',
93 is => 'rw'
94 );
95  
96 has 'transcripts' => (
97 isa => 'ArrayRef[GenOO::Transcript]',
98 is => 'rw',
99 172 ▶ default => sub {[]}
Subroutine __ANON__: called CC=1 SCAR=0.0
100 1 );
101  
102 1 has 'strand' => (
103 is => 'rw',
104 builder => '_find_strand',
105 clearer => '_clear_strand',
106 lazy => 1,
107 );
108  
109 1 has 'chromosome' => (
110 is => 'rw',
111 builder => '_find_chromosome',
112 clearer => '_clear_chromosome',
113 lazy => 1,
114 );
115  
116 1 has 'start' => (
117 is => 'rw',
118 builder => '_find_start',
119 clearer => '_clear_start',
120 lazy => 1,
121 );
122  
123 1 has 'stop' => (
124 is => 'rw',
125 builder => '_find_stop',
126 clearer => '_clear_stop',
127 lazy => 1,
128 );
129  
130 1 has 'exonic_regions' => (
131 traits => ['Array'],
132 is => 'ro',
133 builder => '_build_exonic_regions',
134 clearer => '_clear_exonic_regions',
135 handles => {
136 all_exonic_regions => 'elements',
137 exonic_regions_count => 'count',
138 },
139 lazy => 1
140 );
141  
142 1 has 'utr5_exonic_regions' => (
143 traits => ['Array'],
144 is => 'ro',
145 builder => '_build_utr5_exonic_regions',
146 clearer => '_clear_utr5_exonic_regions',
147 handles => {
148 all_utr5_exonic_regions => 'elements',
149 utr5_exonic_regions_count => 'count',
150 },
151 lazy => 1
152 );
153  
154 1 has 'cds_exonic_regions' => (
155 traits => ['Array'],
156 is => 'ro',
157 builder => '_build_cds_exonic_regions',
158 clearer => '_clear_cds_exonic_regions',
159 handles => {
160 all_cds_exonic_regions => 'elements',
161 cds_exonic_regions_count => 'count',
162 },
163 lazy => 1
164 );
165  
166 1 has 'utr3_exonic_regions' => (
167 traits => ['Array'],
168 is => 'ro',
169 builder => '_build_utr3_exonic_regions',
170 clearer => '_clear_utr3_exonic_regions',
171 handles => {
172 all_utr3_exonic_regions => 'elements',
173 utr3_exonic_regions_count => 'count',
174 },
175 lazy => 1
176 );
177  
178 #######################################################################
179 ######################## Interface Methods ########################
180 #######################################################################
181 sub coding_transcripts {
182 2 ▶ my ($self) = @_;
Subroutine coding_transcripts: called CC=2 SCAR=7.6
Pod undocumented
183
184 2 ▶ if (defined $self->transcripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->transcripts) { } 2 0 2
185 2 return [grep {$_->is_coding} @{$self->transcripts}];
186 }
187 else {
188 0 warn "No transcripts found for ".$self->name."\n";
189 0 return undef;
190 }
191 }
192  
193 sub non_coding_transcripts {
194 1 ▶ my ($self) = @_;
Subroutine non_coding_transcripts: called CC=2 SCAR=7.6
Pod undocumented
195
196 1 ▶ if (defined $self->transcripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->transcripts) { } 1 0 1
197 1 return [grep {not $_->is_coding} @{$self->transcripts}];
198 }
199 else {
200 0 warn "No transcripts found for ".$self->name."\n";
201 0 return undef;
202 }
203 }
204  
205 sub add_transcript {
206 350 ▶ my ($self, $transcript) = @_;
Subroutine add_transcript: called CC=3 SCAR=12.3
Pod undocumented
207
208 350 ▶ if (defined $transcript and ($transcript->isa('GenOO::Transcript'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $transcript and $transcript->isa('GenOO::Transcript')) { } 350 0 350
Condition33%1/3
defined $transcript and $transcript->isa("GenOO::Transcript")
!ll&&!rl&&r
00350
MC/DC0%0/2
defined $transcript and $transcript->isa("GenOO::Transcript")
defined $transcript $transcript->isa("GenOO::Transcript")
Truth table33%1/3
A and B
A= defined $transcriptB= $transcript->isa("GenOO::Transcript")
ABresult
0X0
100
111
209 350 push @{$self->transcripts}, $transcript;
210 350 $self->_reset;
211 }
212 else {
213 0 warn 'Object "'.ref($transcript).'" is not a GenOO::Transcript ... skipped';
214 }
215 }
216  
217 sub constitutive_exonic_regions {
218 1 ▶ my ($self) = @_;
Subroutine constitutive_exonic_regions: called CC=7 SCAR=19.5
Pod undocumented
219
220 1 my %counts;
221 1 foreach my $transcript (@{$self->transcripts}) {
222 2 foreach my $exon (@{$transcript->exons}) {
223 4 $counts{$exon->location}++;
224 }
225 }
226
227 1 my @constitutive_exons;
228 1 my $transcript_count = @{$self->transcripts};
229 1 foreach my $transcript (@{$self->transcripts}) {
230 2 foreach my $exon (@{$transcript->exons}) {
231 4 ▶ if (exists $counts{$exon->location} and ($counts{$exon->location} == $transcript_count)) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $counts{$exon->location} and $counts{$exon->location} == $transcript_count) 1 3 4
Condition100%3/3
exists $counts{$exon->location} and $counts{$exon->location} == $transcript_count
!ll&&!rl&&r
121
MC/DC100%2/2
exists $counts{$exon->location} and $counts{$exon->location} == $transcript_count
exists $counts{$exon->location} $counts{$exon->location} == $transcript_count
Truth table100%3/3
A and B
A= exists $counts{$exon->location}B= $counts{$exon->location} == $transcript_count
ABresult
0X0
100
111
232 1 push @constitutive_exons, GenOO::GenomicRegion->new(
233 strand => $exon->strand,
234 chromosome => $exon->chromosome,
235 start => $exon->start,
236 stop => $exon->stop
237 );
238
239 1 delete $counts{$exon->location};
240 }
241 }
242 }
243 1 return \@constitutive_exons;
244 }
245  
246 sub constitutive_coding_exonic_regions {
247 1 ▶ my ($self) = @_;
Subroutine constitutive_coding_exonic_regions: called CC=7 SCAR=19.5
Pod undocumented
248
249 1 my %counts;
250 1 foreach my $transcript (@{$self->transcripts}) {
251 2 foreach my $exon (@{$transcript->exons}) {
252 4 $counts{$exon->location}++;
253 }
254 }
255
256 1 my @constitutive_exons;
257 1 my $transcript_count = @{$self->coding_transcripts};
258 1 foreach my $transcript (@{$self->transcripts}) {
259 2 foreach my $exon (@{$transcript->exons}) {
260 4 ▶ if (exists $counts{$exon->location} and ($counts{$exon->location} == $transcript_count)) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $counts{$exon->location} and $counts{$exon->location} == $transcript_count) 1 3 4
Condition100%3/3
exists $counts{$exon->location} and $counts{$exon->location} == $transcript_count
!ll&&!rl&&r
121
MC/DC100%2/2
exists $counts{$exon->location} and $counts{$exon->location} == $transcript_count
exists $counts{$exon->location} $counts{$exon->location} == $transcript_count
Truth table100%3/3
A and B
A= exists $counts{$exon->location}B= $counts{$exon->location} == $transcript_count
ABresult
0X0
100
111
261 1 push @constitutive_exons, GenOO::GenomicRegion->new(
262 strand => $exon->strand,
263 chromosome => $exon->chromosome,
264 start => $exon->start,
265 stop => $exon->stop
266 );
267
268 1 delete $counts{$exon->location};
269 }
270 }
271 }
272 1 return \@constitutive_exons;
273 }
274  
275 sub has_coding_transcript {
276 1 ▶ my ($self) = @_;
Subroutine has_coding_transcript: called CC=3 SCAR=11.4
Pod undocumented
277
278 1 foreach my $transcript (@{$self->transcripts}) {
279 1 ▶ if ($transcript->is_coding) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transcript->is_coding) 1 0 1
280 1 return 1;
281 }
282 }
283
284 0 return 0;
285 }
286  
287 sub exonic_length {
288 1 ▶ my ($self) = @_;
Subroutine exonic_length: called CC=2 SCAR=6.9
Pod undocumented
289
290 1 my $exonic_length = 0;
291 1 foreach my $region ($self->all_exonic_regions) {
292 3 $exonic_length += $region->length
293 }
294
295 1 return $exonic_length;
296 }
297  
298 sub utr5_exonic_length {
299 0 ▶ my ($self) = @_;
Subroutine utr5_exonic_length: not called CC=2 SCAR=17.9
Pod undocumented
300
301 0 my $exonic_length = 0;
302 0 foreach my $region ($self->all_utr5_exonic_regions) {
303 0 $exonic_length += $region->length
304 }
305
306 0 return $exonic_length;
307 }
308  
309 sub cds_exonic_length {
310 0 ▶ my ($self) = @_;
Subroutine cds_exonic_length: not called CC=2 SCAR=17.9
Pod undocumented
311
312 0 my $exonic_length = 0;
313 0 foreach my $region ($self->all_cds_exonic_regions) {
314 0 $exonic_length += $region->length
315 }
316
317 0 return $exonic_length;
318 }
319  
320 sub utr3_exonic_length {
321 0 ▶ my ($self) = @_;
Subroutine utr3_exonic_length: not called CC=2 SCAR=17.9
Pod undocumented
322
323 0 my $exonic_length = 0;
324 0 foreach my $region ($self->all_utr3_exonic_regions) {
325 0 $exonic_length += $region->length
326 }
327
328 0 return $exonic_length;
329 }
330  
331 #######################################################################
332 ######################### Private methods ##########################
333 #######################################################################
334 sub _find_strand {
335 163 ▶ my ($self) = @_;
Subroutine _find_strand: called CC=3 SCAR=11.6
336
337 163 my $strand;
338 163 ▶ if (defined $self->transcripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->transcripts) 163 0 163
339 163 $strand = $self->transcripts->[0]->strand;
340 }
341
342 163 ▶ if (not defined $strand) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $strand) { } 0 163 163
343 0 die "No strand found for ".$self->name."\n";
344 }
345 else {
346 163 return $strand;
347 }
348 }
349  
350 sub _find_chromosome {
351 163 ▶ my ($self) = @_;
Subroutine _find_chromosome: called CC=3 SCAR=11.6
352
353 163 my $chromosome;
354 163 ▶ if (defined $self->transcripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->transcripts) 163 0 163
355 163 $chromosome = $self->transcripts->[0]->chromosome;
356 }
357
358 163 ▶ if (not defined $chromosome) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $chromosome) { } 0 163 163
359 0 die "No chromosome found for ".$self->name."\n";
360 }
361 else {
362 163 return $chromosome;
363 }
364 }
365  
366 sub _find_start {
367 1 ▶ my ($self) = @_;
Subroutine _find_start: called CC=6 SCAR=19.0
368
369 1 my $start;
370 1 ▶ if (defined $self->transcripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->transcripts) 1 0 1
371 1 foreach my $transcript (@{$self->transcripts}) {
372 2 ▶ if ((not defined $start) or ($start > $transcript->start)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $start or $start > $transcript->start) 2 0 2
Condition66%2/3
not defined $start or $start > $transcript->start
l!l&&r!l&&!r
110
MC/DC0%0/2
not defined $start or $start > $transcript->start
not defined $start $start > $transcript->start
Truth table66%2/3
not(A) or B
A= not defined $startB= $start > $transcript->start
ABresult
1X1
011
000
373 2 $start = $transcript->start;
374 }
375 }
376 }
377
378 1 ▶ if (not defined $start) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $start) { } 0 1 1
379 0 die "No start found for ".$self->name."\n";
380 }
381 else {
382 1 return $start;
383 }
384 }
385  
386 sub _find_stop {
387 193 ▶ my ($self) = @_;
Subroutine _find_stop: called CC=6 SCAR=18.2
388
389 193 my $stop;
390 193 ▶ if (defined $self->transcripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->transcripts) 193 0 193
391 193 foreach my $transcript (@{$self->transcripts}) {
392 374 ▶ if ((not defined $stop) or ($stop < $transcript->stop)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $stop or $stop < $transcript->stop) 235 139 374
Condition100%3/3
not defined $stop or $stop < $transcript->stop
l!l&&r!l&&!r
19342139
MC/DC100%2/2
not defined $stop or $stop < $transcript->stop
not defined $stop $stop < $transcript->stop
Truth table100%3/3
not(A) or B
A= not defined $stopB= $stop < $transcript->stop
ABresult
1X1
011
000
393 235 $stop = $transcript->stop;
394 }
395 }
396 }
397
398 193 ▶ if (not defined $stop) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $stop) { } 0 193 193
399 0 die "No stop found for ".$self->name."\n";
400 }
401 else {
402 193 return $stop;
403 }
404 }
405  
406 sub _build_exonic_regions {
407 2 ▶ my ($self) = @_;
Subroutine _build_exonic_regions: called CC=3 SCAR=11.0
408
409 2 my @all_exons;
410 2 foreach my $transcript (@{$self->transcripts}) {
411 4 foreach my $exon (@{$transcript->exons}) {
412 8 push @all_exons, $exon;
413 }
414 }
415
416 2 return $self->_merge_exons(\@all_exons);
417 }
418  
419 sub _build_utr5_exonic_regions {
420 0 ▶ my ($self) = @_;
Subroutine _build_utr5_exonic_regions: not called CC=5 SCAR=34.0
421
422 0 my @all_exons;
423 0 foreach my $transcript (@{$self->transcripts}) {
424 0 ▶ next if !$transcript->is_coding;
Branch: 1 branch
BranchTrueFalseTotal
unless $transcript->is_coding 0 0 0
425 0 ▶ next if !defined $transcript->utr5;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $transcript->utr5 0 0 0
426 0 foreach my $exon (@{$transcript->utr5->exons}) {
427 0 push @all_exons, $exon;
428 }
429 }
430
431 0 return $self->_merge_exons(\@all_exons);
432 }
433  
434 sub _build_cds_exonic_regions {
435 0 ▶ my ($self) = @_;
Subroutine _build_cds_exonic_regions: not called CC=4 SCAR=30.0
436
437 0 my @all_exons;
438 0 foreach my $transcript (@{$self->transcripts}) {
439 0 ▶ next if !$transcript->is_coding;
Branch: 1 branch
BranchTrueFalseTotal
unless $transcript->is_coding 0 0 0
440 0 foreach my $exon (@{$transcript->cds->exons}) {
441 0 push @all_exons, $exon;
442 }
443 }
444
445 0 return $self->_merge_exons(\@all_exons);
446 }
447  
448 sub _build_utr3_exonic_regions {
449 0 ▶ my ($self) = @_;
Subroutine _build_utr3_exonic_regions: not called CC=5 SCAR=34.0
450
451 0 my @all_exons;
452 0 foreach my $transcript (@{$self->transcripts}) {
453 0 ▶ next if !$transcript->is_coding;
Branch: 1 branch
BranchTrueFalseTotal
unless $transcript->is_coding 0 0 0
454 0 ▶ next if !defined $transcript->utr3;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $transcript->utr3 0 0 0
455 0 foreach my $exon (@{$transcript->utr3->exons}) {
456 0 push @all_exons, $exon;
457 }
458 }
459
460 0 return $self->_merge_exons(\@all_exons);
461 }
462  
463 sub _merge_exons {
464 2 ▶ my ($self, $exons) = @_;
Subroutine _merge_exons: called CC=5 SCAR=16.1
465
466 2 my @sorted_exons = sort{$a->start <=> $b->start} @$exons;
467
468 2 my @exonic_regions;
469 2 foreach my $exon (@sorted_exons) {
470 8 my $merge_region = $exonic_regions[-1];
471 8 ▶ if (defined $merge_region and $merge_region->overlaps($exon)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $merge_region and $merge_region->overlaps($exon)) { } 2 6 8
Condition100%3/3
defined $merge_region and $merge_region->overlaps($exon)
!ll&&!rl&&r
242
MC/DC100%2/2
defined $merge_region and $merge_region->overlaps($exon)
defined $merge_region $merge_region->overlaps($exon)
Truth table100%3/3
A and B
A= defined $merge_regionB= $merge_region->overlaps($exon)
ABresult
0X0
100
111
472 2 ▶ $merge_region->stop($exon->stop) if $exon->stop > $merge_region->stop;
Branch: 1 branch
BranchTrueFalseTotal
if $exon->stop > $merge_region->stop 0 2 2
473 }
474 else {
475 6 push @exonic_regions, GenOO::GenomicRegion->new(
476 strand => $exon->strand,
477 chromosome => $exon->chromosome,
478 start => $exon->start,
479 stop => $exon->stop,
480 );
481 }
482 }
483
484 2 return \@exonic_regions;
485 }
486  
487 sub _reset {
488 350 ▶ my ($self) = @_;
Subroutine _reset: called CC=1 SCAR=0.0
489
490 350 $self->_clear_strand;
491 350 $self->_clear_chromosome;
492 350 $self->_clear_start;
493 350 $self->_clear_stop;
494 350 $self->_clear_exonic_regions;
495 350 $self->_clear_utr5_exonic_regions;
496 350 $self->_clear_cds_exonic_regions;
497 350 $self->_clear_utr3_exonic_regions;
498 }
499  
500 1 __PACKAGE__->meta->make_immutable;
501  
502 1 1;
« GenOO/Module/Search/Binary.pm ↑ Summary GenOO/GeneCollection/Factory/FromTranscriptCollection.pm »