GenOO/GenomicRegion.pm

filter: Statementstmt 100% 40 / 40 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 94.8% 55 / 58 CC 4 SCAR 4.8
CC
4
Cov
98%
_sanitize_strand
3.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.6
« GenOO/RegionCollection/Factory/BED.pm ↑ Summary GenOO/RegionCollection/Factory/RegionArray.pm »
1 # POD documentation - main docs before the code
2  
3 =head1 NAME
4  
5 GenOO::GenomicRegion - Object that corresponds to a region on a genome
6  
7 =head1 SYNOPSIS
8
9 # This object represents a genomic region (location on the genome)
10 # It extends the L<GenOO::Region> object
11
12 # Instantiate
13 my $genomic_region = GenOO::GenomicRegion->new(
14 name => undef,
15 species => undef,
16 strand => undef, #required
17 chromosome => undef, #required
18 start => undef, #required
19 stop => undef, #required
20 copy_number => undef, #defaults to 1
21 sequence => undef,
22 );
23  
24 =head1 DESCRIPTION
25  
26 A genomic region object is an area on a reference genome. It has a
27 specific start and stop position and specific strand and chromosome.
28 The main difference from the the L<GenOO::Region> role is that it has the
29 "chromosome" attribute instead of the generic "rname". The copy number
30 attribute is useful when counting aligned reads so that the number of
31 reads in this specific location can be collapsed. It defaults to 1.
32 See L<GenOO::Region> and for more available methods
33  
34 =head1 EXAMPLES
35
36 my $genomic_region = GenOO::GenomicRegion->new(
37 name => 'test_object_0',
38 species => 'human',
39 strand => '+',
40 chromosome => 'chr1',
41 start => 3,
42 stop => 10,
43 copy_number => 7,
44 sequence => 'AGCTAGCU'
45 );
46 # Get the genomic location information
47 $genomic_region->start; # 3
48 $genomic_region->stop; # 10
49 $genomic_region->strand; # 1
50 $genomic_region->chromosome; # chr1
51 $genomic_region->rname; # chr1 - this is always the same as chromosome
52
53 # Get the head (5p) position on the reference sequence
54 $genomic_region->head_position; # 3 - this method comes from L<GenOO::Region>
55  
56 =cut
57  
58 # Let the code begin...
59  
60 package GenOO::GenomicRegion;
61 1 $GenOO::GenomicRegion::VERSION = '1.5.0';
62  
63 #######################################################################
64 ####################### Load External modules #####################
65 #######################################################################
66 1 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 1 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 1 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
71  
72 3484 ▶subtype 'RegionStrand', as 'Int', where {($_ == 1) or ($_ == -1)};
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_ == 1 or $_ == -1 1799 1685 3484
73  
74 1190 ▶coerce 'RegionStrand', from 'Str', via { _sanitize_strand($_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
75  
76  
77 #######################################################################
78 ####################### Interface attributes ######################
79 #######################################################################
80 1 has 'name' => (
81 isa => 'Str',
82 is => 'rw'
83 );
84  
85 1 has 'species' => (
86 isa => 'Str',
87 is => 'rw'
88 );
89  
90 1 has 'strand' => (
91 isa => 'RegionStrand',
92 is => 'rw',
93 required => 1,
94 coerce => 1
95 );
96  
97 1 has 'chromosome' => (
98 isa => 'Str',
99 is => 'rw',
100 required => 1
101 );
102  
103 1 has 'start' => (
104 isa => 'Int',
105 is => 'rw',
106 required => 1
107 );
108  
109 1 has 'stop' => (
110 isa => 'Int',
111 is => 'rw',
112 required => 1
113 );
114  
115 1 has 'copy_number' => (
116 isa => 'Int',
117 is => 'rw',
118 default => 1,
119 lazy => 1
120 );
121  
122 1 has 'sequence' => (
123 isa => 'Str',
124 is => 'rw'
125 );
126  
127 1 has 'extra' => (
128 is => 'rw'
129 );
130  
131  
132 #######################################################################
133 ########################## Consumed Roles #########################
134 #######################################################################
135 1 with 'GenOO::Region';
136  
137  
138 #######################################################################
139 ######################## Interface Methods ########################
140 #######################################################################
141 sub rname {
142 1849 ▶ my ($self) = @_;
Subroutine rname: called CC=1 SCAR=0.0
Pod undocumented
143
144 1849 return $self->chromosome;
145 }
146  
147 sub id {
148 4 ▶ my ($self) = @_;
Subroutine id: called CC=1 SCAR=0.0
Pod undocumented
149
150 4 return $self->location;
151 }
152  
153  
154 #######################################################################
155 ######################### Private methods ##########################
156 #######################################################################
157 sub _sanitize_strand {
158 1190 ▶ my ($value) = @_;
Subroutine _sanitize_strand: called CC=3 SCAR=11.0
159
160 1190 ▶ if ($value eq '+') {
Branch: 2 branches
BranchTrueFalseTotal
if ($value eq '+') { } 595 595 1190
elsif ($value eq '-') { } 595 0 595
161 595 return 1;
162 }
163 elsif ($value eq '-') {
164 595 return -1;
165 }
166 }
167  
168  
169 #######################################################################
170 ############################ Finalize #############################
171 #######################################################################
172 1 __PACKAGE__->meta->make_immutable;
173 1 1;
« GenOO/RegionCollection/Factory/BED.pm ↑ Summary GenOO/RegionCollection/Factory/RegionArray.pm »