GenOO/Data/File/BED/Record.pm

filter: Statementstmt 81.2% 39 / 48 Branchbran 35.0% 7 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 2 totaltotal 67.5% 52 / 77 CC 11 SCAR 32.1
CC
11
Cov
68%
to_string
56.0
__ANON__
5.0
BEGIN
1.0
CRAP 24.8
« GenOO/GeneCollection/Factory/GTF.pm ↑ Summary GenOO/TranscriptCollection/Factory/GTF.pm »
1 # POD documentation - main docs before the code
2  
3 =head1 NAME
4  
5 GenOO::Data::File::BED::Record - Object representing a record of a bed file
6  
7 =head1 SYNOPSIS
8  
9 # Object representing a record of a bed file
10  
11 # To initialize
12 my $record = GenOO::Data::File::BED::Record->new({
13 rname => undef,
14 start => undef,
15 stop_1based => undef,
16 name => undef,
17 score => undef,
18 strand_symbol => undef,
19 thick_start => undef,
20 thick_stop_1based => undef,
21 rgb => undef,
22 block_count => undef,
23 block_sizes => undef,
24 block_starts => undef,
25 copy_number => undef,
26 });
27  
28  
29 =head1 DESCRIPTION
30  
31 This object represents a record of a bed file and offers methods for accessing the different attributes.
32 It implements several additional methods that transform original attributes in more manageable attributes.
33  
34 =head1 EXAMPLES
35  
36 # Return strand
37 my $strand = $record->strand; # -1
38 my $strand_symbol = $record->strand_symbol; # -
39
40 # Return stop position
41 my $stop = $record->stop; #10
42 my $stop_1based = $record->stop_1based; #11
43
44 # Return location
45 my $location = $record->location;
46  
47 =cut
48  
49 # Let the code begin...
50  
51 package GenOO::Data::File::BED::Record;
52 1 $GenOO::Data::File::BED::Record::VERSION = '1.4.9';
53 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 # Define the attributes
57 1 has 'rname' => (isa => 'Str', is => 'ro', required => 1);
58 1 has 'start' => (isa => 'Int', is => 'ro', required => 1);
59 1 has 'stop' => (isa => 'Int', is => 'ro', required => 1);
60 1 has 'name' => (isa => 'Str', is => 'ro', required => 1);
61 1 has 'score' => (isa => 'Num', is => 'ro', required => 1);
62 1 has 'strand' => (isa => 'Int', is => 'ro', required => 1);
63 1 has 'thick_start' => (isa => 'Int', is => 'ro');
64 1 has 'thick_stop_1based' => (isa => 'Int', is => 'ro');
65 1 has 'rgb' => (isa => 'Str', is => 'ro');
66 1 has 'block_count' => (isa => 'Int', is => 'ro');
67 has 'block_sizes' => (
68 traits => ['Array'],
69 is => 'ro',
70 isa => 'ArrayRef[Int]',
71 61 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
72 1 handles => {
73 all_block_sizes => 'elements',
74 add_block_size => 'push',
75 map_block_sizes => 'map',
76 filter_block_sizes => 'grep',
77 find_block_size => 'first',
78 get_block_size => 'get',
79 join_block_sizes => 'join',
80 count_block_sizes => 'count',
81 has_block_sizes => 'count',
82 has_no_block_sizes => 'is_empty',
83 sorted_block_sizes => 'sort',
84 },
85 );
86 has 'block_starts' => (
87 traits => ['Array'],
88 is => 'ro',
89 isa => 'ArrayRef[Int]',
90 61 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
91 1 handles => {
92 all_block_starts => 'elements',
93 add_block_start => 'push',
94 map_block_starts => 'map',
95 filter_block_starts => 'grep',
96 find_block_start => 'first',
97 get_block_start => 'get',
98 join_block_starts => 'join',
99 count_block_starts => 'count',
100 has_block_starts => 'count',
101 has_no_block_starts => 'is_empty',
102 sorted_block_starts => 'sort',
103 },
104 );
105 1 has 'extra' => (is => 'rw');
106 1 has 'copy_number' => (isa => 'Int', is => 'ro', default => 1, lazy => 1);
107  
108 # Consume roles
109 1 with 'GenOO::Region';
110  
111 # Before object creation edit the hash with the arguments to resolve 1 based and strand symbol
112 around BUILDARGS => sub {
113 94 ▶ my $orig = shift;
Subroutine __ANON__: called CC=5 SCAR=16.1
114 94 my $class = shift;
115
116 94 my $argv_hash_ref = $class->$orig(@_);
117
118 94 ▶ if (exists $argv_hash_ref->{stop_1based}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $argv_hash_ref->{"stop_1based"}) 78 16 94
119 78 $argv_hash_ref->{stop} = $argv_hash_ref->{stop_1based} - 1;
120 }
121 94 ▶ if (exists $argv_hash_ref->{strand_symbol}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $argv_hash_ref->{"strand_symbol"}) 78 16 94
122 78 ▶ if ($argv_hash_ref->{strand_symbol} eq '+') {
Branch: 2 branches
BranchTrueFalseTotal
if ($argv_hash_ref->{'strand_symbol'} eq '+') { } 58 20 78
elsif ($argv_hash_ref->{'strand_symbol'} eq '-') { } 20 0 20
123 58 $argv_hash_ref->{strand} = 1;
124 }
125 elsif ($argv_hash_ref->{strand_symbol} eq '-') {
126 20 $argv_hash_ref->{strand} = -1;
127 }
128 }
129
130 94 return $argv_hash_ref;
131 1 };
132  
133 #######################################################################
134 ######################## Interface Methods ########################
135 #######################################################################
136 sub stop_1based {
137 1 ▶ my ($self) = @_;
Subroutine stop_1based: called CC=1 SCAR=0.0
Pod undocumented
138 1 return $self->stop + 1;
139 }
140  
141 sub to_string {
142 0 ▶ my ($self) = @_;
Subroutine to_string: not called CC=7 SCAR=40.3
Pod undocumented
143
144 0 my @fields = (
145 $self->rname,
146 $self->start,
147 $self->stop_1based,
148 $self->name,
149 $self->score,
150 $self->strand_symbol);
151
152 0 ▶ push @fields, $self->thick_start if defined $self->thick_start;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->thick_start 0 0 0
153 0 ▶ push @fields, $self->thick_stop_1based if defined $self->thick_stop_1based;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->thick_stop_1based 0 0 0
154 0 ▶ push @fields, $self->rgb if defined $self->rgb;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->rgb 0 0 0
155 0 ▶ push @fields, $self->block_count if defined $self->block_count;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->block_count 0 0 0
156 0 ▶ push @fields, $self->join_block_sizes(",") if $self->has_block_sizes;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_block_sizes 0 0 0
157 0 ▶ push @fields, $self->join_block_starts(",") if $self->has_block_starts;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_block_starts 0 0 0
158
159 0 return join("\t", @fields);
160 }
161  
162 #######################################################################
163 ############################ Finalize #############################
164 #######################################################################
165 1 __PACKAGE__->meta->make_immutable;
166  
167 1 1;
« GenOO/GeneCollection/Factory/GTF.pm ↑ Summary GenOO/TranscriptCollection/Factory/GTF.pm »