GenOO/Gene.pm

filter: Statementstmt 74.1% 155 / 209 Branchbran 52.0% 26 / 50 Conditioncond 88.8% 16 / 18 MC/DCmcdc 83.3% 10 / 12 Subroutinesub 76.0% 19 / 25 Podpod 0.0% 0 / 11 totaltotal 69.5% 226 / 325 CC 57 SCAR 21.4
CC
57
Cov
71%
_build_utr5_exonic_regions
30.0
_build_utr3_exonic_regions
30.0
_build_cds_exonic_regions
20.0
CRAP 8.5
« 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.5.0';
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 174 ▶ 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 'intronic_regions' => (
143 traits => ['Array'],
144 is => 'ro',
145 builder => '_build_intronic_regions',
146 clearer => '_clear_intronic_regions',
147 handles => {
148 all_intronic_regions => 'elements',
149 intronic_regions_count => 'count',
150 },
151 lazy => 1
152 );
153  
154 1 has 'utr5_exonic_regions' => (
155 traits => ['Array'],
156 is => 'ro',
157 builder => '_build_utr5_exonic_regions',
158 clearer => '_clear_utr5_exonic_regions',
159 handles => {
160 all_utr5_exonic_regions => 'elements',
161 utr5_exonic_regions_count => 'count',
162 },
163 lazy => 1
164 );
165  
166 1 has 'cds_exonic_regions' => (
167 traits => ['Array'],
168 is => 'ro',
169 builder => '_build_cds_exonic_regions',
170 clearer => '_clear_cds_exonic_regions',
171 handles => {
172 all_cds_exonic_regions => 'elements',
173 cds_exonic_regions_count => 'count',
174 },
175 lazy => 1
176 );
177  
178 1 has 'utr3_exonic_regions' => (
179 traits => ['Array'],
180 is => 'ro',
181 builder => '_build_utr3_exonic_regions',
182 clearer => '_clear_utr3_exonic_regions',
183 handles => {
184 all_utr3_exonic_regions => 'elements',
185 utr3_exonic_regions_count => 'count',
186 },
187 lazy => 1
188 );
189  
190 #######################################################################
191 ######################## Interface Methods ########################
192 #######################################################################
193 sub coding_transcripts {
194 2 ▶ my ($self) = @_;
Subroutine coding_transcripts: called CC=2 SCAR=7.6
Pod undocumented
195
196 2 ▶ if (defined $self->transcripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->transcripts) { } 2 0 2
197 2 return [grep {$_->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 non_coding_transcripts {
206 1 ▶ my ($self) = @_;
Subroutine non_coding_transcripts: called CC=2 SCAR=7.6
Pod undocumented
207
208 1 ▶ if (defined $self->transcripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->transcripts) { } 1 0 1
209 1 return [grep {not $_->is_coding} @{$self->transcripts}];
210 }
211 else {
212 0 warn "No transcripts found for ".$self->name."\n";
213 0 return undef;
214 }
215 }
216  
217 sub add_transcript {
218 350 ▶ my ($self, $transcript) = @_;
Subroutine add_transcript: called CC=3 SCAR=12.3
Pod undocumented
219
220 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
221 350 push @{$self->transcripts}, $transcript;
222 350 $self->_reset;
223 }
224 else {
225 0 warn 'Object "'.ref($transcript).'" is not a GenOO::Transcript ... skipped';
226 }
227 }
228  
229 sub constitutive_exonic_regions {
230 1 ▶ my ($self) = @_;
Subroutine constitutive_exonic_regions: called CC=7 SCAR=19.5
Pod undocumented
231
232 1 my %counts;
233 1 foreach my $transcript (@{$self->transcripts}) {
234 2 foreach my $exon (@{$transcript->exons}) {
235 4 $counts{$exon->location}++;
236 }
237 }
238
239 1 my @constitutive_exons;
240 1 my $transcript_count = @{$self->transcripts};
241 1 foreach my $transcript (@{$self->transcripts}) {
242 2 foreach my $exon (@{$transcript->exons}) {
243 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
244 1 push @constitutive_exons, GenOO::GenomicRegion->new(
245 strand => $exon->strand,
246 chromosome => $exon->chromosome,
247 start => $exon->start,
248 stop => $exon->stop
249 );
250
251 1 delete $counts{$exon->location};
252 }
253 }
254 }
255 1 return \@constitutive_exons;
256 }
257  
258 sub constitutive_coding_exonic_regions {
259 1 ▶ my ($self) = @_;
Subroutine constitutive_coding_exonic_regions: called CC=7 SCAR=19.5
Pod undocumented
260
261 1 my %counts;
262 1 foreach my $transcript (@{$self->transcripts}) {
263 2 foreach my $exon (@{$transcript->exons}) {
264 4 $counts{$exon->location}++;
265 }
266 }
267
268 1 my @constitutive_exons;
269 1 my $transcript_count = @{$self->coding_transcripts};
270 1 foreach my $transcript (@{$self->transcripts}) {
271 2 foreach my $exon (@{$transcript->exons}) {
272 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
273 1 push @constitutive_exons, GenOO::GenomicRegion->new(
274 strand => $exon->strand,
275 chromosome => $exon->chromosome,
276 start => $exon->start,
277 stop => $exon->stop
278 );
279
280 1 delete $counts{$exon->location};
281 }
282 }
283 }
284 1 return \@constitutive_exons;
285 }
286  
287 sub has_coding_transcript {
288 1 ▶ my ($self) = @_;
Subroutine has_coding_transcript: called CC=3 SCAR=11.4
Pod undocumented
289
290 1 foreach my $transcript (@{$self->transcripts}) {
291 1 ▶ if ($transcript->is_coding) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transcript->is_coding) 1 0 1
292 1 return 1;
293 }
294 }
295
296 0 return 0;
297 }
298  
299 sub exonic_length {
300 1 ▶ my ($self) = @_;
Subroutine exonic_length: called CC=2 SCAR=6.9
Pod undocumented
301
302 1 my $exonic_length = 0;
303 1 foreach my $region ($self->all_exonic_regions) {
304 3 $exonic_length += $region->length
305 }
306
307 1 return $exonic_length;
308 }
309  
310 sub intronic_length {
311 1 ▶ my ($self) = @_;
Subroutine intronic_length: called CC=2 SCAR=6.9
Pod undocumented
312
313 1 my $intronic_length = 0;
314 1 foreach my $region ($self->all_intronic_regions) {
315 2 $intronic_length += $region->length
316 }
317
318 1 return $intronic_length;
319 }
320  
321 sub utr5_exonic_length {
322 0 ▶ my ($self) = @_;
Subroutine utr5_exonic_length: not called CC=2 SCAR=17.9
Pod undocumented
323
324 0 my $exonic_length = 0;
325 0 foreach my $region ($self->all_utr5_exonic_regions) {
326 0 $exonic_length += $region->length
327 }
328
329 0 return $exonic_length;
330 }
331  
332 sub cds_exonic_length {
333 0 ▶ my ($self) = @_;
Subroutine cds_exonic_length: not called CC=2 SCAR=17.9
Pod undocumented
334
335 0 my $exonic_length = 0;
336 0 foreach my $region ($self->all_cds_exonic_regions) {
337 0 $exonic_length += $region->length
338 }
339
340 0 return $exonic_length;
341 }
342  
343 sub utr3_exonic_length {
344 0 ▶ my ($self) = @_;
Subroutine utr3_exonic_length: not called CC=2 SCAR=17.9
Pod undocumented
345
346 0 my $exonic_length = 0;
347 0 foreach my $region ($self->all_utr3_exonic_regions) {
348 0 $exonic_length += $region->length
349 }
350
351 0 return $exonic_length;
352 }
353  
354 #######################################################################
355 ######################### Private methods ##########################
356 #######################################################################
357 sub _find_strand {
358 355 ▶ my ($self) = @_;
Subroutine _find_strand: called CC=3 SCAR=11.6
359
360 355 my $strand;
361 355 ▶ if (defined $self->transcripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->transcripts) 355 0 355
362 355 $strand = $self->transcripts->[0]->strand;
363 }
364
365 355 ▶ if (not defined $strand) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $strand) { } 0 355 355
366 0 die "No strand found for ".$self->name."\n";
367 }
368 else {
369 355 return $strand;
370 }
371 }
372  
373 sub _find_chromosome {
374 355 ▶ my ($self) = @_;
Subroutine _find_chromosome: called CC=3 SCAR=11.6
375
376 355 my $chromosome;
377 355 ▶ if (defined $self->transcripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->transcripts) 355 0 355
378 355 $chromosome = $self->transcripts->[0]->chromosome;
379 }
380
381 355 ▶ if (not defined $chromosome) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $chromosome) { } 0 355 355
382 0 die "No chromosome found for ".$self->name."\n";
383 }
384 else {
385 355 return $chromosome;
386 }
387 }
388  
389 sub _find_start {
390 193 ▶ my ($self) = @_;
Subroutine _find_start: called CC=6 SCAR=18.2
391
392 193 my $start;
393 193 ▶ if (defined $self->transcripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->transcripts) 193 0 193
394 193 foreach my $transcript (@{$self->transcripts}) {
395 374 ▶ if ((not defined $start) or ($start > $transcript->start)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $start or $start > $transcript->start) 194 180 374
Condition100%3/3
not defined $start or $start > $transcript->start
l!l&&r!l&&!r
1931180
MC/DC100%2/2
not defined $start or $start > $transcript->start
not defined $start $start > $transcript->start
Truth table100%3/3
not(A) or B
A= not defined $startB= $start > $transcript->start
ABresult
1X1
011
000
396 194 $start = $transcript->start;
397 }
398 }
399 }
400
401 193 ▶ if (not defined $start) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $start) { } 0 193 193
402 0 die "No start found for ".$self->name."\n";
403 }
404 else {
405 193 return $start;
406 }
407 }
408  
409 sub _find_stop {
410 193 ▶ my ($self) = @_;
Subroutine _find_stop: called CC=6 SCAR=18.2
411
412 193 my $stop;
413 193 ▶ if (defined $self->transcripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->transcripts) 193 0 193
414 193 foreach my $transcript (@{$self->transcripts}) {
415 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
416 235 $stop = $transcript->stop;
417 }
418 }
419 }
420
421 193 ▶ if (not defined $stop) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $stop) { } 0 193 193
422 0 die "No stop found for ".$self->name."\n";
423 }
424 else {
425 193 return $stop;
426 }
427 }
428  
429 sub _build_exonic_regions {
430 4 ▶ my ($self) = @_;
Subroutine _build_exonic_regions: called CC=3 SCAR=11.0
431
432 4 my @all_exons;
433 4 foreach my $transcript (@{$self->transcripts}) {
434 8 foreach my $exon (@{$transcript->exons}) {
435 16 push @all_exons, $exon;
436 }
437 }
438
439 4 return $self->_merge_exons(\@all_exons);
440 }
441  
442 sub _build_intronic_regions {
443 2 ▶ my ($self) = @_;
Subroutine _build_intronic_regions: called CC=3 SCAR=11.0
444
445 2 my @intronic_regions;
446 2 my @e_regions = sort {$a->start <=> $b->start} $self->all_exonic_regions;
447  
448 2 ▶ return [] if @e_regions < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @e_regions < 2 0 2 2
449  
450 2 ▶ for (my $i = 0; $i < @e_regions-1; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @e_regions - 1) 4 2 6
451 4 push @intronic_regions, GenOO::GenomicRegion->new(
452 strand => $self->strand,
453 chromosome => $self->chromosome,
454 start => $e_regions[$i]->stop + 1,
455 stop => $e_regions[$i+1]->start - 1,
456 );
457 }
458
459 2 return \@intronic_regions;
460 }
461  
462 sub _build_utr5_exonic_regions {
463 0 ▶ my ($self) = @_;
Subroutine _build_utr5_exonic_regions: not called CC=5 SCAR=34.0
464
465 0 my @all_exons;
466 0 foreach my $transcript (@{$self->transcripts}) {
467 0 ▶ next if !$transcript->is_coding;
Branch: 1 branch
BranchTrueFalseTotal
unless $transcript->is_coding 0 0 0
468 0 ▶ next if !defined $transcript->utr5;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $transcript->utr5 0 0 0
469 0 foreach my $exon (@{$transcript->utr5->exons}) {
470 0 push @all_exons, $exon;
471 }
472 }
473
474 0 return $self->_merge_exons(\@all_exons);
475 }
476  
477 sub _build_cds_exonic_regions {
478 0 ▶ my ($self) = @_;
Subroutine _build_cds_exonic_regions: not called CC=4 SCAR=30.0
479
480 0 my @all_exons;
481 0 foreach my $transcript (@{$self->transcripts}) {
482 0 ▶ next if !$transcript->is_coding;
Branch: 1 branch
BranchTrueFalseTotal
unless $transcript->is_coding 0 0 0
483 0 foreach my $exon (@{$transcript->cds->exons}) {
484 0 push @all_exons, $exon;
485 }
486 }
487
488 0 return $self->_merge_exons(\@all_exons);
489 }
490  
491 sub _build_utr3_exonic_regions {
492 0 ▶ my ($self) = @_;
Subroutine _build_utr3_exonic_regions: not called CC=5 SCAR=34.0
493
494 0 my @all_exons;
495 0 foreach my $transcript (@{$self->transcripts}) {
496 0 ▶ next if !$transcript->is_coding;
Branch: 1 branch
BranchTrueFalseTotal
unless $transcript->is_coding 0 0 0
497 0 ▶ next if !defined $transcript->utr3;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $transcript->utr3 0 0 0
498 0 foreach my $exon (@{$transcript->utr3->exons}) {
499 0 push @all_exons, $exon;
500 }
501 }
502
503 0 return $self->_merge_exons(\@all_exons);
504 }
505  
506 sub _merge_exons {
507 4 ▶ my ($self, $exons) = @_;
Subroutine _merge_exons: called CC=5 SCAR=16.1
508
509 4 my @sorted_exons = sort{$a->start <=> $b->start} @$exons;
510
511 4 my @exonic_regions;
512 4 foreach my $exon (@sorted_exons) {
513 16 my $merge_region = $exonic_regions[-1];
514 16 ▶ if (defined $merge_region and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $merge_region and $merge_region->overlaps_with_offset($exon, 1, 1)) { } 4 12 16
Condition100%3/3
defined $merge_region and $merge_region->overlaps_with_offset($exon, 1, 1)
!ll&&!rl&&r
484
MC/DC100%2/2
defined $merge_region and $merge_region->overlaps_with_offset($exon, 1, 1)
defined $merge_region $merge_region->overlaps_with_offset($exon, 1, 1)
Truth table100%3/3
A and B
A= defined $merge_regionB= $merge_region->overlaps_with_offset($exon, 1, 1)
ABresult
0X0
100
111
515 $merge_region->overlaps_with_offset($exon, 1, 1)) {
516  
517 4 ▶ $merge_region->stop($exon->stop) if $exon->stop > $merge_region->stop;
Branch: 1 branch
BranchTrueFalseTotal
if $exon->stop > $merge_region->stop 0 4 4
518 }
519 else {
520 12 push @exonic_regions, GenOO::GenomicRegion->new(
521 strand => $exon->strand,
522 chromosome => $exon->chromosome,
523 start => $exon->start,
524 stop => $exon->stop,
525 );
526 }
527 }
528
529 4 return \@exonic_regions;
530 }
531  
532 sub _reset {
533 350 ▶ my ($self) = @_;
Subroutine _reset: called CC=1 SCAR=0.0
534
535 350 $self->_clear_strand;
536 350 $self->_clear_chromosome;
537 350 $self->_clear_start;
538 350 $self->_clear_stop;
539 350 $self->_clear_exonic_regions;
540 350 $self->_clear_intronic_regions;
541 350 $self->_clear_utr5_exonic_regions;
542 350 $self->_clear_cds_exonic_regions;
543 350 $self->_clear_utr3_exonic_regions;
544 }
545  
546 1 __PACKAGE__->meta->make_immutable;
547  
548 1 1;
« GenOO/Module/Search/Binary.pm ↑ Summary GenOO/GeneCollection/Factory/FromTranscriptCollection.pm »