lib/Bio/ToolBox/Data/core.pm

filter: Statementstmt 55.3% 469 / 847 Branchbran 45.1% 249 / 552 Conditioncond 48.7% 112 / 230 MC/DCmcdc 14.4% 20 / 138 Subroutinesub 86.8% 53 / 61 Podpod 100% 50 / 50 totaltotal 50.7% 953 / 1878 CC 385 SCAR 83.2
CC
385
Cov
51%
verify
9779.1
rewrite_vcf_headers
56.0
delete_metadata
56.0
CRAP 4116.5
« script/bam2wig.pl ↑ Summary lib/Bio/ToolBox/Data/file.pm »
1 package Bio::ToolBox::Data::core;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Carp qw(carp cluck croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use base 'Bio::ToolBox::Data::file';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Bio::ToolBox::db_helper qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
8 open_db_connection
9 verify_or_request_feature_types
10 use_bam_adapter
11 use_big_adapter
12 4 );
13 4 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 our $VERSION = '2.03';
16  
17 #### Initialization and verification ###############################################
18  
19 80 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
20 80 my $class = shift;
21  
22 # in case someone calls this from an established object
23 80 ▶ if ( ref $class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 1 79 80
24 1 $class = ref $class;
25 }
26  
27 # Initialize the hash structure
28 80 my %data = (
29 'program' => undef,
30 'feature' => undef,
31 'feature_type' => undef,
32 'db' => undef,
33 'format' => q(),
34 'gff' => 0,
35 'bed' => 0,
36 'ucsc' => 0,
37 'vcf' => 0,
38 'number_columns' => 0,
39 'last_row' => 0,
40 'headers' => 1,
41 'filename' => q(),
42 'basename' => q(),
43 'extension' => q(),
44 'path' => q(),
45 'comments' => [],
46 'data_table' => [ ['BLANK'] ],
47 'header_line_count' => 0,
48 'zerostart' => 0,
49 );
50  
51 # Finished
52 80 return bless \%data, $class;
53 }
54  
55 72 ▶sub verify {
Subroutine verify: called CC=187 SCAR=91.9
Pod documented
56  
57 # this function does not rely on any self functions for two reasons
58 # this is a low level integrity checker
59 # this is very old code from before the days of an OO API of Bio::ToolBox
60 # although a lot of things have been added and changed since then....
61 72 my $self = shift;
62 72 ▶ my $silence = shift || 0; # default is to yell
Condition100%2/2
shift() || 0
l!l
5913
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
63  
64 # check for data table
65 72 ▶ unless ( defined $self->{'data_table'}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"data_table"} and ref $self->{"data_table"} eq "ARRAY") 0 72 72
Condition33%1/3
defined $self->{"data_table"} and ref $self->{"data_table"} eq "ARRAY"
!ll&&!rl&&r
0072
MC/DC0%0/2
defined $self->{"data_table"} and ref $self->{"data_table"} eq "ARRAY"
defined $self->{"data_table"} ref $self->{"data_table"} eq "ARRAY"
Truth table33%1/3
A and B
A= defined $self->{"data_table"}B= ref $self->{"data_table"} eq "ARRAY"
ABresult
0X0
100
111
66 and ref( $self->{'data_table'} ) eq 'ARRAY' )
67 {
68 0 ▶ carp sprintf "\n DATA INTEGRITY ERROR: No data table in %s object!", ref $self
Branch: 1 branch
BranchTrueFalseTotal
unless $silence 0 0 0
69 unless $silence;
70 0 return;
71 }
72  
73 # check for last row index
74 72 ▶ if ( defined $self->{'last_row'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'last_row'}) { } 72 0 72
75 72 my $number = scalar( @{ $self->{'data_table'} } ) - 1;
76 72 ▶ if ( $self->{'last_row'} != $number ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"last_row"} != $number) 0 72 72
77 0 $self->{'last_row'} = $number;
78 }
79 }
80 else {
81 # define it for them
82 0 $self->{'last_row'} = scalar( @{ $self->{'data_table'} } ) - 1;
83 }
84  
85 # check for consistent number of columns
86 72 ▶ if ( defined $self->{'number_columns'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'number_columns'}) { } 72 0 72
87 72 my $number = $self->{'number_columns'} + 1; # account for base 1 column indexing
88 72 my @problems;
89 72 my $too_low = 0;
90 72 my $too_high = 0;
91 72 for my $row ( 0 .. $self->{'last_row'} ) {
92 999 my $count = scalar @{ $self->{'data_table'}->[$row] };
93 999 ▶ if ( $count != $number ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count != $number) 0 999 999
94 0 push @problems, $row;
95 0 ▶ $too_low++ if $count < $number;
Branch: 1 branch
BranchTrueFalseTotal
if $count < $number 0 0 0
96 0 ▶ $too_high++ if $count > $number;
Branch: 1 branch
BranchTrueFalseTotal
if $count > $number 0 0 0
97  
98 # add null values
99 0 ▶ if ( $count < $number ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count < $number) 0 0 0
100 0 for ( $count .. $number ) {
101 0 push @{ $self->{'data_table'}->[$row] }, '.';
102 }
103 }
104 }
105 }
106  
107 # we found errors
108 72 ▶ if (@problems) {
Branch: 1 branch
BranchTrueFalseTotal
if (@problems) 0 72 72
109  
110 0 ▶ unless ($silence) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($silence) 0 0 0
111  
112 # collapse problem list into compact string
113 # from http://www.perlmonks.org/?node_id=87538
114 0 my $problem = join( ',', @problems );
115 0 $problem =~ s/(?<!\d) (\d+) (?: ,((??{$++1})) (?!\d) )+/$1-$+/xg;
116  
117 0 ▶ if ($too_low) {
Branch: 1 branch
BranchTrueFalseTotal
if ($too_low) 0 0 0
118 0 print "
119 COLUMN INCONSISTENCY ERRORS: $too_low rows had fewer than expected columns!
120 padded rows $problem with null values\n";
121 }
122 0 ▶ if ($too_high) {
Branch: 1 branch
BranchTrueFalseTotal
if ($too_high) 0 0 0
123 0 print "
124 COLUMN INCONSISTENCY ERRORS: $too_high rows had more columns than
125 expected!\n Problem rows: $problem\n";
126 }
127 }
128 }
129 }
130 else {
131 # this wasn't set???? then set it
132 $self->{'number_columns'} =
133 0 scalar @{ $self->{'data_table'}->[0] } - 1;
134 }
135  
136 # check metadata and table names
137 72 my $mdcheck = 0;
138 72 for my $i ( 1 .. $self->{'number_columns'} ) {
139 725 ▶ if ( not exists $self->{$i} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{$i}) 0 725 725
140 0 ▶ unless ($silence) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($silence) 0 0 0
141 0 print " METADATA ERROR: No metadata hash for column $i!";
142 }
143 0 $mdcheck++;
144 0 next; # the other tests will fail anyway
145 }
146 725 ▶ if ( $self->{$i}{'name'} ne $self->{'data_table'}->[0][$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{$i}{"name"} ne $self->{"data_table"}[0][$i]) 0 725 725
147 0 ▶ unless ($silence) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($silence) 0 0 0
148 printf "
149 TABLE/METADATA MISMATCH ERROR: Column header names don't match metadata
150 name values for index $i! compare '%s' with '%s'\n",
151 0 $self->{'data_table'}->[0][$i], $self->{$i}{'name'};
152 }
153 0 $mdcheck++;
154 }
155 725 ▶ if ( $self->{$i}{'index'} != $i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{$i}{"index"} != $i) 0 725 725
156 0 ▶ unless ($silence) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($silence) 0 0 0
157 printf "
158 METADATA INDEX ERROR: index $i metadata doesn't match its index value %s\n",
159 0 $self->{$i}{'index'};
160 0 $mdcheck++;
161 }
162 }
163 }
164 72 ▶ return if $mdcheck;
Branch: 1 branch
BranchTrueFalseTotal
if $mdcheck 0 72 72
165  
166 ### Defined file format structure integrity
167 72 my $error;
168  
169 # check for proper gff structure
170 72 ▶ if ( $self->{'gff'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"gff"}) 13 59 72
171  
172 # if any of these checks fail, we will reset the gff version to
173 # the default of 0, or no gff
174 13 my $gff_check = 1; # start with assumption it is true
175  
176 # check number of columns
177 13 ▶ if ( $self->{'number_columns'} != 9 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"number_columns"} != 9) 0 13 13
178 0 $gff_check = 0;
179 0 $error .= ' Number of columns not 9.';
180 }
181  
182 # check column indices
183 13 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{1} and not $self->{1}{"name"} =~ /^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi) 0 13 13
Condition33%1/3
exists $self->{1} and not $self->{1}{"name"} =~ /^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi
!ll&&!rl&&r
0130
MC/DC0%0/2
exists $self->{1} and not $self->{1}{"name"} =~ /^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi
exists $self->{1} not $self->{1}{"name"} =~ /^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi
Truth table33%1/3
A and not(B)
A= exists $self->{1}B= not $self->{1}{"name"} =~ /^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi
ABresult
0X0
100
111
184 # column 1 should look like chromosome
185 exists $self->{1}
186 and $self->{1}{'name'} !~
187 m/^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi
188 )
189 {
190 0 $gff_check = 0;
191 0 $error .= ' Column 1 name not chromosome-like.';
192 }
193 13 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{4} and not $self->{4}{"name"} =~ /start | pos | position/xi) 0 13 13
Condition33%1/3
exists $self->{4} and not $self->{4}{"name"} =~ /start | pos | position/xi
!ll&&!rl&&r
0130
MC/DC0%0/2
exists $self->{4} and not $self->{4}{"name"} =~ /start | pos | position/xi
exists $self->{4} not $self->{4}{"name"} =~ /start | pos | position/xi
Truth table33%1/3
A and not(B)
A= exists $self->{4}B= not $self->{4}{"name"} =~ /start | pos | position/xi
ABresult
0X0
100
111
194 # column 4 should look like start
195 exists $self->{4} and $self->{4}{'name'} !~ m/start | pos | position/xi
196 )
197 {
198 0 $gff_check = 0;
199 0 $error .= ' Column 4 name not start-like.';
200 }
201 13 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{5} and not $self->{5}{"name"} =~ /stop | end | pos | position/xi) 0 13 13
Condition33%1/3
exists $self->{5} and not $self->{5}{"name"} =~ /stop | end | pos | position/xi
!ll&&!rl&&r
0130
MC/DC0%0/2
exists $self->{5} and not $self->{5}{"name"} =~ /stop | end | pos | position/xi
exists $self->{5} not $self->{5}{"name"} =~ /stop | end | pos | position/xi
Truth table33%1/3
A and not(B)
A= exists $self->{5}B= not $self->{5}{"name"} =~ /stop | end | pos | position/xi
ABresult
0X0
100
111
202 # column 5 should look like end
203 exists $self->{5}
204 and $self->{5}{'name'} !~ m/stop | end | pos | position/xi
205 )
206 {
207 0 $gff_check = 0;
208 0 $error .= ' Column 5 name not stop-like.';
209 }
210 13 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{7} and not $self->{7}{"name"} =~ /strand/i) 0 13 13
Condition33%1/3
exists $self->{7} and not $self->{7}{"name"} =~ /strand/i
!ll&&!rl&&r
0130
MC/DC0%0/2
exists $self->{7} and not $self->{7}{"name"} =~ /strand/i
exists $self->{7} not $self->{7}{"name"} =~ /strand/i
Truth table33%1/3
A and not(B)
A= exists $self->{7}B= not $self->{7}{"name"} =~ /strand/i
ABresult
0X0
100
111
211 # column 7 should look like strand
212 exists $self->{7} and $self->{7}{'name'} !~ m/strand/i
213 )
214 {
215 0 $gff_check = 0;
216 0 $error .= ' Column 7 name not strand-like.';
217 }
218  
219 # check column data
220 13 ▶ unless ( $self->_column_is_integers( 4, 5 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_integers(4, 5)) 0 13 13
221 0 $gff_check = 0;
222 0 $error .= ' Columns 4 and 5 not integers.';
223 }
224 13 ▶ unless ( $self->_column_is_numeric(6) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_numeric(6)) 0 13 13
225 0 $gff_check = 0;
226 0 $error .= ' Column 6 not numeric.';
227 }
228 13 ▶ unless ( $self->_column_is_stranded(7) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_stranded(7)) 0 13 13
229 0 $gff_check = 0;
230 0 $error .= ' Column 7 not strand values.';
231 }
232  
233 # update metadata as necessary
234 13 ▶ if ( $gff_check == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gff_check == 1) { } 13 0 13
235 13 $self->{'bed'} = 0;
236 13 $self->{'ucsc'} = 0;
237 13 $self->{'vcf'} = 0;
238 13 $self->{'headers'} = 0;
239 13 ▶ if ( $self->{'format'} and $self->{'format'} !~ m/g[tvf]f/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"format"} and not $self->{"format"} =~ /g[tvf]f/i) 0 13 13
Condition33%1/3
$self->{"format"} and not $self->{"format"} =~ /g[tvf]f/i
!ll&&!rl&&r
0130
MC/DC0%0/2
$self->{"format"} and not $self->{"format"} =~ /g[tvf]f/i
$self->{"format"} not $self->{"format"} =~ /g[tvf]f/i
Truth table33%1/3
A and not(B)
A= $self->{"format"}B= not $self->{"format"} =~ /g[tvf]f/i
ABresult
0X0
100
111
240 0 $self->{'format'} = 'gff'; # generic
241 }
242 13 ▶ if ( $self->{'extension'} and $self->{'extension'} !~ m/\.g[tvf]f/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extension"} and not $self->{"extension"} =~ /\.g[tvf]f/i) 0 13 13
Condition33%1/3
$self->{"extension"} and not $self->{"extension"} =~ /\.g[tvf]f/i
!ll&&!rl&&r
0130
MC/DC0%0/2
$self->{"extension"} and not $self->{"extension"} =~ /\.g[tvf]f/i
$self->{"extension"} not $self->{"extension"} =~ /\.g[tvf]f/i
Truth table33%1/3
A and not(B)
A= $self->{"extension"}B= not $self->{"extension"} =~ /\.g[tvf]f/i
ABresult
0X0
100
111
243 0 $self->{'extension'} = '.gff'; # generic????
244 }
245 }
246 else {
247 0 $self->{'gff'} = 0;
248 0 $self->{'headers'} = 1;
249 0 $self->{'extension'} = '.txt';
250 0 $self->{'format'} = q();
251  
252 # remove the AUTO key from the metadata
253 0 for my $i ( 1 .. $self->{'number_columns'} ) {
254 0 ▶ if ( exists $self->{$i}{'AUTO'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$i}{"AUTO"}) 0 0 0
255 0 delete $self->{$i}{'AUTO'};
256 }
257 }
258 0 ▶ print "\n GFF FILE FORMAT ERROR: $error\n" unless $silence;
Branch: 1 branch
BranchTrueFalseTotal
unless $silence 0 0 0
259 }
260 }
261  
262 # check for proper BED structure
263 72 ▶ if ( $self->{'bed'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bed"}) 31 41 72
264  
265 # if any of these checks fail, we will reset the bed flag to 0
266 # to make it not a bed file format
267 31 my $bed_check = 1; # start with assumption it is correct
268  
269 # check number of columns
270 31 ▶ if ( $self->{'number_columns'} < 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"number_columns"} < 3) 0 31 31
271 0 $bed_check = 0;
272 0 $error .= ' Number of columns not at least 3.';
273 }
274  
275 # check column index names
276 31 ▶ if ( exists $self->{1}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{1} and not $self->{1}{"name"} =~ /^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi) 0 31 31
Condition33%1/3
exists $self->{1} and not $self->{1}{"name"} =~ /^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi
!ll&&!rl&&r
0310
MC/DC0%0/2
exists $self->{1} and not $self->{1}{"name"} =~ /^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi
exists $self->{1} not $self->{1}{"name"} =~ /^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi
Truth table33%1/3
A and not(B)
A= exists $self->{1}B= not $self->{1}{"name"} =~ /^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi
ABresult
0X0
100
111
277 and $self->{1}{'name'} !~
278 m/^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi )
279 {
280 0 $bed_check = 0;
281 0 $error .= ' Column 1 name not chromosome-like.';
282 }
283 31 ▶ if ( exists $self->{2}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{2} and not $self->{2}{"name"} =~ /start | pos | position/xi) 0 31 31
Condition33%1/3
exists $self->{2} and not $self->{2}{"name"} =~ /start | pos | position/xi
!ll&&!rl&&r
0310
MC/DC0%0/2
exists $self->{2} and not $self->{2}{"name"} =~ /start | pos | position/xi
exists $self->{2} not $self->{2}{"name"} =~ /start | pos | position/xi
Truth table33%1/3
A and not(B)
A= exists $self->{2}B= not $self->{2}{"name"} =~ /start | pos | position/xi
ABresult
0X0
100
111
284 and $self->{2}{'name'} !~ m/start | pos | position/xi )
285 {
286 0 $bed_check = 0;
287 0 $error .= ' Column 2 name not start-like.';
288 }
289 31 ▶ if ( exists $self->{3}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{3} and not $self->{3}{"name"} =~ /stop | end | pos | position/xi) 0 31 31
Condition33%1/3
exists $self->{3} and not $self->{3}{"name"} =~ /stop | end | pos | position/xi
!ll&&!rl&&r
0310
MC/DC0%0/2
exists $self->{3} and not $self->{3}{"name"} =~ /stop | end | pos | position/xi
exists $self->{3} not $self->{3}{"name"} =~ /stop | end | pos | position/xi
Truth table33%1/3
A and not(B)
A= exists $self->{3}B= not $self->{3}{"name"} =~ /stop | end | pos | position/xi
ABresult
0X0
100
111
290 and $self->{3}{'name'} !~ m/stop | end | pos | position/xi )
291 {
292 0 $bed_check = 0;
293 0 $error .= ' Column 3 name not stop-like.';
294 }
295 31 ▶ if ( exists $self->{6}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{6} and not $self->{6}{"name"} =~ /strand/i) 0 31 31
Condition66%2/3
exists $self->{6} and not $self->{6}{"name"} =~ /strand/i
!ll&&!rl&&r
3280
MC/DC0%0/2
exists $self->{6} and not $self->{6}{"name"} =~ /strand/i
exists $self->{6} not $self->{6}{"name"} =~ /strand/i
Truth table66%2/3
A and not(B)
A= exists $self->{6}B= not $self->{6}{"name"} =~ /strand/i
ABresult
0X0
100
111
296 and $self->{6}{'name'} !~ m/strand/i )
297 {
298 0 $bed_check = 0;
299 0 $error .= ' Column 6 name not strand-like.';
300 }
301 31 ▶ if ( exists $self->{7}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{7} and not $self->{"format"} =~ /narrow | broad/xi and not $self->{7}{"name"} =~ /start | thick | cds/xi) 0 31 31
Condition83%5/6
exists $self->{7} and not $self->{"format"} =~ /narrow | broad/xi and not $self->{7}{"name"} =~ /start | thick | cds/xi
!ll&&!rl&&r
18130
exists $self->{7} and not $self->{"format"} =~ /narrow | broad/xi
!ll&&!rl&&r
12613
MC/DC0%0/3
exists $self->{7} and not $self->{"format"} =~ /narrow | broad/xi and not $self->{7}{"name"} =~ /start | thick | cds/xi
exists $self->{7} not $self->{"format"} =~ /narrow | broad/xi not $self->{7}{"name"} =~ /start | thick | cds/xi
Truth table75%3/4
A and not(B) and not(C)
A= exists $self->{7}B= not $self->{"format"} =~ /narrow | broad/xiC= not $self->{7}{"name"} =~ /start | thick | cds/xi
ABCresult
0XX0
10X0
1100
1111
302 and $self->{'format'} !~ /narrow | broad/xi
303 and $self->{7}{'name'} !~ m/start | thick | cds/xi )
304 {
305 0 $bed_check = 0;
306 0 $error .= ' Column 7 name not thickStart-like.';
307 }
308 31 ▶ if ( exists $self->{8}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{8} and not $self->{"format"} =~ /narrow | broad/xi and not $self->{8}{"name"} =~ /end | stop | thick | cds/xi) 0 31 31
Condition83%5/6
exists $self->{8} and not $self->{"format"} =~ /narrow | broad/xi and not $self->{8}{"name"} =~ /end | stop | thick | cds/xi
!ll&&!rl&&r
18130
exists $self->{8} and not $self->{"format"} =~ /narrow | broad/xi
!ll&&!rl&&r
12613
MC/DC0%0/3
exists $self->{8} and not $self->{"format"} =~ /narrow | broad/xi and not $self->{8}{"name"} =~ /end | stop | thick | cds/xi
exists $self->{8} not $self->{"format"} =~ /narrow | broad/xi not $self->{8}{"name"} =~ /end | stop | thick | cds/xi
Truth table75%3/4
A and not(B) and not(C)
A= exists $self->{8}B= not $self->{"format"} =~ /narrow | broad/xiC= not $self->{8}{"name"} =~ /end | stop | thick | cds/xi
ABCresult
0XX0
10X0
1100
1111
309 and $self->{'format'} !~ /narrow | broad/xi
310 and $self->{8}{'name'} !~ m/end | stop | thick | cds/xi )
311 {
312 0 $bed_check = 0;
313 0 $error .= ' Column 8 name not thickEnd-like.';
314 }
315 31 ▶ if ( exists $self->{9}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{9} and not $self->{"format"} =~ /narrow | broad/xi and not $self->{9}{"name"} =~ /item | rgb | color/xi) 0 31 31
Condition83%5/6
exists $self->{9} and not $self->{"format"} =~ /narrow | broad/xi and not $self->{9}{"name"} =~ /item | rgb | color/xi
!ll&&!rl&&r
18130
exists $self->{9} and not $self->{"format"} =~ /narrow | broad/xi
!ll&&!rl&&r
12613
MC/DC0%0/3
exists $self->{9} and not $self->{"format"} =~ /narrow | broad/xi and not $self->{9}{"name"} =~ /item | rgb | color/xi
exists $self->{9} not $self->{"format"} =~ /narrow | broad/xi not $self->{9}{"name"} =~ /item | rgb | color/xi
Truth table75%3/4
A and not(B) and not(C)
A= exists $self->{9}B= not $self->{"format"} =~ /narrow | broad/xiC= not $self->{9}{"name"} =~ /item | rgb | color/xi
ABCresult
0XX0
10X0
1100
1111
316 and $self->{'format'} !~ /narrow | broad/xi
317 and $self->{9}{'name'} !~ m/item | rgb | color/xi )
318 {
319 0 $bed_check = 0;
320 0 $error .= ' Column 9 name not itemRGB-like.';
321 }
322 31 ▶ if ( exists $self->{10}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{10} and not $self->{"format"} =~ /narrow | broad/xi and not $self->{10}{"name"} =~ /count | number | block | exon/xi) 0 31 31
Condition83%5/6
exists $self->{10} and not $self->{"format"} =~ /narrow | broad/xi and not $self->{10}{"name"} =~ /count | number | block | exon/xi
!ll&&!rl&&r
18130
exists $self->{10} and not $self->{"format"} =~ /narrow | broad/xi
!ll&&!rl&&r
12613
MC/DC0%0/3
exists $self->{10} and not $self->{"format"} =~ /narrow | broad/xi and not $self->{10}{"name"} =~ /count | number | block | exon/xi
exists $self->{10} not $self->{"format"} =~ /narrow | broad/xi not $self->{10}{"name"} =~ /count | number | block | exon/xi
Truth table75%3/4
A and not(B) and not(C)
A= exists $self->{10}B= not $self->{"format"} =~ /narrow | broad/xiC= not $self->{10}{"name"} =~ /count | number | block | exon/xi
ABCresult
0XX0
10X0
1100
1111
323 and $self->{'format'} !~ /narrow | broad/xi
324 and $self->{10}{'name'} !~ m/count | number | block | exon/xi )
325 {
326 0 $bed_check = 0;
327 0 $error .= ' Column 10 name not blockCount-like.';
328 }
329 31 ▶ if ( exists $self->{11}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{11} and not $self->{11}{"name"} =~ /size | length | block | exon/xi) 0 31 31
Condition66%2/3
exists $self->{11} and not $self->{11}{"name"} =~ /size | length | block | exon/xi
!ll&&!rl&&r
18130
MC/DC0%0/2
exists $self->{11} and not $self->{11}{"name"} =~ /size | length | block | exon/xi
exists $self->{11} not $self->{11}{"name"} =~ /size | length | block | exon/xi
Truth table66%2/3
A and not(B)
A= exists $self->{11}B= not $self->{11}{"name"} =~ /size | length | block | exon/xi
ABresult
0X0
100
111
330 and $self->{11}{'name'} !~ m/size | length | block | exon/xi )
331 {
332 0 $bed_check = 0;
333 0 $error .= ' Column 11 name not blockSizes-like.';
334 }
335 31 ▶ if ( exists $self->{12}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{12} and not $self->{12}{"name"} =~ /start | block | exon/xi) 0 31 31
Condition66%2/3
exists $self->{12} and not $self->{12}{"name"} =~ /start | block | exon/xi
!ll&&!rl&&r
18130
MC/DC0%0/2
exists $self->{12} and not $self->{12}{"name"} =~ /start | block | exon/xi
exists $self->{12} not $self->{12}{"name"} =~ /start | block | exon/xi
Truth table66%2/3
A and not(B)
A= exists $self->{12}B= not $self->{12}{"name"} =~ /start | block | exon/xi
ABresult
0X0
100
111
336 and $self->{12}{'name'} !~ m/start | block | exon/xi )
337 {
338 0 $bed_check = 0;
339 0 $error .= ' Column 12 name not blockStarts-like.';
340 }
341  
342 # check column data
343 31 ▶ unless ( $self->_column_is_integers( 2, 3 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_integers(2, 3)) 0 31 31
344 0 $bed_check = 0;
345 0 $error .= ' Columns 2 and 3 not integers.';
346 }
347 31 ▶ if ( $self->{'number_columns'} >= 5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"number_columns"} >= 5) 28 3 31
348  
349 # only check if it is actually present, since could be optional
350 28 ▶ unless ( $self->_column_is_numeric(5) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_numeric(5)) 0 28 28
351 0 $bed_check = 0;
352 0 $error .= ' Column 5 not numeric.';
353 }
354 }
355 31 ▶ if ( $self->{'number_columns'} >= 6 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"number_columns"} >= 6) 28 3 31
356  
357 # only check if it is actually present, since could be optional
358 28 ▶ unless ( $self->_column_is_stranded(6) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_stranded(6)) 0 28 28
359 0 $bed_check = 0;
360 0 $error .= ' Column 6 not strand values.';
361 }
362 }
363 31 ▶ if ( $self->{'format'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"format"} and $self->{"format"} =~ /narrow | broad/xi) 6 25 31
Condition100%3/3
$self->{"format"} and $self->{"format"} =~ /narrow | broad/xi
!ll&&!rl&&r
2236
MC/DC100%2/2
$self->{"format"} and $self->{"format"} =~ /narrow | broad/xi
$self->{"format"} $self->{"format"} =~ /narrow | broad/xi
Truth table100%3/3
A and B
A= $self->{"format"}B= $self->{"format"} =~ /narrow | broad/xi
ABresult
0X0
100
111
364 and $self->{'format'} =~ /narrow | broad/xi )
365 {
366 6 ▶ unless ( $self->_column_is_numeric( 7, 8, 9 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_numeric(7, 8, 9)) 0 6 6
367 0 $bed_check = 0;
368 0 $error .= ' Columns 7,8,9 not numeric.';
369 }
370 }
371 31 ▶ if ( $self->{'format'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"format"} and $self->{"format"} =~ /narrow/i) 6 25 31
Condition100%3/3
$self->{"format"} and $self->{"format"} =~ /narrow/i
!ll&&!rl&&r
2236
MC/DC100%2/2
$self->{"format"} and $self->{"format"} =~ /narrow/i
$self->{"format"} $self->{"format"} =~ /narrow/i
Truth table100%3/3
A and B
A= $self->{"format"}B= $self->{"format"} =~ /narrow/i
ABresult
0X0
100
111
372 and $self->{'format'} =~ /narrow/i )
373 {
374 6 ▶ unless ( $self->_column_is_integers(10) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_integers(10)) 0 6 6
375 0 $bed_check = 0;
376 0 $error .= ' Column 10 is not integers.';
377 }
378 }
379 31 ▶ if ( $self->{'number_columns'} == 12 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"number_columns"} == 12) 7 24 31
380  
381 # bed12 has extra special limitations
382 7 ▶ unless ( $self->_column_is_integers( 7, 8, 10 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_integers(7, 8, 10)) 0 7 7
383 0 $bed_check = 0;
384 0 $error .= ' Column 7,8,10 not integers.';
385 }
386 7 ▶ unless ( $self->_column_is_comma_integers( 11, 12 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_comma_integers(11, 12)) 0 7 7
387 0 $bed_check = 0;
388 0 $error .= ' Column 11,12 not comma-delimited integers.';
389 }
390 }
391 31 ▶ if ( $self->{'number_columns'} == 15
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"number_columns"} == 15 and $self->{"format"} =~ /gapped/i) 6 25 31
Condition66%2/3
$self->{"number_columns"} == 15 and $self->{"format"} =~ /gapped/i
!ll&&!rl&&r
2506
MC/DC50%1/2
$self->{"number_columns"} == 15 and $self->{"format"} =~ /gapped/i
$self->{"number_columns"} == 15 $self->{"format"} =~ /gapped/i
Truth table66%2/3
A and B
A= $self->{"number_columns"} == 15B= $self->{"format"} =~ /gapped/i
ABresult
0X0
100
111
392 and $self->{'format'} =~ /gapped/i )
393 {
394 # gappedPeak has extra special limitations
395 6 ▶ unless ( $self->_column_is_integers( 7, 8, 10 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_integers(7, 8, 10)) 0 6 6
396 0 $bed_check = 0;
397 0 $error .= ' Column 7,8,10 not integers.';
398 }
399 6 ▶ unless ( $self->_column_is_comma_integers( 11, 12 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_comma_integers(11, 12)) 0 6 6
400 0 $bed_check = 0;
401 0 $error .= ' Column 11,12 not comma-delimited integers.';
402 }
403 6 ▶ unless ( $self->_column_is_numeric( 13, 14, 15 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_numeric(13, 14, 15)) 0 6 6
404 0 $bed_check = 0;
405 0 $error .= ' Columns 13,14,15 not numeric.';
406 }
407 }
408  
409 # peak file format
410 31 ▶ if ( $self->{'format'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"format"} and $self->{"format"} =~ /narrowpeak/i and $self->{"number_columns"} != 10) 0 31 31
Condition83%5/6
$self->{"format"} and $self->{"format"} =~ /narrowpeak/i and $self->{"number_columns"} != 10
!ll&&!rl&&r
2560
$self->{"format"} and $self->{"format"} =~ /narrowpeak/i
!ll&&!rl&&r
2236
MC/DC0%0/3
$self->{"format"} and $self->{"format"} =~ /narrowpeak/i and $self->{"number_columns"} != 10
$self->{"format"} $self->{"format"} =~ /narrowpeak/i $self->{"number_columns"} != 10
Truth table75%3/4
A and B and C
A= $self->{"format"}B= $self->{"format"} =~ /narrowpeak/iC= $self->{"number_columns"} != 10
ABCresult
0XX0
10X0
1100
1111
411 and $self->{'format'} =~ /narrowpeak/i
412 and $self->{'number_columns'} != 10 )
413 {
414 0 $bed_check = 0;
415 0 $error .= ' NarrowPeak has 10 columns.';
416 }
417 31 ▶ if ( $self->{'format'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"format"} and $self->{"format"} =~ /broadpeak/i and $self->{"number_columns"} != 9) 0 31 31
Condition50%3/6
$self->{"format"} and $self->{"format"} =~ /broadpeak/i and $self->{"number_columns"} != 9
!ll&&!rl&&r
3100
$self->{"format"} and $self->{"format"} =~ /broadpeak/i
!ll&&!rl&&r
2290
MC/DC0%0/3
$self->{"format"} and $self->{"format"} =~ /broadpeak/i and $self->{"number_columns"} != 9
$self->{"format"} $self->{"format"} =~ /broadpeak/i $self->{"number_columns"} != 9
Truth table50%2/4
A and B and C
A= $self->{"format"}B= $self->{"format"} =~ /broadpeak/iC= $self->{"number_columns"} != 9
ABCresult
0XX0
10X0
1100
1111
418 and $self->{'format'} =~ /broadpeak/i
419 and $self->{'number_columns'} != 9 )
420 {
421 0 $bed_check = 0;
422 0 $error .= ' BroadPeak has 9 columns.';
423 }
424 31 ▶ if ( $self->{'format'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"format"} and $self->{"format"} =~ /gappedpeak/i and $self->{"number_columns"} != 15) 0 31 31
Condition83%5/6
$self->{"format"} and $self->{"format"} =~ /gappedpeak/i and $self->{"number_columns"} != 15
!ll&&!rl&&r
2560
$self->{"format"} and $self->{"format"} =~ /gappedpeak/i
!ll&&!rl&&r
2236
MC/DC0%0/3
$self->{"format"} and $self->{"format"} =~ /gappedpeak/i and $self->{"number_columns"} != 15
$self->{"format"} $self->{"format"} =~ /gappedpeak/i $self->{"number_columns"} != 15
Truth table75%3/4
A and B and C
A= $self->{"format"}B= $self->{"format"} =~ /gappedpeak/iC= $self->{"number_columns"} != 15
ABCresult
0XX0
10X0
1100
1111
425 and $self->{'format'} =~ /gappedpeak/i
426 and $self->{'number_columns'} != 15 )
427 {
428 0 $bed_check = 0;
429 0 $error .= ' GappeddPeak has 15 columns.';
430 }
431  
432 # update metadata as necessary
433 31 ▶ if ( $bed_check == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bed_check == 1) { } 31 0 31
434 31 $self->{'bed'} = $self->{'number_columns'};
435 31 $self->{'gff'} = 0;
436 31 $self->{'ucsc'} = 0;
437 31 $self->{'vcf'} = 0;
438 31 $self->{'headers'} = 0;
439 31 ▶ if ( $self->{'format'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"format"} and not $self->{"format"} =~ / (?: bed | peak ) /xi) 0 31 31
Condition66%2/3
$self->{"format"} and not $self->{"format"} =~ / (?: bed | peak ) /xi
!ll&&!rl&&r
2290
MC/DC0%0/2
$self->{"format"} and not $self->{"format"} =~ / (?: bed | peak ) /xi
$self->{"format"} not $self->{"format"} =~ / (?: bed | peak ) /xi
Truth table66%2/3
A and not(B)
A= $self->{"format"}B= not $self->{"format"} =~ / (?: bed | peak ) /xi
ABresult
0X0
100
111
440 and $self->{'format'} !~ m/ (?: bed | peak ) /xi )
441 {
442 0 $self->{'format'} = sprintf "bed%d", $self->{'number_columns'};
443 }
444 31 ▶ if ( $self->{'extension'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extension"} and not $self->{"extension"} =~ / (?: bed | peak ) /xi) 0 31 31
Condition66%2/3
$self->{"extension"} and not $self->{"extension"} =~ / (?: bed | peak ) /xi
!ll&&!rl&&r
2290
MC/DC0%0/2
$self->{"extension"} and not $self->{"extension"} =~ / (?: bed | peak ) /xi
$self->{"extension"} not $self->{"extension"} =~ / (?: bed | peak ) /xi
Truth table66%2/3
A and not(B)
A= $self->{"extension"}B= not $self->{"extension"} =~ / (?: bed | peak ) /xi
ABresult
0X0
100
111
445 and $self->{'extension'} !~ m/ (?: bed | peak ) /xi )
446 {
447 $self->{'extension'} = sprintf ".%s",
448 0 ▶ $self->{'format'} =~ /peak/ ? lc $self->{'format'} : 'bed';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'format'} =~ /peak/ ? : 0 0 0
449 }
450 }
451 else {
452 0 $self->{'bed'} = 0;
453 0 $self->{'headers'} = 1;
454 0 $self->{'extension'} = '.txt';
455 0 $self->{'format'} = q();
456  
457 # remove the AUTO key from the metadata
458 0 for my $i ( 1 .. $self->{'number_columns'} ) {
459 0 ▶ if ( exists $self->{$i}{'AUTO'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$i}{"AUTO"}) 0 0 0
460 0 delete $self->{$i}{'AUTO'};
461 }
462 }
463 0 ▶ print "\n BED FILE FORMAT ERROR: $error\n" unless $silence;
Branch: 1 branch
BranchTrueFalseTotal
unless $silence 0 0 0
464 }
465 }
466  
467 # check refFlat or genePred gene structure
468 72 ▶ if ( $self->{'ucsc'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ucsc"}) 12 60 72
469  
470 # if any of these checks fail, we will reset the extension
471 12 my $ucsc_check = 1; # start with assumption it is correct
472 12 my $ucsc_type;
473  
474 # check number of columns
475 12 my $colnumber = $self->{number_columns};
476 12 ▶ if ( $colnumber == 16 ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($colnumber == 16) { } 12 0 12
elsif ($colnumber == 15 or $colnumber == 12) { } 0 0 0
elsif ($colnumber == 11) { } 0 0 0
elsif ($colnumber == 10) { } 0 0 0
477 12 $ucsc_type = 'genePredExtBin';
478  
479 # genePredExt with bin
480 # bin name chrom strand txStart txEnd cdsStart cdsEnd
481 # exonCount exonStarts exonEnds score name2 cdsStartSt
482 # cdsEndStat exonFrames
483 12 ▶ unless ( $self->{3}{name} =~
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{3}{"name"} =~ /^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi) 0 12 12
484 m/^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi )
485 {
486 0 $ucsc_check = 0;
487 0 $error .= ' Column 3 name not chromosome-like.';
488 }
489 12 ▶ unless ( $self->{4}{name} =~ m/strand/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{4}{"name"} =~ /strand/i) 6 6 12
490 6 $ucsc_check = 0;
491 6 $error .= ' Column 4 name not strand-like.';
492 }
493 12 ▶ unless ( $self->{5}{name} =~ m/start | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{5}{"name"} =~ /start | pos | position/xi) 6 6 12
494 6 $ucsc_check = 0;
495 6 $error .= ' Column 5 name not start-like.';
496 }
497 12 ▶ unless ( $self->{6}{name} =~ m/stop | end | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{6}{"name"} =~ /stop | end | pos | position/xi) 6 6 12
498 6 $ucsc_check = 0;
499 6 $error .= ' Column 6 name not stop-like.';
500 }
501 12 ▶ unless ( $self->{7}{name} =~ m/start | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{7}{"name"} =~ /start | pos | position/xi) 6 6 12
502 6 $ucsc_check = 0;
503 6 $error .= ' Column 7 name not start-like.';
504 }
505 12 ▶ unless ( $self->{8}{name} =~ m/stop | end | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{8}{"name"} =~ /stop | end | pos | position/xi) 6 6 12
506 6 $ucsc_check = 0;
507 6 $error .= ' Column 8 name not stop-like.';
508 }
509 12 ▶ unless ( $self->_column_is_integers( 5, 6, 7, 8, 9 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_integers(5, 6, 7, 8, 9)) 0 12 12
510 0 $ucsc_check = 0;
511 0 $error .= ' Columns 5,6,7,8,9 not integers.';
512 }
513 12 ▶ unless ( $self->_column_is_comma_integers( 10, 11 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_comma_integers(10, 11)) 0 12 12
514 0 $ucsc_check = 0;
515 0 $error .= ' Columns 10,11 not comma-delimited integers.';
516 }
517 12 ▶ unless ( $self->_column_is_stranded(4) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_stranded(4)) 0 12 12
518 0 $ucsc_check = 0;
519 0 $error .= ' Column 4 not strand values.';
520 }
521 }
522 ▶ elsif ( $colnumber == 15 or $colnumber == 12 ) {
Condition0%0/3
$colnumber == 15 or $colnumber == 12
l!l&&r!l&&!r
000
MC/DC0%0/2
$colnumber == 15 or $colnumber == 12
$colnumber == 15 $colnumber == 12
Truth table0%0/3
A or B
A= $colnumber == 15B= $colnumber == 12
ABresult
1X1
011
000
523 0 ▶ $ucsc_type = $colnumber == 15 ? 'genePredExt' : 'knownGene';
Branch: 1 branch
BranchTrueFalseTotal
$colnumber == 15 ? : 0 0 0
524  
525 # GenePredExt
526 # name chrom strand txStart txEnd cdsStart cdsEnd
527 # exonCount exonStarts exonEnds score name2 cdsStartSt
528 # cdsEndStat exonFrames
529 # or knownGene
530 # name chrom strand txStart txEnd cdsStart cdsEnd
531 # exonCount exonStarts exonEnds proteinID alignID
532 0 ▶ unless ( $self->{2}{name} =~
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{2}{"name"} =~ /^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi) 0 0 0
533 m/^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi )
534 {
535 0 $ucsc_check = 0;
536 0 $error .= ' Column 2 name not chromosome-like.';
537 }
538 0 ▶ unless ( $self->{3}{name} =~ m/strand/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{3}{"name"} =~ /strand/i) 0 0 0
539 0 $ucsc_check = 0;
540 0 $error .= ' Column 3 name not strand-like.';
541 }
542 0 ▶ unless ( $self->{4}{name} =~ m/start | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{4}{"name"} =~ /start | pos | position/xi) 0 0 0
543 0 $ucsc_check = 0;
544 0 $error .= ' Column 4 name not start-like.';
545 }
546 0 ▶ unless ( $self->{5}{name} =~ m/stop | end | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{5}{"name"} =~ /stop | end | pos | position/xi) 0 0 0
547 0 $ucsc_check = 0;
548 0 $error .= ' Column 5 name not stop-like.';
549 }
550 0 ▶ unless ( $self->{6}{name} =~ m/start | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{6}{"name"} =~ /start | pos | position/xi) 0 0 0
551 0 $ucsc_check = 0;
552 0 $error .= ' Column 6 name not start-like.';
553 }
554 0 ▶ unless ( $self->{7}{name} =~ m/stop | end | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{7}{"name"} =~ /stop | end | pos | position/xi) 0 0 0
555 0 $ucsc_check = 0;
556 0 $error .= ' Column 7 name not stop-like.';
557 }
558 0 ▶ unless ( $self->_column_is_integers( 4, 5, 6, 7, 8 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_integers(4, 5, 6, 7, 8)) 0 0 0
559 0 $ucsc_check = 0;
560 0 $error .= ' Columns 4,5,6,7,8 not integers.';
561 }
562 0 ▶ unless ( $self->_column_is_comma_integers( 9, 10 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_comma_integers(9, 10)) 0 0 0
563 0 $ucsc_check = 0;
564 0 $error .= ' Columns 9,10 not comma-delimited integers.';
565 }
566 0 ▶ unless ( $self->_column_is_stranded(3) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_stranded(3)) 0 0 0
567 0 $ucsc_check = 0;
568 0 $error .= ' Column 3 not strand values.';
569 }
570 }
571 elsif ( $colnumber == 11 ) {
572 0 $ucsc_type = 'refFlat';
573  
574 # geneName transcriptName chrom strand txStart txEnd
575 # cdsStart cdsEnd exonCount exonStarts exonEnds
576 0 ▶ unless ( $self->{3}{name} =~
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{3}{"name"} =~ /^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi) 0 0 0
577 m/^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi )
578 {
579 0 $ucsc_check = 0;
580 0 $error .= ' Column 3 name not chromosome-like.';
581 }
582 0 ▶ unless ( $self->{4}{name} =~ m/strand/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{4}{"name"} =~ /strand/i) 0 0 0
583 0 $ucsc_check = 0;
584 0 $error .= ' Column 4 name not strand-like.';
585 }
586 0 ▶ unless ( $self->{5}{name} =~ m/start | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{5}{"name"} =~ /start | pos | position/xi) 0 0 0
587 0 $ucsc_check = 0;
588 0 $error .= ' Column 5 name not start-like.';
589 }
590 0 ▶ unless ( $self->{6}{name} =~ m/stop | end | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{6}{"name"} =~ /stop | end | pos | position/xi) 0 0 0
591 0 $ucsc_check = 0;
592 0 $error .= ' Column 6 name not stop-like.';
593 }
594 0 ▶ unless ( $self->{7}{name} =~ m/start | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{7}{"name"} =~ /start | pos | position/xi) 0 0 0
595 0 $ucsc_check = 0;
596 0 $error .= ' Column 7 name not start-like.';
597 }
598 0 ▶ unless ( $self->{8}{name} =~ m/stop | end | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{8}{"name"} =~ /stop | end | pos | position/xi) 0 0 0
599 0 $ucsc_check = 0;
600 0 $error .= ' Column 8 name not stop-like.';
601 }
602 0 ▶ unless ( $self->_column_is_integers( 5, 6, 7, 8, 9 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_integers(5, 6, 7, 8, 9)) 0 0 0
603 0 $ucsc_check = 0;
604 0 $error .= ' Columns 5,6,7,8,9 not integers.';
605 }
606 0 ▶ unless ( $self->_column_is_comma_integers( 10, 11 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_comma_integers(10, 11)) 0 0 0
607 0 $ucsc_check = 0;
608 0 $error .= ' Columns 10,11 not comma-delimited integers.';
609 }
610 0 ▶ unless ( $self->_column_is_stranded(4) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_stranded(4)) 0 0 0
611 0 $ucsc_check = 0;
612 0 $error .= ' Column 4 not strand values.';
613 }
614 }
615 elsif ( $colnumber == 10 ) {
616 0 $ucsc_type = 'genePred';
617  
618 # name chrom strand txStart txEnd cdsStart cdsEnd
619 # exonCount exonStarts exonEnds
620 0 ▶ unless ( $self->{2}{name} =~
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{2}{"name"} =~ /^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi) 0 0 0
621 m/^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi )
622 {
623 0 $ucsc_check = 0;
624 0 $error .= ' Column 2 name not chromosome-like.';
625 }
626 0 ▶ unless ( $self->{3}{name} =~ m/strand/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{3}{"name"} =~ /strand/i) 0 0 0
627 0 $ucsc_check = 0;
628 0 $error .= ' Column 3 name not strand-like.';
629 }
630 0 ▶ unless ( $self->{4}{name} =~ m/start | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{4}{"name"} =~ /start | pos | position/xi) 0 0 0
631 0 $ucsc_check = 0;
632 0 $error .= ' Column 4 name not start-like.';
633 }
634 0 ▶ unless ( $self->{5}{name} =~ m/stop | end | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{5}{"name"} =~ /stop | end | pos | position/xi) 0 0 0
635 0 $ucsc_check = 0;
636 0 $error .= ' Column 5 name not stop-like.';
637 }
638 0 ▶ unless ( $self->{6}{name} =~ m/start | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{6}{"name"} =~ /start | pos | position/xi) 0 0 0
639 0 $ucsc_check = 0;
640 0 $error .= ' Column 6 name not start-like.';
641 }
642 0 ▶ unless ( $self->{7}{name} =~ m/stop | end | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{7}{"name"} =~ /stop | end | pos | position/xi) 0 0 0
643 0 $ucsc_check = 0;
644 0 $error .= ' Column 7 name not stop-like.';
645 }
646 0 ▶ unless ( $self->_column_is_integers( 4, 5, 6, 7, 8 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_integers(4, 5, 6, 7, 8)) 0 0 0
647 0 $ucsc_check = 0;
648 0 $error .= ' Columns 4,5,6,7,8 not integers.';
649 }
650 0 ▶ unless ( $self->_column_is_comma_integers( 9, 10 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_comma_integers(9, 10)) 0 0 0
651 0 $ucsc_check = 0;
652 0 $error .= ' Columns 9,10 not comma-delimited integers.';
653 }
654 0 ▶ unless ( $self->_column_is_stranded(3) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_stranded(3)) 0 0 0
655 0 $ucsc_check = 0;
656 0 $error .= ' Column 3 not strand values.';
657 }
658 }
659 else {
660 0 $ucsc_type = 'UCSC';
661 0 $ucsc_check = 0;
662 0 $error .= ' Wrong # of columns.';
663 }
664  
665 # update metadata as necessary
666 12 ▶ if ( $ucsc_check == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ucsc_check == 1) { } 6 6 12
667 6 $self->{'bed'} = 0;
668 6 $self->{'gff'} = 0;
669 6 $self->{'vcf'} = 0;
670 6 $self->{'format'} = $ucsc_type;
671 6 ▶ if ( $self->{'extension'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extension"} and not $self->{"extension"} =~ /(?: ucsc | txt | $ucsc_type )/xi) 0 6 6
Condition33%1/3
$self->{"extension"} and not $self->{"extension"} =~ /(?: ucsc | txt | $ucsc_type )/xi
!ll&&!rl&&r
060
MC/DC0%0/2
$self->{"extension"} and not $self->{"extension"} =~ /(?: ucsc | txt | $ucsc_type )/xi
$self->{"extension"} not $self->{"extension"} =~ /(?: ucsc | txt | $ucsc_type )/xi
Truth table33%1/3
A and not(B)
A= $self->{"extension"}B= not $self->{"extension"} =~ /(?: ucsc | txt | $ucsc_type )/xi
ABresult
0X0
100
111
672 and $self->{'extension'} !~ m/(?: ucsc | txt | $ucsc_type )/xi )
673 {
674 0 $self->{'extension'} = ".ucsc"; # generic extension
675 }
676 }
677 else {
678 6 $self->{'ucsc'} = 0;
679 6 $self->{'extension'} = '.txt';
680 6 $self->{'format'} = q();
681  
682 # remove the AUTO key
683 6 for my $i ( 1 .. $self->{'number_columns'} ) {
684 96 ▶ if ( exists $self->{$i}{'AUTO'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$i}{"AUTO"}) 96 0 96
685 96 delete $self->{$i}{'AUTO'};
686 }
687 }
688 6 ▶ print "\n $ucsc_type FILE FORMAT ERROR: $error\n" unless $silence;
Branch: 1 branch
BranchTrueFalseTotal
unless $silence 0 6 6
689 }
690 }
691  
692 # check VCF format
693 72 ▶ if ( $self->{vcf} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"vcf"}) 0 72 72
694  
695 # if any of these checks fail, we will reset the vcf flag to 0
696 # to make it not a vcf file format
697 0 my $vcf_check = 1; # start with assumption it is correct
698  
699 # check number of columns
700 0 ▶ if ( $self->{'number_columns'} < 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"number_columns"} < 8) 0 0 0
701 0 $vcf_check = 0;
702 0 $error .= ' Number of Columns is too few.';
703 }
704  
705 # check column index names
706 0 ▶ if ( $self->{1}{'name'} !~ m/chrom/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{1}{"name"} =~ /chrom/i) 0 0 0
707 0 $vcf_check = 0;
708 0 $error .= ' Column 1 name not chromosome.';
709 }
710 0 ▶ if ( $self->{2}{'name'} !~ m/^pos|start/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{2}{"name"} =~ /^pos|start/i) 0 0 0
711 0 $vcf_check = 0;
712 0 $error .= ' Column 2 name not position.';
713 }
714  
715 # check column data
716 0 ▶ unless ( $self->_column_is_integers(2) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_integers(2)) 0 0 0
717 0 $vcf_check = 0;
718 0 $error .= ' Columns 2 not integers.';
719 }
720  
721 # reset the vcf tag value as appropriate
722 # update metadata as necessary
723 0 ▶ if ( $vcf_check == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vcf_check == 1) { } 0 0 0
724 0 $self->{'bed'} = 0;
725 0 $self->{'gff'} = 0;
726 0 $self->{'ucsc'} = 0;
727 0 ▶ if ( $self->{'format'} and $self->{'format'} !~ m/vcf/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"format"} and not $self->{"format"} =~ /vcf/i) 0 0 0
Condition0%0/3
$self->{"format"} and not $self->{"format"} =~ /vcf/i
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"format"} and not $self->{"format"} =~ /vcf/i
$self->{"format"} not $self->{"format"} =~ /vcf/i
Truth table0%0/3
A and not(B)
A= $self->{"format"}B= not $self->{"format"} =~ /vcf/i
ABresult
0X0
100
111
728 0 $self->{'format'} = 'vcf'; # generic
729 }
730 0 ▶ if ( $self->{'extension'} and $self->{ 'extension' !~ /\.vcf/ } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extension"} and $$self{not "extension" =~ /\.vcf/}) 0 0 0
Condition0%0/3
$self->{"extension"} and $$self{not "extension" =~ /\.vcf/}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"extension"} and $$self{not "extension" =~ /\.vcf/}
$self->{"extension"} $$self{not "extension" =~ /\.vcf/}
Truth table0%0/3
A and B
A= $self->{"extension"}B= $$self{not "extension" =~ /\.vcf/}
ABresult
0X0
100
111
731 0 $self->{'extension'} = '.vcf';
732 }
733 }
734 else {
735 # reset metadata
736 0 $self->{'vcf'} = 0;
737 0 $self->{'headers'} = 1;
738 0 $self->{'format'} = q();
739 0 $self->{'extension'} = '.txt';
740  
741 # remove the AUTO key from the metadata
742 0 for my $i ( 1 .. $self->{'number_columns'} ) {
743 0 ▶ if ( exists $self->{$i}{'AUTO'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$i}{"AUTO"}) 0 0 0
744 0 delete $self->{$i}{'AUTO'};
745 }
746 }
747 0 ▶ print "\n VCF FILE FORMAT ERROR: $error\n" unless $silence;
Branch: 1 branch
BranchTrueFalseTotal
unless $silence 0 0 0
748 }
749 }
750  
751 # check proper SGR file structure
752 72 ▶ if ( exists $self->{'extension'}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"extension"} and defined $self->{"extension"} and $self->{"extension"} =~ /sgr/i) 0 72 72
Condition33%2/6
exists $self->{"extension"} and defined $self->{"extension"} and $self->{"extension"} =~ /sgr/i
!ll&&!rl&&r
0720
exists $self->{"extension"} and defined $self->{"extension"}
!ll&&!rl&&r
0072
MC/DC0%0/3
exists $self->{"extension"} and defined $self->{"extension"} and $self->{"extension"} =~ /sgr/i
exists $self->{"extension"} defined $self->{"extension"} $self->{"extension"} =~ /sgr/i
Truth table25%1/4
A and B and C
A= exists $self->{"extension"}B= defined $self->{"extension"}C= $self->{"extension"} =~ /sgr/i
ABCresult
0XX0
10X0
1100
1111
753 and defined $self->{'extension'}
754 and $self->{'extension'} =~ /sgr/i )
755 {
756 # there is no sgr field in the data structure
757 # so we're just checking for the extension
758 # we will change the extension as necessary if it doesn't conform
759 0 my $sgr_check = 1;
760 0 ▶ if ( $self->{'number_columns'} != 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"number_columns"} != 3) 0 0 0
761 0 $sgr_check = 0;
762 0 $error .= ' Column number is not 3.';
763 }
764 0 ▶ if ( $self->{1}{'name'} !~
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{1}{"name"} =~ /^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi) 0 0 0
765 m/^\#? (?: chr | chromo | chromosome | seq | seq.id )/xi )
766 {
767 0 $sgr_check = 0;
768 0 $error .= ' Column 1 name not chromosome-like.';
769 }
770 0 ▶ if ( $self->{2}{'name'} !~ m/start | pos | position/xi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{2}{"name"} =~ /start | pos | position/xi) 0 0 0
771 0 $sgr_check = 0;
772 0 $error .= ' Column 2 name not start-like.';
773 }
774 0 ▶ unless ( $self->_column_is_integers(2) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_column_is_integers(2)) 0 0 0
775 0 $sgr_check = 0;
776 0 $error .= ' Columns 2 not integers.';
777 }
778  
779 # update metadata as necessary
780 0 ▶ if ( $sgr_check == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sgr_check == 1) { } 0 0 0
781 0 $self->{'bed'} = 0;
782 0 $self->{'gff'} = 0;
783 0 $self->{'ucsc'} = 0;
784 0 $self->{'vcf'} = 0;
785 0 $self->{'headers'} = 0;
786 0 ▶ if ( $self->{'format'} and $self->{'format'} !~ m/sgr/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"format"} and not $self->{"format"} =~ /sgr/i) 0 0 0
Condition0%0/3
$self->{"format"} and not $self->{"format"} =~ /sgr/i
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"format"} and not $self->{"format"} =~ /sgr/i
$self->{"format"} not $self->{"format"} =~ /sgr/i
Truth table0%0/3
A and not(B)
A= $self->{"format"}B= not $self->{"format"} =~ /sgr/i
ABresult
0X0
100
111
787 0 $self->{'format'} = 'sgr';
788 }
789 0 ▶ if ( $self->{'extension'} and $self->{ 'extension' !~ /\.sgr/ } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extension"} and $$self{not "extension" =~ /\.sgr/}) 0 0 0
Condition0%0/3
$self->{"extension"} and $$self{not "extension" =~ /\.sgr/}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"extension"} and $$self{not "extension" =~ /\.sgr/}
$self->{"extension"} $$self{not "extension" =~ /\.sgr/}
Truth table0%0/3
A and B
A= $self->{"extension"}B= $$self{not "extension" =~ /\.sgr/}
ABresult
0X0
100
111
790 0 $self->{'extension'} = '.sgr';
791 }
792 }
793 else {
794  
795 # doesn't smell like a SGR file
796 # change the extension so the write subroutine won't think it is
797 # make it a text file
798 0 $self->{'extension'} =~ s/sgr/txt/i;
799 0 $self->{'headers'} = 1;
800 0 $self->{'format'} = q();
801  
802 # remove the AUTO key from the metadata
803 0 for my $i ( 1 .. $self->{'number_columns'} ) {
804 0 ▶ if ( exists $self->{$i}{'AUTO'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$i}{"AUTO"}) 0 0 0
805 0 delete $self->{$i}{'AUTO'};
806 }
807 }
808 0 ▶ print "\n SGR FILE FORMAT ERROR: $error\n" unless $silence;
Branch: 1 branch
BranchTrueFalseTotal
unless $silence 0 0 0
809 }
810 }
811  
812 # if we have made it here, then there were no major structural problems
813 # file is verified, any minor issues should have been fixed
814 72 return 1;
815 }
816  
817 # internal method to check if a column is nothing but integers, i.e. start, stop
818 75 ▶sub _column_is_integers {
Subroutine _column_is_integers: called CC=7 SCAR=20.0
819 75 my $self = shift;
820 75 my @index = @_;
821 75 ▶ return 1 if ( $self->{last_row} == 0 ); # can't check if table is empty
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"last_row"} == 0 0 75 75
822 75 foreach (@index) {
823 193 ▶ return 0 unless exists $self->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$_} 0 193 193
824 }
825 75 for my $row ( 1 .. $self->{last_row} ) {
826 897 for my $i (@index) {
827 2224 ▶ return 0 unless ( $self->{data_table}->[$row][$i] =~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data_table"}[$row][$i] =~ /^\d+$/ 0 2224 2224
828 }
829 }
830 75 return 1;
831 }
832  
833 # internal method to check if a column appears numeric, i.e. scores
834 53 ▶sub _column_is_numeric {
Subroutine _column_is_numeric: called CC=7 SCAR=20.0
835 53 my $self = shift;
836 53 my @index = @_;
837 53 ▶ return 1 if ( $self->{last_row} == 0 ); # can't check if table is empty
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"last_row"} == 0 0 53 53
838 53 foreach (@index) {
839 77 ▶ return 0 unless exists $self->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$_} 0 77 77
840 }
841 53 for my $row ( 1 .. $self->{last_row} ) {
842 434 for my $i (@index) {
843  
844 # we have a very loose definition of numeric: exponents, signs, commas
845 554 ▶ return 0 unless ( $self->{data_table}->[$row][$i] =~ m/^ [\d\-\+\.,eE]+ $/x );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data_table"}[$row][$i] =~ /^ [\d\-\+\.,eE]+ $/x 0 554 554
846 }
847 }
848 53 return 1;
849 }
850  
851 # internal method to check if a column is nothing but comma delimited integers
852 25 ▶sub _column_is_comma_integers {
Subroutine _column_is_comma_integers: called CC=7 SCAR=20.0
853 25 my $self = shift;
854 25 my @index = @_;
855 25 ▶ return 1 if ( $self->{last_row} == 0 ); # can't check if table is empty
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"last_row"} == 0 0 25 25
856 25 foreach (@index) {
857 50 ▶ return 0 unless exists $self->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$_} 0 50 50
858 }
859 25 for my $row ( 1 .. $self->{last_row} ) {
860 220 for my $i (@index) {
861 440 ▶ return 0 unless ( $self->{data_table}->[$row][$i] =~ /^[\d,]+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data_table"}[$row][$i] =~ /^[\d,]+$/ 0 440 440
862 }
863 }
864 25 return 1;
865 }
866  
867 # internal method to check if a column looks like a strand column
868 53 ▶sub _column_is_stranded {
Subroutine _column_is_stranded: called CC=4 SCAR=14.3
869 53 my ( $self, $index ) = @_;
870 53 ▶ return unless exists $self->{$index};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$index} 0 53 53
871 53 for my $row ( 1 .. $self->{last_row} ) {
872 return 0
873 494 ▶ if ( $self->{data_table}->[$row][$index] !~
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data_table"}[$row][$index] =~ /^(?: \-1 | 0 | 1 | \+ | \- | \. )$/x 0 494 494
874 m/^(?: \-1 | 0 | 1 | \+ | \- | \. )$/x );
875 }
876 53 return 1;
877 }
878  
879 #### Database methods ##############################################################
880  
881 1 ▶sub open_database {
Subroutine open_database: called CC=5 SCAR=27.0
Pod documented
882 1 my $self = shift;
883 1 ▶ if ( not defined $_[0] ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $_[0]) { } 1 0 1
elsif ($_[0] eq '0' or $_[0] eq '1') { } 0 0 0
elsif ($_[0] =~ /[a-zA-Z]+/) { } 0 0 0
884 1 return $self->open_meta_database;
885 }
886 ▶ elsif ( $_[0] eq '0' or $_[0] eq '1' ) {
Condition0%0/3
$_[0] eq 0 or $_[0] eq 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] eq 0 or $_[0] eq 1
$_[0] eq 0 $_[0] eq 1
Truth table0%0/3
A or B
A= $_[0] eq 0B= $_[0] eq 1
ABresult
1X1
011
000
887  
888 # likely a boolean value to indicate force
889 0 return $self->open_meta_database( $_[0] );
890 }
891 elsif ( $_[0] =~ /[a-zA-Z]+/ ) {
892  
893 # likely the name of a database
894 0 return $self->open_new_database(@_);
895 }
896 else {
897 # original default
898 0 return $self->open_meta_database(@_);
899 }
900 }
901  
902 15 ▶sub open_meta_database {
Subroutine open_meta_database: called CC=7 SCAR=20.2
Pod documented
903 15 my $self = shift;
904 15 ▶ my $force = shift || 0;
Condition50%1/2
shift() || 0
l!l
015
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
905 15 ▶ return unless $self->{db};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"db"} 0 15 15
906 15 ▶ return if $self->{db} =~ /^Parsed:/; # we don't open parsed annotation files
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"db"} =~ /^Parsed:/ 0 15 15
907 15 ▶ if ( exists $self->{db_connection} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"db_connection"}) 14 1 15
908 14 ▶ return $self->{db_connection} unless $force;
Branch: 1 branch
BranchTrueFalseTotal
unless $force 14 0 14
909 }
910 1 my $db = open_db_connection( $self->{db}, $force );
911 1 ▶ return unless $db;
Branch: 1 branch
BranchTrueFalseTotal
unless $db 0 1 1
912 1 $self->{db_connection} = $db;
913 1 return $db;
914 }
915  
916 0 ▶sub open_new_database {
Subroutine open_new_database: not called CC=2 SCAR=17.9
Pod documented
917 0 my $self = shift;
918 0 my $database = shift;
919 0 ▶ my $force = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
920 0 return open_db_connection( $database, $force );
921 }
922  
923 12 ▶sub verify_dataset {
Subroutine verify_dataset: called CC=6 SCAR=19.9
Pod documented
924 12 my ( $self, $dataset, $database ) = @_;
925 12 ▶ return unless $dataset;
Branch: 1 branch
BranchTrueFalseTotal
unless $dataset 0 12 12
926 12 ▶ if ( exists $self->{verfied_dataset}{$dataset} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'verfied_dataset'}{$dataset}) { } 11 1 12
927 11 return $self->{verfied_dataset}{$dataset};
928 }
929 else {
930 1 ▶ if ( $dataset =~ /^(?: file | http | ftp )/x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dataset =~ /^(?: file | http | ftp )/x) 0 1 1
931  
932 # local or remote file already verified?
933 0 $self->{verfied_dataset}{$dataset} = $dataset;
934 0 return $dataset;
935 }
936 1 ▶ $database ||= $self->open_meta_database;
Condition33%1/3
$database ||= $self->open_meta_database
l!l&&r!l&&!r
100
MC/DC0%0/2
$database ||= $self->open_meta_database
$database $self->open_meta_database
Truth table33%1/3
A ||= B
A= $databaseB= $self->open_meta_database
ABresult
1X1
011
000
937 1 my ($verified) = verify_or_request_feature_types(
938  
939 # normally returns an array of verified features, we're only checking one
940 db => $database,
941 feature => $dataset,
942 );
943 1 ▶ if ($verified) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verified) 1 0 1
944 1 $self->{verfied_dataset}{$dataset} = $verified;
945 1 return $verified;
946 }
947 }
948 0 return;
949 }
950  
951 #### Column Manipulation ####
952  
953 2 ▶sub delete_column {
Subroutine delete_column: called CC=9 SCAR=28.6
Pod documented
954 2 my $self = shift;
955  
956 # check for Stream
957 2 ▶ if ( ref($self) eq 'Bio::ToolBox::Data::Stream' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self eq "Bio::ToolBox::Data::Stream") 0 2 2
958 0 ▶ unless ( $self->mode ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->mode) 0 0 0
959 0 cluck 'ERROR: We have a read-only Stream object, cannot add columns';
960 0 return;
961 }
962 0 ▶ if ( defined $self->{fh} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"fh"}) 0 0 0
963  
964 # Stream file handle is opened
965 0 cluck 'ERROR: Cannot modify columns when a Stream file handle is opened!';
966 0 return;
967 }
968 }
969 2 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 2 2
970 0 carp 'ERROR: must provide a list';
971 0 return;
972 }
973  
974 # identify columns to retain
975 2 my @deletion_list = @_;
976 2 ▶ if ( scalar @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1) 0 2 2
977 0 @deletion_list = sort { $a <=> $b } @_;
978 }
979 2 my @retain_list;
980 2 for my $i ( 1 .. $self->{'number_columns'} ) {
981  
982 # compare each current index with the first one in the list of
983 # deleted indices. if it matches, delete. if not, keep
984 18 ▶ if ( defined $deletion_list[0] and $i == $deletion_list[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $deletion_list[0] and $i == $deletion_list[0]) { } 2 16 18
Condition100%3/3
defined $deletion_list[0] and $i == $deletion_list[0]
!ll&&!rl&&r
1152
MC/DC100%2/2
defined $deletion_list[0] and $i == $deletion_list[0]
defined $deletion_list[0] $i == $deletion_list[0]
Truth table100%3/3
A and B
A= defined $deletion_list[0]B= $i == $deletion_list[0]
ABresult
0X0
100
111
985 2 shift @deletion_list; # this particular index should be deleted
986 }
987 else {
988 16 push @retain_list, $i; # this particular index should be kept
989 }
990 }
991 2 return $self->reorder_column(@retain_list);
992 }
993  
994 3 ▶sub reorder_column {
Subroutine reorder_column: called CC=10 SCAR=25.8
Pod documented
995 3 my $self = shift;
996  
997 # check for Stream
998 3 ▶ if ( ref($self) eq 'Bio::ToolBox::Data::Stream' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self eq "Bio::ToolBox::Data::Stream") 0 3 3
999 0 ▶ unless ( $self->mode ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->mode) 0 0 0
1000 0 cluck 'ERROR: We have a read-only Stream object, cannot add columns';
1001 0 return;
1002 }
1003 0 ▶ if ( defined $self->{fh} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"fh"}) 0 0 0
1004  
1005 # Stream file handle is opened
1006 0 cluck 'ERROR: Cannot modify columns when a Stream file handle is opened!';
1007 0 return;
1008 }
1009 }
1010  
1011 # reorder data table
1012 3 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 3 3
1013 0 carp 'ERROR: must provide a list';
1014 0 return;
1015 }
1016 3 my @order = @_;
1017 3 unshift @order, 0; # to maintain 1-based indexing
1018 3 for my $r ( 0 .. $self->last_row ) {
1019 237 my @old = $self->row_values($r); # this is an array copy
1020 237 unshift @old, q(); # to maintain 1-based indexing
1021 237 my @new = map { $old[$_] } @order;
1022 237 splice( @{ $self->{data_table} }, $r, 1, \@new );
1023 }
1024 3 $self->{data_table}->[0][0] = 'BLANK'; # not necessary but consistent
1025  
1026 # reorder metadata
1027 # copy the current metadata info hash into a temporary hash
1028 # then copy back from the old_metadata into the main data hash
1029 # using the new index number in the @order array
1030 # must regenerate the hash, not just link to the old anonymous hash, in
1031 # case we're duplicating columns
1032 3 my %old_metadata;
1033 3 for my $i ( 1 .. $self->{'number_columns'} ) {
1034 28 $old_metadata{$i} = $self->{$i};
1035 28 delete $self->{$i};
1036 }
1037 3 for my $i ( 1 .. ( scalar(@order) - 1 ) ) {
1038  
1039 #specifically skipping 0 because it doesn't have metadata
1040 20 $self->{$i} = {};
1041 20 foreach my $k ( keys %{ $old_metadata{ $order[$i] } } ) {
1042 61 $self->{$i}{$k} = $old_metadata{ $order[$i] }{$k};
1043 }
1044 20 $self->{$i}{'index'} = $i; # reset index
1045 }
1046  
1047 # additional metadata
1048 3 $self->{'number_columns'} = scalar(@order) - 1; # ignore first index
1049 3 ▶ delete $self->{column_indices} if exists $self->{column_indices};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"column_indices"} 2 1 3
1050  
1051 3 return 1;
1052 }
1053  
1054 #### General Metadata ####
1055  
1056 108 ▶sub feature {
Subroutine feature: called CC=2 SCAR=6.9
Pod documented
1057 108 my $self = shift;
1058 108 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 57 51 108
1059 57 $self->{feature} = shift;
1060 }
1061 108 return $self->{feature};
1062 }
1063  
1064 37 ▶sub feature_type {
Subroutine feature_type: called CC=10 SCAR=28.3
Pod documented
1065 37 my $self = shift;
1066 37 ▶ carp 'ERROR: feature_type is a read only method' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 37 37
1067 37 ▶ if ( defined $self->{feature_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"feature_type"}) 23 14 37
1068 23 return $self->{feature_type};
1069 }
1070 14 my $feature_type;
1071 14 ▶ if ( $self->chromo_column and $self->start_column ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->chromo_column and $self->start_column) { } 9 5 14
elsif ($self->id_column or $self->type_column and $self->name_column or $self->feature and $self->name_column) { } 5 0 5
Condition66%2/3
$self->chromo_column and $self->start_column
!ll&&!rl&&r
509
MC/DC50%1/2
$self->chromo_column and $self->start_column
$self->chromo_column $self->start_column
Truth table66%2/3
A and B
A= $self->chromo_columnB= $self->start_column
ABresult
0X0
100
111
1072 9 $feature_type = 'coordinate';
1073 }
1074 ▶ elsif ( $self->id_column
Condition16%2/12
$self->id_column or $self->type_column and $self->name_column or $self->feature and $self->name_column
l!l&&r!l&&!r
500
$self->id_column or $self->type_column and $self->name_column
l!l&&r!l&&!r
500
$self->type_column and $self->name_column
!ll&&!rl&&r
000
$self->feature and $self->name_column
!ll&&!rl&&r
000
MC/DC0%0/5
$self->id_column or $self->type_column and $self->name_column or $self->feature and $self->name_column
$self->id_column $self->type_column $self->name_column $self->feature $self->name_column
Truth table12%1/8
A or B and C or D and E
A= $self->id_columnB= $self->type_columnC= $self->name_columnD= $self->featureE= $self->name_column
ABCDEresult
1XXXX1
011XX1
00X111
010111
00X0X0
00X100
0100X0
010100
1075 or ( $self->type_column and $self->name_column )
1076 or ( $self->feature and $self->name_column ) )
1077 {
1078 5 $feature_type = 'named';
1079 }
1080 else {
1081 0 $feature_type = 'unknown';
1082 }
1083 14 $self->{feature_type} = $feature_type;
1084 14 return $feature_type;
1085 }
1086  
1087 73 ▶sub program {
Subroutine program: called CC=2 SCAR=6.9
Pod documented
1088 73 my $self = shift;
1089 73 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 65 8 73
1090 65 $self->{program} = shift;
1091 }
1092 73 return $self->{program};
1093 }
1094  
1095 51 ▶sub database {
Subroutine database: called CC=4 SCAR=15.0
Pod documented
1096 51 my $self = shift;
1097 51 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 20 31 51
1098 20 $self->{db} = shift;
1099 20 ▶ if ( exists $self->{db_connection} and $self->{db_connection} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"db_connection"} and $self->{"db_connection"}) 0 20 20
Condition33%1/3
exists $self->{"db_connection"} and $self->{"db_connection"}
!ll&&!rl&&r
2000
MC/DC0%0/2
exists $self->{"db_connection"} and $self->{"db_connection"}
exists $self->{"db_connection"} $self->{"db_connection"}
Truth table33%1/3
A and B
A= exists $self->{"db_connection"}B= $self->{"db_connection"}
ABresult
0X0
100
111
1100 0 $self->open_meta_database(1);
1101 }
1102 }
1103 51 return $self->{db};
1104 }
1105  
1106 0 ▶sub bam_adapter {
Subroutine bam_adapter: not called CC=1 SCAR=6.9
Pod documented
1107 0 my $self = shift;
1108 0 return use_bam_adapter(@_);
1109 }
1110  
1111 0 ▶sub big_adapter {
Subroutine big_adapter: not called CC=1 SCAR=6.9
Pod documented
1112 0 my $self = shift;
1113 0 return use_big_adapter(@_);
1114 }
1115  
1116 287 ▶sub format {
Subroutine format: called CC=2 SCAR=6.9
Pod documented
1117 287 my $self = shift;
1118 287 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 75 212 287
1119 75 $self->{format} = $_[0];
1120 }
1121 287 return $self->{format};
1122 }
1123  
1124 104 ▶sub gff {
Subroutine gff: called CC=4 SCAR=13.9
Pod documented
1125 104 my $self = shift;
1126 104 ▶ if ( defined $_[0] and $_[0] =~ m/^(?: 0 | 1 | 2 | 2\.[2|5] | 3 )$/x ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and $_[0] =~ /^(?: 0 | 1 | 2 | 2\.[2|5] | 3 )$/x) 14 90 104
Condition66%2/3
defined $_[0] and $_[0] =~ /^(?: 0 | 1 | 2 | 2\.[2|5] | 3 )$/x
!ll&&!rl&&r
90014
MC/DC50%1/2
defined $_[0] and $_[0] =~ /^(?: 0 | 1 | 2 | 2\.[2|5] | 3 )$/x
defined $_[0] $_[0] =~ /^(?: 0 | 1 | 2 | 2\.[2|5] | 3 )$/x
Truth table66%2/3
A and B
A= defined $_[0]B= $_[0] =~ /^(?: 0 | 1 | 2 | 2\.[2|5] | 3 )$/x
ABresult
0X0
100
111
1127 14 $self->{gff} = $_[0];
1128 14 ▶ if ($_[0] > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] > 0) { } 13 1 14
1129 13 $self->{headers} = 0;
1130 }
1131 else {
1132 1 $self->{headers} = 1;
1133 }
1134 }
1135 104 return $self->{gff};
1136 }
1137  
1138 69 ▶sub bed {
Subroutine bed: called CC=4 SCAR=14.2
Pod documented
1139 69 my $self = shift;
1140 69 ▶ if ( defined $_[0] and $_[0] =~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and $_[0] =~ /^\d+$/) 14 55 69
Condition66%2/3
defined $_[0] and $_[0] =~ /^\d+$/
!ll&&!rl&&r
55014
MC/DC50%1/2
defined $_[0] and $_[0] =~ /^\d+$/
defined $_[0] $_[0] =~ /^\d+$/
Truth table66%2/3
A and B
A= defined $_[0]B= $_[0] =~ /^\d+$/
ABresult
0X0
100
111
1141 14 $self->{bed} = $_[0];
1142 14 ▶ if ($_[0] > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] > 0) { } 14 0 14
1143 14 $self->{headers} = 0;
1144 }
1145 else {
1146 0 $self->{headers} = 1;
1147 }
1148 }
1149 69 return $self->{bed};
1150 }
1151  
1152 46 ▶sub ucsc {
Subroutine ucsc: called CC=3 SCAR=11.0
Pod documented
1153 46 my $self = shift;
1154 46 ▶ if ( defined $_[0] and $_[0] =~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and $_[0] =~ /^\d+$/) 12 34 46
Condition66%2/3
defined $_[0] and $_[0] =~ /^\d+$/
!ll&&!rl&&r
34012
MC/DC50%1/2
defined $_[0] and $_[0] =~ /^\d+$/
defined $_[0] $_[0] =~ /^\d+$/
Truth table66%2/3
A and B
A= defined $_[0]B= $_[0] =~ /^\d+$/
ABresult
0X0
100
111
1155 12 $self->{ucsc} = $_[0];
1156 }
1157 46 return $self->{ucsc};
1158 }
1159  
1160 18 ▶sub vcf {
Subroutine vcf: called CC=3 SCAR=13.3
Pod documented
1161 18 my $self = shift;
1162 18 ▶ if ( defined $_[0] and $_[0] =~ /^[\d\.]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and $_[0] =~ /^[\d\.]+$/) 0 18 18
Condition33%1/3
defined $_[0] and $_[0] =~ /^[\d\.]+$/
!ll&&!rl&&r
1800
MC/DC0%0/2
defined $_[0] and $_[0] =~ /^[\d\.]+$/
defined $_[0] $_[0] =~ /^[\d\.]+$/
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] =~ /^[\d\.]+$/
ABresult
0X0
100
111
1163 0 $self->{vcf} = $_[0];
1164 }
1165 18 return $self->{vcf};
1166 }
1167  
1168 461 ▶sub number_columns {
Subroutine number_columns: called CC=2 SCAR=7.1
Pod documented
1169 461 my $self = shift;
1170 461 ▶ carp 'ERROR: number_columns is a read only method' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 461 461
1171 461 return $self->{'number_columns'};
1172 }
1173  
1174 33 ▶sub number_rows {
Subroutine number_rows: called CC=2 SCAR=7.1
Pod documented
1175 33 my $self = shift;
1176 33 ▶ carp 'ERROR: number_rows is a read only method' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 33 33
1177 33 return $self->{last_row};
1178 }
1179  
1180 0 ▶sub last_column {
Subroutine last_column: not called CC=2 SCAR=17.9
Pod documented
1181 0 my $self = shift;
1182 0 ▶ carp 'ERROR: last_column is a read only method' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
1183 0 return $self->{'number_columns'};
1184 }
1185  
1186 297 ▶sub last_row {
Subroutine last_row: called CC=2 SCAR=7.1
Pod documented
1187 297 my $self = shift;
1188 297 ▶ carp 'ERROR: last_row is a read only method' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 297 297
1189 297 return $self->{last_row};
1190 }
1191  
1192 226 ▶sub filename {
Subroutine filename: called CC=2 SCAR=7.1
Pod documented
1193 226 my $self = shift;
1194 226 ▶ carp 'ERROR: filename is a read only method. Use add_file_metadata().' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 226 226
1195 226 return $self->{filename};
1196 }
1197  
1198 9 ▶sub basename {
Subroutine basename: called CC=2 SCAR=7.1
Pod documented
1199 9 my $self = shift;
1200 9 ▶ carp 'ERROR: basename is a read only method. Use add_file_metadata().' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 9 9
1201 9 return $self->{basename};
1202 }
1203  
1204 0 ▶sub path {
Subroutine path: not called CC=2 SCAR=17.9
Pod documented
1205 0 my $self = shift;
1206 0 ▶ carp 'ERROR: path is a read only method. Use add_file_metadata().' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
1207 0 return $self->{path};
1208 }
1209  
1210 120 ▶sub extension {
Subroutine extension: called CC=2 SCAR=7.1
Pod documented
1211 120 my $self = shift;
1212 120 ▶ carp 'ERROR: extension() is a read only method. Use add_file_metadata().' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 120 120
1213 120 return $self->{extension};
1214 }
1215  
1216 #### General Comments ####
1217  
1218 7 ▶sub comments {
Subroutine comments: called CC=2 SCAR=6.9
Pod documented
1219 7 my $self = shift;
1220 7 my @comments = @{ $self->{comments} };
1221 7 foreach (@comments) {s/[\r\n]+//g}
1222  
1223 # comments are not chomped when loading
1224 # side effect of dealing with rare commented header lines with null values at end
1225 7 return @comments;
1226 }
1227  
1228 69 ▶sub add_comment {
Subroutine add_comment: called CC=2 SCAR=7.0
Pod documented
1229 69 my $self = shift;
1230 69 ▶ my $comment = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $comment = shift() or return 69 0 69
1231  
1232 # comment is not required to be prefixed with "# ", it will be added when saving
1233 69 push @{ $self->{comments} }, $comment;
1234 69 return 1;
1235 }
1236  
1237 1 ▶sub delete_comment {
Subroutine delete_comment: called CC=2 SCAR=7.1
Pod documented
1238 1 my $self = shift;
1239 1 my $index = shift;
1240 1 ▶ if ( defined $index ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $index) { } 1 0 1
1241 1 eval { splice @{ $self->{comments} }, $index, 1 };
1242 }
1243 else {
1244 0 $self->{comments} = [];
1245 }
1246 }
1247  
1248 77 ▶sub headers {
Subroutine headers: called CC=2 SCAR=6.9
Pod documented
1249 77 my $self = shift;
1250 77 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 58 19 77
1251 58 $self->{headers} = $_[0];
1252 }
1253 77 return $self->{headers};
1254 }
1255  
1256 0 ▶sub vcf_headers {
Subroutine vcf_headers: not called CC=6 SCAR=37.4
Pod documented
1257 0 my $self = shift;
1258 0 ▶ return unless $self->vcf;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->vcf 0 0 0
1259 0 ▶ return $self->{vcf_headers} if exists $self->{vcf_headers};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"vcf_headers"} 0 0 0
1260 0 my $headers = {};
1261 0 foreach my $comment ( $self->comments ) {
1262 0 my ( $key, $value );
1263 0 ▶ if ( $comment =~ m/^ \#\# ( [\w\-\.]+ ) = (.+) $/x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comment =~ /^ \#\# ( [\w\-\.]+ ) = (.+) $/x) { } 0 0 0
1264 0 $key = $1;
1265 0 $value = $2;
1266 }
1267 else {
1268 # invalid vcf header format!?
1269 0 next;
1270 }
1271 0 ▶ if ( $value !~ /^<.+>$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $value =~ /^<.+>$/) { } 0 0 0
1272  
1273 # simple value
1274 0 $headers->{$key} = $value;
1275 }
1276 else {
1277 # process complex values
1278 # extract ID with regex which should have
1279 0 my $id = ( $value =~ m/ID = ( [\w\-\.:]+ )/x )[0];
1280 0 $headers->{$key}{$id} = $value;
1281 }
1282 }
1283  
1284 # store and return
1285 0 $self->{vcf_headers} = $headers;
1286 0 return $headers;
1287 }
1288  
1289 0 ▶sub rewrite_vcf_headers {
Subroutine rewrite_vcf_headers: not called CC=7 SCAR=40.3
Pod documented
1290 0 my $self = shift;
1291 0 ▶ return unless $self->vcf;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->vcf 0 0 0
1292 0 ▶ return unless exists $self->{vcf_headers};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"vcf_headers"} 0 0 0
1293 0 my @newComments;
1294  
1295 # file format always comes first
1296 0 push @newComments, sprintf( "##fileformat=%s\n", $self->{vcf_headers}{fileformat} );
1297  
1298 # common attributes
1299 0 foreach my $key ( sort { $a cmp $b } keys %{ $self->{vcf_headers} } ) {
1300 0 ▶ next if $key eq 'fileformat';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "fileformat" 0 0 0
1301 0 ▶ if ( ref( $self->{vcf_headers}{$key} ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'vcf_headers'}{$key} eq 'HASH') { } 0 0 0
1302  
1303 # we have a complex VCF header with multiple keys
1304 # we will rewrite for each ID
1305 0 foreach my $id (
1306 0 sort { $a cmp $b }
1307 0 keys %{ $self->{vcf_headers}{$key} }
1308 )
1309 {
1310 # to avoid complexity of writing correct formatting
1311 push @newComments,
1312 0 sprintf( "##%s=%s\n", $key, $self->{vcf_headers}{$key}{$id} );
1313 }
1314 }
1315 else {
1316 # a simple value
1317 0 push @newComments, sprintf( "##%s=%s\n", $key, $self->{vcf_headers}{$key} );
1318 }
1319 }
1320  
1321 # replace the headers
1322 0 $self->{comments} = \@newComments;
1323 }
1324  
1325 #### Column Metadata ####
1326  
1327 5 ▶sub list_columns {
Subroutine list_columns: called CC=3 SCAR=11.0
Pod documented
1328 5 my $self = shift;
1329 5 ▶ carp 'ERROR: list_columns is a read only method' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 5 5
1330 5 my @list = map { $self->name($_) } ( 1 .. $self->{'number_columns'} );
1331 5 ▶ return wantarray ? @list : \@list;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 3 5
1332 }
1333  
1334 161 ▶sub name {
Subroutine name: called CC=4 SCAR=14.0
Pod documented
1335 161 my $self = shift;
1336 161 my ( $index, $new_name ) = @_;
1337 161 ▶ return unless defined $index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 0 161 161
1338 161 ▶ return unless exists $self->{$index};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$index} 0 161 161
1339 161 ▶ if ( defined $new_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new_name) 2 159 161
1340 2 $self->{$index}{name} = $new_name;
1341 2 $self->{data_table}->[0][$index] = $new_name;
1342 }
1343 161 return $self->{$index}{'name'};
1344 }
1345  
1346 36 ▶sub metadata {
Subroutine metadata: called CC=11 SCAR=26.3
Pod documented
1347 36 my $self = shift;
1348 36 my ( $index, $key, $value ) = @_;
1349 36 ▶ return unless defined $index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 0 36 36
1350 36 ▶ return unless exists $self->{$index};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$index} 0 36 36
1351 36 ▶ if ( $key and $key eq 'name' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key and $key eq "name") 2 34 36
Condition100%3/3
$key and $key eq "name"
!ll&&!rl&&r
3132
MC/DC100%2/2
$key and $key eq "name"
$key $key eq "name"
Truth table100%3/3
A and B
A= $keyB= $key eq "name"
ABresult
0X0
100
111
1352 2 return $self->name( $index, $value );
1353 }
1354 34 ▶ if ( $key and defined $value ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($key and defined $value) { } 3 31 34
elsif ($key and not defined $value) { } 0 31 31
Condition66%2/3
$key and defined $value
!ll&&!rl&&r
3103
MC/DC50%1/2
$key and defined $value
$key defined $value
Truth table66%2/3
A and B
A= $keyB= defined $value
ABresult
0X0
100
111
1355  
1356 # we are setting a new value
1357 3 $self->{$index}{$key} = $value;
1358 3 return $value;
1359 }
1360 ▶ elsif ( $key and not defined $value ) {
Condition33%1/3
$key and not defined $value
!ll&&!rl&&r
3100
MC/DC0%0/2
$key and not defined $value
$key not defined $value
Truth table33%1/3
A and not(B)
A= $keyB= not defined $value
ABresult
0X0
100
111
1361 0 ▶ if ( exists $self->{$index}{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$index}{$key}) { } 0 0 0
1362  
1363 # retrieve a value
1364 0 return $self->{$index}{$key};
1365 }
1366 else {
1367 # key does not exist
1368 0 return;
1369 }
1370 }
1371 else {
1372 31 my %hash = %{ $self->{$index} };
1373 31 ▶ return wantarray ? %hash : \%hash;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 27 4 31
1374 }
1375 }
1376  
1377 0 ▶sub delete_metadata {
Subroutine delete_metadata: not called CC=7 SCAR=40.3
Pod documented
1378 0 my $self = shift;
1379 0 my ( $index, $key ) = @_;
1380 0 ▶ return unless defined $index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 0 0 0
1381 0 ▶ if ( defined $key ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 0 0 0
1382 0 ▶ if ( exists $self->{$index}{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$index}{$key}) 0 0 0
1383 0 return delete $self->{$index}{$key};
1384 }
1385 }
1386 else {
1387 # user wants to delete the metadata
1388 # but we need to keep the basics name and index
1389 0 foreach my $key ( keys %{ $self->{$index} } ) {
1390 0 ▶ next if $key eq 'name';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "name" 0 0 0
1391 0 ▶ next if $key eq 'index';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "index" 0 0 0
1392 0 delete $self->{$index}{$key};
1393 }
1394 }
1395 }
1396  
1397 2 ▶sub copy_metadata {
Subroutine copy_metadata: called CC=5 SCAR=16.4
Pod documented
1398 2 my ( $self, $source, $target ) = @_;
1399 2 ▶ return unless ( exists $self->{$source}{name} and exists $self->{$target}{name} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$source}{"name"} and exists $self->{$target}{"name"} 0 2 2
Condition33%1/3
exists $self->{$source}{"name"} and exists $self->{$target}{"name"}
!ll&&!rl&&r
002
MC/DC0%0/2
exists $self->{$source}{"name"} and exists $self->{$target}{"name"}
exists $self->{$source}{"name"} exists $self->{$target}{"name"}
Truth table33%1/3
A and B
A= exists $self->{$source}{"name"}B= exists $self->{$target}{"name"}
ABresult
0X0
100
111
1400 2 my $md = $self->metadata($source);
1401 2 delete $md->{name};
1402 2 delete $md->{'index'};
1403 2 ▶ delete $md->{'AUTO'} if exists $md->{'AUTO'}; # presume this is no longer auto index
Branch: 1 branch
BranchTrueFalseTotal
if exists $md->{"AUTO"} 1 1 2
1404 2 foreach ( keys %{$md} ) {
1405 1 $self->{$target}{$_} = $md->{$_};
1406 }
1407 2 return 1;
1408 }
1409  
1410 #### Column Indices ####
1411  
1412 776 ▶sub find_column {
Subroutine find_column: called CC=4 SCAR=13.9
Pod documented
1413 776 my ( $self, $name ) = @_;
1414 776 ▶ return unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 776 776
1415  
1416 # the $name variable will be used as a regex in identifying the name
1417 # fix it so that it will possible accept a # character at the beginning
1418 # without a following space, in case the first column has a # prefix
1419 # also place the remainder of the text in a non-capturing parentheses for
1420 # grouping purposes while maintaining the anchors
1421 776 $name =~ s/ \A (\^?) (.+) (\$?)\Z /$1#?(?:$2)$3/x;
1422  
1423 # walk through each column index and check the name
1424 776 my $index;
1425 776 for my $i ( 1 .. $self->{'number_columns'} ) {
1426 3901 ▶ if ( $self->{$i}{'name'} =~ /$name/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{$i}{"name"} =~ /$name/i) 344 3557 3901
1427 344 $index = $i;
1428 344 last;
1429 }
1430 }
1431 776 return $index;
1432 }
1433  
1434 69 ▶sub _find_column_indices {
Subroutine _find_column_indices: called CC=22 SCAR=31.2
1435 69 my $self = shift;
1436  
1437 # these are hard coded index name regex to accomodate different possibilities
1438 # these do not include parentheses for grouping
1439 # non-capturing parentheses will be added later in the sub for proper
1440 # anchoring and grouping - long story why, don't ask
1441 # some of these have progressively more relaxed criteria to avoid false positives
1442 69 my $name = $self->find_column('^name$');
1443 69 ▶ unless ( defined $name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 15 54 69
1444  
1445 # try more agressive search for names
1446 15 $name = $self->find_column('^gene.?name|transcript.?name$');
1447 }
1448 69 ▶ unless ( defined $name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 15 54 69
1449  
1450 # take any column with "name" in it
1451 15 $name = $self->find_column('name');
1452 }
1453 69 ▶ unless ( defined $name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 15 54 69
1454  
1455 # try even more agressive for annotation identifiers
1456 15 $name = $self->find_column('^gene|gene.?id|transcript.?id$');
1457 }
1458 69 ▶ unless ( defined $name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 15 54 69
1459  
1460 # use an id
1461 15 $name = $self->find_column('^id$');
1462 }
1463 69 my $type = $self->find_column('^type|class|primary_tag|biotype');
1464 69 my $id = $self->find_column('^primary_id$'); # database specific primary id
1465 69 my $chromo = $self->find_column('^chromosome|chromo|chrom|chr|seq.*id$');
1466 69 ▶ unless ( defined $chromo ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chromo) 13 56 69
1467 13 $chromo = $self->find_column('chr');
1468 }
1469 69 my $start = $self->find_column('^start$');
1470 69 ▶ unless ( defined $start ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $start) 52 17 69
1471 52 $start = $self->find_column('start');
1472 }
1473 69 ▶ unless ( defined $start ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $start) 13 56 69
1474 13 $start = $self->find_column('^position|pos');
1475 }
1476 69 my $stop = $self->find_column('^stop|end$');
1477 69 ▶ unless ( defined $stop ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $stop) 13 56 69
1478 13 $stop = $self->find_column('stop|end');
1479 }
1480 69 my $strand = $self->find_column('^strand');
1481 69 my $score = $self->find_column('^score$');
1482  
1483 # check for coordinate string
1484 69 my $coord = $self->find_column('^coordinate$');
1485 69 ▶ if ( not $coord and not $chromo and not $start ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($coord or $chromo or $start) 12 57 69
Condition83%5/6
$coord or $chromo or $start
l!l&&r!l&&!r
57012
$coord or $chromo
l!l&&r!l&&!r
15612
MC/DC66%2/3
$coord or $chromo or $start
$coord $chromo $start
Truth table75%3/4
A or B or C
A= $coordB= $chromoC= $start
ABCresult
1XX1
01X1
0011
0000
1486  
1487 # check if ID or name id looks like a coordinate string
1488 12 ▶ if ( $id and $self->{data_table}->[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id and $self->{"data_table"}[1]) 12 0 12
Condition33%1/3
$id and $self->{"data_table"}[1]
!ll&&!rl&&r
0012
MC/DC0%0/2
$id and $self->{"data_table"}[1]
$id $self->{"data_table"}[1]
Truth table33%1/3
A and B
A= $idB= $self->{"data_table"}[1]
ABresult
0X0
100
111
1489 12 ▶ if ( $self->{data_table}->[1][$id] =~
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"data_table"}[1][$id] =~ /^ [\w\-\.]+: \d+ (?: [\-\.]{1,2} \d+ )?$/x) 8 4 12
1490 m/^ [\w\-\.]+: \d+ (?: [\-\.]{1,2} \d+ )?$/x )
1491 {
1492  
1493 # first value looks like a coordinate string
1494 8 $coord = $id;
1495 }
1496 }
1497 12 ▶ if ( not $coord
Branch: 1 branch
BranchTrueFalseTotal
if (not $coord and $name and defined $self->{"data_table"}[1]) 4 8 12
Condition66%4/6
not $coord and $name and defined $self->{"data_table"}[1]
!ll&&!rl&&r
804
not $coord and $name
!ll&&!rl&&r
804
MC/DC33%1/3
not $coord and $name and defined $self->{"data_table"}[1]
not $coord $name defined $self->{"data_table"}[1]
Truth table50%2/4
not(A) and B and C
A= not $coordB= $nameC= defined $self->{"data_table"}[1]
ABCresult
0XX0
10X0
1100
1111
1498 and $name
1499 and defined $self->{data_table}->[1] )
1500 {
1501 4 ▶ if ( $self->{data_table}->[1][$name] =~
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"data_table"}[1][$name] =~ /^ [\w\-\.]+: \d+ (?: [\-\.]{1,2} \d+ )?$/x) 0 4 4
1502 m/^ [\w\-\.]+: \d+ (?: [\-\.]{1,2} \d+ )?$/x )
1503 {
1504 # first value looks like a coordinate string
1505 0 $coord = $name;
1506 }
1507 }
1508 }
1509  
1510 # determine zero-based start coordinates
1511 69 ▶ if ( $self->{zerostart} == 0
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"zerostart"} == 0 and $start and substr($self->name($start), -1) eq 0) 39 30 69
Condition83%5/6
$self->{"zerostart"} == 0 and $start and substr($self->name($start), -1) eq 0
!ll&&!rl&&r
131739
$self->{"zerostart"} == 0 and $start
!ll&&!rl&&r
01356
MC/DC66%2/3
$self->{"zerostart"} == 0 and $start and substr($self->name($start), -1) eq 0
$self->{"zerostart"} == 0 $start substr($self->name($start), -1) eq 0
Truth table75%3/4
A and B and C
A= $self->{"zerostart"} == 0B= $startC= substr($self->name($start), -1) eq 0
ABCresult
0XX0
10X0
1100
1111
1512 and $start
1513 and substr( $self->name($start), -1 ) eq '0' )
1514 {
1515 39 $self->{zerostart} = 1;
1516 }
1517  
1518 # cache the indexes
1519 $self->{column_indices} = {
1520 69 'name' => $name,
1521 'type' => $type,
1522 'id' => $id,
1523 'seq_id' => $chromo,
1524 'chromo' => $chromo,
1525 'start' => $start,
1526 'stop' => $stop,
1527 'end' => $stop,
1528 'strand' => $strand,
1529 'score' => $score,
1530 'coord' => $coord,
1531 };
1532 69 return 1;
1533 }
1534  
1535 38 ▶sub chromo_column {
Subroutine chromo_column: called CC=5 SCAR=16.8
Pod documented
1536 38 my $self = shift;
1537 38 ▶ $self->_find_column_indices unless exists $self->{column_indices};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"column_indices"} 10 28 38
1538 38 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 2 36 38
1539 2 ▶ if ( $_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'}) { } 2 0 2
Condition33%1/3
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
!ll&&!rl&&r
002
MC/DC0%0/2
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
$_[0] =~ /^\d+$/ $_[0] <= $self->{"number_columns"}
Truth table33%1/3
A and B
A= $_[0] =~ /^\d+$/B= $_[0] <= $self->{"number_columns"}
ABresult
0X0
100
111
1540 2 $self->{column_indices}{chromo} = $_[0];
1541 }
1542 else {
1543 0 carp sprintf( "chromo_column %s is not a valid index!", $_[0] );
1544 }
1545 }
1546 38 return $self->{column_indices}{chromo};
1547 }
1548  
1549 172 ▶sub start_column {
Subroutine start_column: called CC=5 SCAR=16.8
Pod documented
1550 172 my $self = shift;
1551 172 ▶ $self->_find_column_indices unless exists $self->{column_indices};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"column_indices"} 51 121 172
1552 172 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 2 170 172
1553 2 ▶ if ( $_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'}) { } 2 0 2
Condition33%1/3
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
!ll&&!rl&&r
002
MC/DC0%0/2
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
$_[0] =~ /^\d+$/ $_[0] <= $self->{"number_columns"}
Truth table33%1/3
A and B
A= $_[0] =~ /^\d+$/B= $_[0] <= $self->{"number_columns"}
ABresult
0X0
100
111
1554 2 $self->{column_indices}{start} = $_[0];
1555 }
1556 else {
1557 0 carp sprintf( "ERROR: start_column %s is not a valid index!", $_[0] );
1558 }
1559 }
1560 172 return $self->{column_indices}{start};
1561 }
1562  
1563 27 ▶sub stop_column {
Subroutine stop_column: called CC=5 SCAR=17.5
Pod documented
1564 27 my $self = shift;
1565 27 ▶ $self->_find_column_indices unless exists $self->{column_indices};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"column_indices"} 0 27 27
1566 27 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 2 25 27
1567 2 ▶ if ( $_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'}) { } 2 0 2
Condition33%1/3
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
!ll&&!rl&&r
002
MC/DC0%0/2
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
$_[0] =~ /^\d+$/ $_[0] <= $self->{"number_columns"}
Truth table33%1/3
A and B
A= $_[0] =~ /^\d+$/B= $_[0] <= $self->{"number_columns"}
ABresult
0X0
100
111
1568 2 $self->{column_indices}{stop} = $_[0];
1569 }
1570 else {
1571 0 carp sprintf( "ERROR: stop_column %s is not a valid index!", $_[0] );
1572 }
1573 }
1574 27 return $self->{column_indices}{stop};
1575 }
1576  
1577 4 *end_column = \&stop_column;
1578 4 *end_column if 0; # avoid once warning
1579  
1580 131 ▶sub coord_column {
Subroutine coord_column: called CC=5 SCAR=24.1
Pod documented
1581 131 my $self = shift;
1582 131 ▶ $self->_find_column_indices unless exists $self->{column_indices};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"column_indices"} 0 131 131
1583 131 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 0 131 131
1584 0 ▶ if ( $_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'}) { } 0 0 0
Condition0%0/3
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
$_[0] =~ /^\d+$/ $_[0] <= $self->{"number_columns"}
Truth table0%0/3
A and B
A= $_[0] =~ /^\d+$/B= $_[0] <= $self->{"number_columns"}
ABresult
0X0
100
111
1585 0 $self->{column_indices}{coord} = $_[0];
1586 }
1587 else {
1588 0 carp sprintf( "ERROR: coord_column %s is not a valid index!", $_[0] );
1589 }
1590 }
1591 131 return $self->{column_indices}{coord};
1592 }
1593  
1594 22 ▶sub strand_column {
Subroutine strand_column: called CC=5 SCAR=16.8
Pod documented
1595 22 my $self = shift;
1596 22 ▶ $self->_find_column_indices unless exists $self->{column_indices};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"column_indices"} 3 19 22
1597 22 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 2 20 22
1598 2 ▶ if ( $_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'}) { } 2 0 2
Condition33%1/3
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
!ll&&!rl&&r
002
MC/DC0%0/2
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
$_[0] =~ /^\d+$/ $_[0] <= $self->{"number_columns"}
Truth table33%1/3
A and B
A= $_[0] =~ /^\d+$/B= $_[0] <= $self->{"number_columns"}
ABresult
0X0
100
111
1599 2 $self->{column_indices}{strand} = $_[0];
1600 }
1601 else {
1602 0 carp sprintf( "ERROR: strand_column %s is not a valid index!", $_[0] );
1603 }
1604 }
1605 22 return $self->{column_indices}{strand};
1606 }
1607  
1608 12 ▶sub name_column {
Subroutine name_column: called CC=5 SCAR=24.1
Pod documented
1609 12 my $self = shift;
1610 12 ▶ $self->_find_column_indices unless exists $self->{column_indices};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"column_indices"} 0 12 12
1611 12 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 0 12 12
1612 0 ▶ if ( $_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'}) { } 0 0 0
Condition0%0/3
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
$_[0] =~ /^\d+$/ $_[0] <= $self->{"number_columns"}
Truth table0%0/3
A and B
A= $_[0] =~ /^\d+$/B= $_[0] <= $self->{"number_columns"}
ABresult
0X0
100
111
1613 0 $self->{column_indices}{name} = $_[0];
1614 }
1615 else {
1616 0 carp sprintf( "ERROR: name_column %s is not a valid index!", $_[0] );
1617 }
1618 }
1619 12 return $self->{column_indices}{name};
1620 }
1621  
1622 14 ▶sub type_column {
Subroutine type_column: called CC=5 SCAR=16.8
Pod documented
1623 14 my $self = shift;
1624 14 ▶ $self->_find_column_indices unless exists $self->{column_indices};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"column_indices"} 4 10 14
1625 14 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 2 12 14
1626 2 ▶ if ( $_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'}) { } 2 0 2
Condition33%1/3
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
!ll&&!rl&&r
002
MC/DC0%0/2
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
$_[0] =~ /^\d+$/ $_[0] <= $self->{"number_columns"}
Truth table33%1/3
A and B
A= $_[0] =~ /^\d+$/B= $_[0] <= $self->{"number_columns"}
ABresult
0X0
100
111
1627 2 $self->{column_indices}{type} = $_[0];
1628 }
1629 else {
1630 0 carp sprintf( "ERROR: type_column %s is not a valid index!", $_[0] );
1631 }
1632 }
1633 14 return $self->{column_indices}{type};
1634 }
1635  
1636 71 ▶sub id_column {
Subroutine id_column: called CC=5 SCAR=22.5
Pod documented
1637 71 my $self = shift;
1638 71 ▶ $self->_find_column_indices unless exists $self->{column_indices};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"column_indices"} 1 70 71
1639 71 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 0 71 71
1640 0 ▶ if ( $_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'}) { } 0 0 0
Condition0%0/3
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
$_[0] =~ /^\d+$/ $_[0] <= $self->{"number_columns"}
Truth table0%0/3
A and B
A= $_[0] =~ /^\d+$/B= $_[0] <= $self->{"number_columns"}
ABresult
0X0
100
111
1641 0 $self->{column_indices}{id} = $_[0];
1642 }
1643 else {
1644 0 carp sprintf( "ERROR: id_column %s is not a valid index!", $_[0] );
1645 }
1646 }
1647 71 return $self->{column_indices}{id};
1648 }
1649  
1650 5 ▶sub score_column {
Subroutine score_column: called CC=5 SCAR=24.1
Pod documented
1651 5 my $self = shift;
1652 5 ▶ $self->_find_column_indices unless exists $self->{column_indices};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"column_indices"} 0 5 5
1653 5 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 0 5 5
1654 0 ▶ if ( $_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/ and $_[0] <= $self->{'number_columns'}) { } 0 0 0
Condition0%0/3
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] =~ /^\d+$/ and $_[0] <= $self->{"number_columns"}
$_[0] =~ /^\d+$/ $_[0] <= $self->{"number_columns"}
Truth table0%0/3
A and B
A= $_[0] =~ /^\d+$/B= $_[0] <= $self->{"number_columns"}
ABresult
0X0
100
111
1655 0 $self->{column_indices}{score} = $_[0];
1656 }
1657 else {
1658 0 carp sprintf( "ERROR: score_column %s is not a valid index!", $_[0] );
1659 }
1660 }
1661 5 return $self->{column_indices}{score};
1662 }
1663  
1664 147 ▶sub interbase {
Subroutine interbase: called CC=6 SCAR=18.1
Pod documented
1665 147 my $self = shift;
1666 147 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 51 96 147
1667 51 my $i = $self->start_column;
1668 51 my $n = $self->name($i);
1669 51 ▶ if ( $_[0] == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_[0] == 1) { } 38 13 51
elsif ($_[0] == 0) { } 13 0 13
1670 38 $self->{zerostart} = 1;
1671 38 ▶ if ( lc $n eq 'start' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $n eq "start") 1 37 38
1672 1 $self->name( $i, 'Start0' );
1673 }
1674 }
1675 elsif ( $_[0] == 0 ) {
1676 13 $self->{zerostart} = 0;
1677 13 ▶ if ( lc $n eq 'start0' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $n eq "start0") 0 13 13
1678 0 $self->name( $i, 'Start' );
1679 }
1680 }
1681 }
1682 147 return $self->{zerostart};
1683 }
1684  
1685 #### Special Row methods ####
1686  
1687 # Why is this in core and not in Data? I keep asking myself.
1688 # Because this can get called from a Data::Feature object, which might be
1689 # associated with a Data::Stream object. No, Stream objects don't have stored
1690 # SeqFeatures, but I don't want the entire program to crash because of an
1691 # undefined method because some doofus forgot. Since both Data and Stream
1692 # objects inherit from Data::core, this is in here.
1693 13 ▶sub get_seqfeature {
Subroutine get_seqfeature: called CC=6 SCAR=20.7
Pod documented
1694 13 my ( $self, $row ) = @_;
1695 13 ▶ return unless ( ref($self) eq 'Bio::ToolBox::Data' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq "Bio::ToolBox::Data" 0 13 13
1696 13 ▶ return unless ( $row and $row <= $self->{last_row} );
Branch: 1 branch
BranchTrueFalseTotal
unless $row and $row <= $self->{"last_row"} 0 13 13
Condition33%1/3
$row and $row <= $self->{"last_row"}
!ll&&!rl&&r
0013
MC/DC0%0/2
$row and $row <= $self->{"last_row"}
$row $row <= $self->{"last_row"}
Truth table33%1/3
A and B
A= $rowB= $row <= $self->{"last_row"}
ABresult
0X0
100
111
1697 13 ▶ return unless exists $self->{SeqFeatureObjects};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"SeqFeatureObjects"} 0 13 13
1698 13 ▶ return $self->{SeqFeatureObjects}->[$row] || undef;
Condition50%1/2
$self->{'SeqFeatureObjects'}[$row] || undef
l!l
130
MC/DC0%0/1
$self->{'SeqFeatureObjects'}[$row] || undef
$self->{'SeqFeatureObjects'}[$row]
Truth table50%1/2
A
A= $self->{'SeqFeatureObjects'}[$row]
Aresult
11
00
1699 }
1700  
1701 4 1;
1702  
1703 __END__
« script/bam2wig.pl ↑ Summary lib/Bio/ToolBox/Data/file.pm »