lib/TIGR/FASTA/Reader.pm

filter: Statementstmt 13.0% 37 / 283 Branchbran 0.0% 0 / 122 Conditioncond 0.0% 0 / 111 MC/DCmcdc 0.0% 0 / 60 Subroutinesub 30.4% 7 / 23 Podpod 100% 12 / 12 totaltotal 9.1% 56 / 611 CC 99 SCAR 59.9
CC
99
Cov
7%
_parseDBfile
1190.0
open
182.0
new
156.0
CRAP 398.7
« lib/TIGR/HmmTools.pm ↑ Summary lib/TIGR/FASTA/Iterator.pm »
1 # $Id: FASTAreader.pm,v 1.1 2004/04/28 15:03:43 aphillip Exp $
2  
3 package TIGR::FASTA::Reader;
4 {
5
6 =head1 NAME
7  
8 TIGR::FASTA::Reader - TIGR::FASTA::Reader class for parsing and navigating
9 FASTA format files.
10  
11 =head1 SYNOPSIS
12  
13 use TIGR::FASTA::Reader;
14 my $obj_instance = new TIGR::FASTA::Reader ($foundation_obj_ref,
15 $error_array_ref, $fasta_file_name);
16  
17 =head1 DESCRIPTION
18  
19 This module iterates over a FASTA formatted database file. It provides
20 data extraction and simple analysis routines. This module utilizes
21 acceptance validation of FASTA formatted files via the TIGR::FASTA::Grammar
22 module.
23  
24 =cut
25  
26 1 ▶ BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 require 5.006_00;
28 }
29  
30 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶ use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶ use TIGR::Foundation;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶ use TIGR::FASTA::Grammar ':public';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶ use TIGR::FASTA::Grammar ':private';
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶ use TIGR::FASTA::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37  
38 ## internal variables and identifiers
39  
40 1 our $REVISION = (qw$Revision: 1.1 $)[-1];
41 1 our $VERSION = '1.21';
42 1 our $VERSION_STRING = "$VERSION (Build $REVISION)";
43 1 our @DEPEND = ();
44  
45 1 my $SYS_ERR = 0; # this flag specifies non-user related error
46 1 my $USR_ERR = 1; # this flag specifies user related error
47  
48 ## external variables
49  
50 1 my $UNBOUND_FASTA_SEPARATOR = $TIGR::FASTA::Grammar::UNBOUND_FASTA_SEPARATOR;
51
52 # debugging scheme
53 #
54 # Debugging via the TIGR Foundation uses increasing log levels based on
55 # nesting. 'MAIN' starts at level 1. Every nest increments the level by
56 # 1.
57 # Subroutines always start nesting at level 2. As debugging levels
58 # increase, logging is more verbose. This makes sense as you log at
59 # greater depth (ie. deeper branching).
60 #
61 # The following definitions help emphasize the debugging in the program.
62 #
63 1 my $DEBUG_LEVEL_1 = 1;
64 1 my $DEBUG_LEVEL_2 = 2;
65 1 my $DEBUG_LEVEL_3 = 3;
66 1 my $DEBUG_LEVEL_4 = 4;
67 1 my $DEBUG_LEVEL_5 = 5;
68 1 my $DEBUG_LEVEL_6 = 6;
69 1 my $DEBUG_LEVEL_7 = 7;
70 1 my $DEBUG_LEVEL_8 = 8;
71 1 my $DEBUG_LEVEL_9 = 9;
72  
73 ## prototypes
74  
75 sub new(;$$$);
76 sub open($;$);
77 sub close();
78 sub index();
79 sub seekIndex($);
80 sub getRecordByIdentifier($);
81 sub seekIdentifer($);
82 sub get();
83 sub next();
84 sub hasNext();
85 sub count();
86 sub path();
87 sub _initialize();
88 sub _parseDBfile();
89 sub _nullRecordHandler($$);
90 sub _errorHandler($$$);
91  
92  
93 ## implementation
94  
95 =over
96  
97 =item $obj_instance = new TIGR::FASTA::Reader ($foundation_object,
98 $error_array_ref, $db_file);
99  
100 This method returns a new instance of a TIGR::FASTA::Reader object. It takes
101 three optional parameters: a TIGR::Foundation object (C<$foundation_object>),
102 a reference to an array for logging user error messages (C<$error_array_ref>),
103 and FASTA file (C<$db_file>). The new instance is returned on success. If
104 the file supplied cannot be opened or is invalid, this method returns
105 undefined. This method also returns undefined if the parameters supplied are
106 invalid. Errors in parsing are written to the array at C<$error_array_ref>
107 and the log file.
108  
109 =cut
110  
111 0 ▶ sub new(;$$$) {
Subroutine new: not called CC=12 SCAR=50.5
Pod documented
112 0 my $pkg = shift;
113 0 my @method_args = @_;
114  
115 0 my $error_condition = 0;
116 0 my $self = {};
117 0 bless $self, $pkg;
118 0 $self->_initialize(); # set up internal variables;
119  
120 0 ▶ if ( ( scalar (@method_args) > 0 ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @method_args > 0 and ref($method_args[0]) =~ /foundation/i) { } 0 0 0
Condition0%0/3
scalar @method_args > 0 and ref($method_args[0]) =~ /foundation/i
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @method_args > 0 and ref($method_args[0]) =~ /foundation/i
scalar @method_args > 0 ref($method_args[0]) =~ /foundation/i
Truth table0%0/3
A and B
A= scalar @method_args > 0B= ref($method_args[0]) =~ /foundation/i
ABresult
0X0
100
111
121 ( ( ref ($method_args[0]) ) =~ /foundation/i ) ) {
122 0 $self->{foundation} = shift @method_args;
123 0 $self->_errorHandler("Got TIGR::Foundation in new()", $DEBUG_LEVEL_3,
124 $SYS_ERR);
125 }
126 else {
127 0 $self->{foundation} = undef;
128 0 $self->_errorHandler("No TIGR::Foundation in new()", $DEBUG_LEVEL_3,
129 $SYS_ERR);
130 }
131  
132 0 ▶ if ( ( scalar (@method_args) > 0 ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @method_args > 0 and ref($method_args[0]) =~ /array/i) { } 0 0 0
Condition0%0/3
scalar @method_args > 0 and ref($method_args[0]) =~ /array/i
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @method_args > 0 and ref($method_args[0]) =~ /array/i
scalar @method_args > 0 ref($method_args[0]) =~ /array/i
Truth table0%0/3
A and B
A= scalar @method_args > 0B= ref($method_args[0]) =~ /array/i
ABresult
0X0
100
111
133 ( ( ref ($method_args[0]) ) =~ /array/i ) ) {
134 0 $self->{error_ref} = shift @method_args;
135 0 $self->_errorHandler("Got Error ARRAY in new()", $DEBUG_LEVEL_3,
136 $SYS_ERR);
137 }
138 else {
139 0 $self->{error_ref} = undef;
140 0 $self->_errorHandler("No Error ARRAY in new()", $DEBUG_LEVEL_3,
141 $SYS_ERR);
142 }
143  
144 0 ▶ if ( ( scalar (@method_args) > 0 ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @method_args > 0 and not ref $method_args[0]) { } 0 0 0
Condition0%0/3
scalar @method_args > 0 and not ref $method_args[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @method_args > 0 and not ref $method_args[0]
scalar @method_args > 0 not ref $method_args[0]
Truth table0%0/3
A and not(B)
A= scalar @method_args > 0B= not ref $method_args[0]
ABresult
0X0
100
111
145 ( ! ref ($method_args[0]) ) ) {
146 0 my $filename = shift @method_args;
147 0 ▶ if(defined($filename)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $filename) { } 0 0 0
148 0 $self->{db_file_name} = $filename ;
149 0 $self->_errorHandler("Got file name in new()", $DEBUG_LEVEL_4,
150 $SYS_ERR);
151 }
152 else {
153 0 $self->_errorHandler("undef passed as filename", $DEBUG_LEVEL_4,
154 $USR_ERR);
155 }
156 }
157 else {
158 0 $self->{db_file_name} = undef;
159 0 $self->_errorHandler("No file name in new()", $DEBUG_LEVEL_3,
160 $SYS_ERR);
161 }
162  
163 # check for invocation errors
164 0 ▶ if ( ( scalar (@method_args) > 0 ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @method_args > 0) { } 0 0 0
elsif (defined $self->{'db_file_name'} and not defined $self->open($self->{'db_file_name'}, 'r')) { } 0 0 0
165 0 $error_condition = 1;
166 0 $self->_errorHandler("Too many parameters passed to new() method",
167 $DEBUG_LEVEL_3, $SYS_ERR);
168 }
169 ▶ elsif ( defined ( $self->{db_file_name} ) &&
Condition0%0/3
defined $self->{"db_file_name"} and not defined $self->open($self->{"db_file_name"}, "r")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"db_file_name"} and not defined $self->open($self->{"db_file_name"}, "r")
defined $self->{"db_file_name"} not defined $self->open($self->{"db_file_name"}, "r")
Truth table0%0/3
A and not(B)
A= defined $self->{"db_file_name"}B= not defined $self->open($self->{"db_file_name"}, "r")
ABresult
0X0
100
111
170 ! defined ( $self->open($self->{db_file_name}, "r") ) ) {
171 # the error message is logged via the open() routine
172 0 $self = undef;
173 }
174 0 ▶ return ( $error_condition == 0 ) ? $self : undef;
Branch: 1 branch
BranchTrueFalseTotal
$error_condition == 0 ? : 0 0 0
175 }
176  
177  
178 =item $result = $obj_instance->open($file_name, $flag);
179  
180 This method opens a FASTA file for reading. This method also parses the file
181 for correctness. The file, C<$file_name>, is opened using the C<open()> flags
182 specified by C<$flag>. On success, this method returns 1. If the file cannot
183 be opened or parsing fails, this method returns undefined.
184  
185 =cut
186  
187 0 ▶ sub open($;$) {
Subroutine open: not called CC=13 SCAR=52.0
Pod documented
188 0 my $self = shift;
189 0 my $db_file_name = shift;
190 0 my $open_flags = shift;
191  
192 0 my $error_condition = 0;
193  
194 0 ▶ if ( ( ! defined ($open_flags) ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $open_flags and $open_flags =~ /^r$/i) 0 0 0
Condition0%0/3
defined $open_flags and $open_flags =~ /^r$/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $open_flags and $open_flags =~ /^r$/i
defined $open_flags $open_flags =~ /^r$/i
Truth table0%0/3
A and B
A= defined $open_flagsB= $open_flags =~ /^r$/i
ABresult
0X0
100
111
195 ( $open_flags !~ /^r$/i ) ) {
196 0 $open_flags = "r";
197 }
198 0 $self->_errorHandler("Open flags = \'$open_flags\' in open()",
199 $DEBUG_LEVEL_3, $SYS_ERR);
200  
201 # close a previously open file
202 0 ▶ if ( defined ($self->{db_handle}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"db_handle"}) 0 0 0
203 0 $self->_errorHandler("Closing old handle in open()", $DEBUG_LEVEL_3,
204 $SYS_ERR);
205 0 $self->close();
206 }
207  
208 0 ▶ if (!(
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $db_file_name && ($self->{'db_file_name'} = $db_file_name) && defined $self->{'db_file_name'} && defined($self->{'db_handle'} = 'IO::File'->new($self->{'db_file_name'}, $open_flags))) { } 0 0 0
elsif (defined $self->{'db_file_name'} and defined $self->{'db_handle'} and $self->_parseDBfile == 0) { } 0 0 0
Condition0%0/9
defined $db_file_name && ($self->{'db_file_name'} = $db_file_name) && defined $self->{'db_file_name'} && defined($self->{'db_handle'} = 'IO::File'->new($self->{'db_file_name'}, $open_flags))
!ll&&!rl&&r
000
defined $db_file_name and $self->{"db_file_name"} = $db_file_name and defined $self->{"db_file_name"}
!ll&&!rl&&r
000
defined $db_file_name and $self->{"db_file_name"} = $db_file_name
!ll&&!rl&&r
000
MC/DC0%0/4
defined $db_file_name && ($self->{'db_file_name'} = $db_file_name) && defined $self->{'db_file_name'} && defined($self->{'db_handle'} = 'IO::File'->new($self->{'db_file_name'}, $open_flags))
defined $db_file_name $self->{"db_file_name"} = $db_file_name defined $self->{"db_file_name"} defined($self->{'db_handle'} = 'IO::File'->new($self->{'db_file_name'}, $open_flags))
Truth table0%0/5
A and B and C && D
A= defined $db_file_nameB= $self->{"db_file_name"} = $db_file_nameC= defined $self->{"db_file_name"}D= defined($self->{'db_handle'} = 'IO::File'->new($self->{'db_file_name'}, $open_flags))
ABCDresult
0XXX0
10XX0
110X0
11100
11111
209 ( defined ( $db_file_name ) ) &&
210 ( $self->{db_file_name} = $db_file_name ) &&
211 ( defined ( $self->{db_file_name} )) &&
212 ( defined ( $self->{db_handle} =
213 new IO::File $self->{db_file_name}, $open_flags ))
214 ) ) {
215 0 $error_condition = 1;
216 0 $self->_errorHandler(
217 "Cannot open file \'$self->{db_file_name}\'", $DEBUG_LEVEL_3,
218 $USR_ERR);
219 }
220 ▶ elsif ( ( defined ( $self->{db_file_name} ) ) &&
Condition0%0/6
defined $self->{"db_file_name"} and defined $self->{"db_handle"} and $self->_parseDBfile == 0
!ll&&!rl&&r
000
defined $self->{"db_file_name"} and defined $self->{"db_handle"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $self->{"db_file_name"} and defined $self->{"db_handle"} and $self->_parseDBfile == 0
defined $self->{"db_file_name"} defined $self->{"db_handle"} $self->_parseDBfile == 0
Truth table0%0/4
A and B and C
A= defined $self->{"db_file_name"}B= defined $self->{"db_handle"}C= $self->_parseDBfile == 0
ABCresult
0XX0
10X0
1100
1111
221 ( defined ( $self->{db_handle} ) ) &&
222 ( $self->_parseDBfile() == 0 ) ) {
223 0 $error_condition = 1;
224 0 $self->_errorHandler("Encountered errors in file " .
225 "\'$self->{db_file_name}\'.", $DEBUG_LEVEL_3, $USR_ERR);
226 }
227  
228 0 ▶ if ( $error_condition == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error_condition == 1) 0 0 0
229 0 $self->_initialize(); # reset object state
230 }
231  
232 0 ▶ return ($error_condition == 1) ? undef : 1;
Branch: 1 branch
BranchTrueFalseTotal
$error_condition == 1 ? : 0 0 0
233 }
234  
235  
236 =item $result = $obj_instance->close();
237  
238 This method closes the object file stream and resets all internal data
239 structures. The result of the operation is returned. If the file stream
240 is closed successfully, this object returns true (1), otherwise false
241 (undefined).
242  
243 =cut
244  
245 0 ▶ sub close() {
Subroutine close: not called CC=3 SCAR=24.8
Pod documented
246 0 my $self = shift;
247 0 my $return_val = undef;
248  
249 0 ▶ if ( defined ( $self->{db_handle} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"db_handle"}) 0 0 0
250 0 $return_val = $self->{db_handle}->close();
251 0 ▶ if (!$return_val) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($return_val) 0 0 0
252 0 $return_val = undef;
253 0 $self->_errorHandler(
254 "Error closing FASTA file: $self->{db_file_name}",
255 $DEBUG_LEVEL_4, $USR_ERR);
256 }
257 }
258 0 $self->_initialize();
259 0 return $return_val;
260 }
261  
262  
263 =item $record_num = $obj_instance->index();
264  
265 This method returns the record number of the active record. If no record has
266 been selected (ie. made active), then this method returns undefined. If
267 the active record pointer is before the first record, this method returns
268 '-1'.
269  
270 =cut
271  
272 0 ▶ sub index() {
Subroutine index: not called CC=2 SCAR=17.9
Pod documented
273 0 my $self = shift;
274 0 my $return_val = undef;
275  
276 0 ▶ if ( defined ($self->{active_record}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'active_record'}) { } 0 0 0
277 0 $return_val = $self->{active_record};
278 }
279 else {
280 0 $return_val = undef;
281 }
282 0 return $return_val;
283 }
284  
285  
286 =item $result = $obj_instance->seekIndex($num);
287  
288 This method selects a record by record order index. The C<$num> ordered
289 record is selected. If C<$num> is out of range for the database or not -1
290 (indicating to seek one record before the first record), this
291 function returns undefined and the active record pointer is not changed.
292 Otherwise, the requested record is made active and the method returns 1.
293  
294 =cut
295  
296 0 ▶ sub seekIndex($) {
Subroutine seekIndex: not called CC=6 SCAR=37.4
Pod documented
297 0 my $self = shift;
298 0 my $active_num = shift;
299 0 my $return_val;
300  
301 0 ▶ if ( (defined ($active_num) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $active_num and $active_num =~ /^\d+$/ || $active_num == -1 and $active_num < $self->count) { } 0 0 0
Condition0%0/9
defined $active_num and $active_num =~ /^\d+$/ || $active_num == -1 and $active_num < $self->count
!ll&&!rl&&r
000
defined $active_num and $active_num =~ /^\d+$/ || $active_num == -1
!ll&&!rl&&r
000
$active_num =~ /^\d+$/ or $active_num == -1
l!l&&r!l&&!r
000
MC/DC0%0/4
defined $active_num and $active_num =~ /^\d+$/ || $active_num == -1 and $active_num < $self->count
defined $active_num $active_num =~ /^\d+$/ $active_num == -1 $active_num < $self->count
Truth table0%0/6
A and B or C and D
A= defined $active_numB= $active_num =~ /^\d+$/C= $active_num == -1D= $active_num < $self->count
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
302 ( ($active_num =~ /^\d+$/) ||
303 ($active_num == -1 ) ) &&
304 ($active_num < $self->count()) ) {
305 0 $self->_errorHandler(
306 "Setting active record num to $active_num.",
307 $DEBUG_LEVEL_3, $SYS_ERR);
308 0 $self->{active_record} = $active_num;
309 0 $return_val = 1;
310 }
311 else {
312 0 ▶ if ( ! defined ($active_num) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $active_num) 0 0 0
313 0 $active_num = "<undefined>";
314 }
315 $self->_errorHandler(
316 0 "Cannot set active record num to $active_num, out of " .
317 $self->count(), $DEBUG_LEVEL_3, $SYS_ERR);
318 0 $return_val = undef;
319 }
320 0 return $return_val;
321 }
322
323  
324 =item $result = $obj_instance->next();
325  
326 This method selects the next record in numerical order to be the active
327 record. It returns the record on success, undefined on failure. If the active
328 record is equal to -1, the first record is selected.
329  
330 =cut
331  
332 0 ▶ sub next() {
Subroutine next: not called CC=2 SCAR=17.9
Pod documented
333 0 my $self = shift;
334 0 my $return_val = undef;
335  
336 0 ▶ if ( defined ( $self->hasNext() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->hasNext) { } 0 0 0
337 0 $self->{active_record}++;
338 0 $return_val = $self->get();
339 }
340 # set undefined if no more records left or no records at all
341 else {
342 0 $return_val = undef;
343 }
344  
345 0 return $return_val;
346 }
347  
348  
349 =item $result = $obj_instance->hasNext();
350  
351 This method returns true (1) if there are more elements beyond the
352 current element. If not, this method returns false (undefined).
353  
354 =cut
355  
356 0 ▶ sub hasNext() {
Subroutine hasNext: not called CC=4 SCAR=30.0
Pod documented
357 0 my $self = shift;
358 0 my $return_val = undef;
359  
360 0 ▶ if ( ( defined ($self->{active_record}) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'active_record'} and $self->{'active_record'} >= -1 and $self->{'active_record'} < $self->count - 1) { } 0 0 0
Condition0%0/6
defined $self->{"active_record"} and $self->{"active_record"} >= -1 and $self->{"active_record"} < $self->count - 1
!ll&&!rl&&r
000
defined $self->{"active_record"} and $self->{"active_record"} >= -1
!ll&&!rl&&r
000
MC/DC0%0/3
defined $self->{"active_record"} and $self->{"active_record"} >= -1 and $self->{"active_record"} < $self->count - 1
defined $self->{"active_record"} $self->{"active_record"} >= -1 $self->{"active_record"} < $self->count - 1
Truth table0%0/4
A and B and C
A= defined $self->{"active_record"}B= $self->{"active_record"} >= -1C= $self->{"active_record"} < $self->count - 1
ABCresult
0XX0
10X0
1100
1111
361 ( $self->{active_record} >= -1 ) &&
362 ( $self->{active_record} < ( $self->count() - 1 ) )
363 ) {
364 0 $return_val = 1;
365 }
366 else {
367 0 $return_val = undef;
368 }
369 0 return $return_val;
370 }
371  
372  
373 =item $result =
374 $obj_instance->getRecordByIdentifier($identifier);
375  
376 This method selects a record by record minimal identifier.
377 If C<$identifier> does not exist in the set of records, this function
378 returns undefined and the previously active record remains active. Otherwise,
379 the requested record is made active and the method returns a
380 C<TIGR::FASTA::Record> object representation of the current(active) record.
381  
382 =cut
383  
384 0 ▶ sub getRecordByIdentifier($) {
Subroutine getRecordByIdentifier: not called CC=4 SCAR=30.0
Pod documented
385
386 0 my $self = shift;
387 0 my $identifier = shift;
388 0 my $fasta_record = undef;
389 0 my $seek_result = undef;
390 0 ▶ if((defined $identifier)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $identifier) { } 0 0 0
391
392 0 my $seek_result = $self->seekIdentifier($identifier);
393 0 ▶ if( (defined ($seek_result)) && ($seek_result == 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $seek_result and $seek_result == 1) 0 0 0
Condition0%0/3
defined $seek_result and $seek_result == 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $seek_result and $seek_result == 1
defined $seek_result $seek_result == 1
Truth table0%0/3
A and B
A= defined $seek_resultB= $seek_result == 1
ABresult
0X0
100
111
394 0 $fasta_record = $self->get();
395 }
396 }
397 else {
398 0 $self->_errorHandler("undefined identifier passed", $DEBUG_LEVEL_3,
399 $USR_ERR);
400 }
401 0 return $fasta_record;
402 }
403
404  
405 =item $result = $obj_instance->seekIdentifier($identifier);
406  
407 This method selects a record by record minimal identifier.
408 If C<$identifier> does not exist in the set of records, this function
409 returns undefined and the previously active record remains active. Otherwise,
410 the requested record is made active and the method returns 1.
411  
412 =cut
413  
414 0 ▶ sub seekIdentifier($) {
Subroutine seekIdentifier: not called CC=3 SCAR=24.8
Pod documented
415 0 my $self = shift;
416 0 my $identifier = shift;
417 0 my $number = undef;
418  
419 0 ▶ if ( (defined $identifier) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $identifier and exists $self->{"identifier_to_number_hash"}{$identifier}) 0 0 0
Condition0%0/3
defined $identifier and exists $self->{"identifier_to_number_hash"}{$identifier}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $identifier and exists $self->{"identifier_to_number_hash"}{$identifier}
defined $identifier exists $self->{"identifier_to_number_hash"}{$identifier}
Truth table0%0/3
A and B
A= defined $identifierB= exists $self->{"identifier_to_number_hash"}{$identifier}
ABresult
0X0
100
111
420 (exists $self->{identifier_to_number_hash}->{$identifier}) ) {
421 0 $number = $self->{identifier_to_number_hash}->{$identifier};
422 0 $self->_errorHandler(
423 "Got record number $number for $identifier.", $DEBUG_LEVEL_3,
424 $SYS_ERR);
425 }
426 0 return $self->seekIndex($number);
427 }
428
429  
430 =item $record_contents = $obj_instance->get();
431  
432 This method returns a C<TIGR::FASTA::Record> object representation of the current
433 (active) record. If no defined record is active, this method returns
434 undefined.
435  
436 =cut
437  
438 0 ▶ sub get() {
Subroutine get: not called CC=12 SCAR=50.5
Pod documented
439 0 my $self = shift;
440 my $db_handle = defined ($self->{db_handle}) ?
441 0 ▶ $self->{db_handle} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'db_handle'} ? : 0 0 0
442 0 my $header = "";
443 0 my $data = "";
444 0 my $f_obj = undef;
445 0 my $pos_str = undef;
446 0 my @pos_arr = ();
447 0 my $record = undef;
448  
449 # open FASTA file for reading
450 0 ▶ if (! defined ($db_handle) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $db_handle) 0 0 0
451 0 $self->_errorHandler("db_handle not defined: " .
452 "cannot access FASTA file \'$self->{db_file_name}\'.",
453 $DEBUG_LEVEL_3);
454 }
455  
456 # search and extract the FASTA record
457 0 ▶ if (( defined ( $self->{active_record} )) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"active_record"} and $self->{"active_record"} > -1 and $self->{"active_record"} < $self->count and defined $db_handle and defined($pos_str = $self->{"number_to_fp_array"}{$self->{"active_record"}})) 0 0 0
Condition0%0/12
defined $self->{"active_record"} and $self->{"active_record"} > -1 and $self->{"active_record"} < $self->count and defined $db_handle and defined($pos_str = $self->{"number_to_fp_array"}{$self->{"active_record"}})
!ll&&!rl&&r
000
defined $self->{"active_record"} and $self->{"active_record"} > -1 and $self->{"active_record"} < $self->count and defined $db_handle
!ll&&!rl&&r
000
defined $self->{"active_record"} and $self->{"active_record"} > -1 and $self->{"active_record"} < $self->count
!ll&&!rl&&r
000
defined $self->{"active_record"} and $self->{"active_record"} > -1
!ll&&!rl&&r
000
MC/DC0%0/5
defined $self->{"active_record"} and $self->{"active_record"} > -1 and $self->{"active_record"} < $self->count and defined $db_handle and defined($pos_str = $self->{"number_to_fp_array"}{$self->{"active_record"}})
defined $self->{"active_record"} $self->{"active_record"} > -1 $self->{"active_record"} < $self->count defined $db_handle defined($pos_str = $self->{"number_to_fp_array"}{$self->{"active_record"}})
Truth table0%0/6
A and B and C and D and E
A= defined $self->{"active_record"}B= $self->{"active_record"} > -1C= $self->{"active_record"} < $self->countD= defined $db_handleE= defined($pos_str = $self->{"number_to_fp_array"}{$self->{"active_record"}})
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
458 ( $self->{active_record} > -1 ) &&
459 ( $self->{active_record} < $self->count() ) &&
460 ( defined ( $db_handle )) &&
461 ( defined ( $pos_str =
462 $self->{number_to_fp_array}->{$self->{active_record}} ))
463 ) {
464 0 @pos_arr = split " ", $pos_str;
465  
466 # seek to the start position of the record in the file and read the
467 # record information
468 0 ▶ if((defined $pos_arr[0]) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos_arr[0] and defined $db_handle->seek($pos_arr[0], 0) and defined $pos_arr[1] and defined read($db_handle, $record, $pos_arr[1] - $pos_arr[0] + 1)) 0 0 0
Condition0%0/9
defined $pos_arr[0] and defined $db_handle->seek($pos_arr[0], 0) and defined $pos_arr[1] and defined read($db_handle, $record, $pos_arr[1] - $pos_arr[0] + 1)
!ll&&!rl&&r
000
defined $pos_arr[0] and defined $db_handle->seek($pos_arr[0], 0) and defined $pos_arr[1]
!ll&&!rl&&r
000
defined $pos_arr[0] and defined $db_handle->seek($pos_arr[0], 0)
!ll&&!rl&&r
000
MC/DC0%0/4
defined $pos_arr[0] and defined $db_handle->seek($pos_arr[0], 0) and defined $pos_arr[1] and defined read($db_handle, $record, $pos_arr[1] - $pos_arr[0] + 1)
defined $pos_arr[0] defined $db_handle->seek($pos_arr[0], 0) defined $pos_arr[1] defined read($db_handle, $record, $pos_arr[1] - $pos_arr[0] + 1)
Truth table0%0/5
A and B and C and D
A= defined $pos_arr[0]B= defined $db_handle->seek($pos_arr[0], 0)C= defined $pos_arr[1]D= defined read($db_handle, $record, $pos_arr[1] - $pos_arr[0] + 1)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
469 (defined($db_handle->seek($pos_arr[0],SEEK_SET))) &&
470 (defined $pos_arr[1]) &&
471 (defined (read $db_handle, $record,
472 (($pos_arr[1]-$pos_arr[0])+1)))) {
473
474 0 ($header) = $record =~ /(>.*)\n/;
475 0 $record =~ s/(>.*)\n//;
476 0 $record =~ s/[\s\n]+//g;
477 0 $f_obj = new TIGR::FASTA::Record $header, $record;
478 }
479 }
480 0 return $f_obj;
481 }
482
483  
484 =item $db_name = $obj_instance->path();
485  
486 This method returns the path to the file used for processing.
487  
488 =cut
489  
490 0 ▶ sub path() {
Subroutine path: not called CC=1 SCAR=6.9
Pod documented
491 0 my $self = shift;
492 # the existence of db_file_name is checked in new()
493 0 return $self->{db_file_name};
494 }
495  
496  
497 =item $cnt = $obj_instance->count();
498  
499 This method returns the number of records in the database file.
500  
501 =cut
502  
503 0 ▶ sub count() {
Subroutine count: not called CC=1 SCAR=6.9
Pod documented
504 0 my $self = shift;
505 0 return $self->{num_records};
506 }
507  
508  
509 # $obj_instance->_initialize();
510  
511 #This method resets the object to its initial state. Internal data structures
512 #are reset. This method does not return.
513  
514 0 ▶ sub _initialize() {
Subroutine _initialize: not called CC=1 SCAR=6.9
515 0 my $self = shift;
516  
517 0 $self->{num_records} = 0; # number of recs
518  
519 # look up methods for records here
520 # the active record is stored as a sequence number
521 0 $self->{active_record} = undef; # current working record
522 0 $self->{number_to_fp_array} = (); # map seq# to file loc
523 0 $self->{number_to_identifier_array} = (); # map seq# to identifier
524 0 $self->{identifier_to_number_hash} = (); # map seq identifier to seq#
525 0 $self->{error_cnt} = 0; # parse error tabulator
526 0 $self->{db_file_name} = "";
527 0 $self->{db_handle} = undef;
528 }
529  
530  
531 # $obj_instance->_parseDBfile();
532  
533 #This method parses the FASTA database file passed via the C<open()> method.
534 #It defines all of the sequence look-ups and validates every record. This
535 #method finds the number of sequences and maximum sequence length. This
536 #method is called from the C<open()> method. The active record is un-selected
537 #by this method.
538  
539 0 ▶ sub _parseDBfile() {
Subroutine _parseDBfile: not called CC=34 SCAR=70.8
540 0 my $self = shift;
541 0 my $last_line_length_lt_std_flag = 0;
542 0 my $line_number = 0;
543 0 my $record_identifier = "<undefined>";
544 0 my $preceding_header_flag = 0;
545 0 my $first_data_line_length = undef;
546 0 my $empty_line_found = 0;
547 my $db_handle = defined ( $self->{db_handle} ) ?
548 0 ▶ $self->{db_handle} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'db_handle'} ? : 0 0 0
549 #the file position where the record starts
550 0 my $pos1 = 0;
551 #the file position where the record ends
552 0 my $pos2 = undef;
553 #the start and end positions of a record separated with a space
554 0 my $string = "";
555 # variable to give the length of each line
556 0 my $line_len = undef;
557 # the sum of the length of all the lines in a file
558 0 my $sum_len = 0;
559 # loop through FASTA file
560 0 ▶ while ( ( defined ( $db_handle ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $db_handle and defined(my $line = readline $db_handle) and ++$line_number) 0 0 0
Condition0%0/6
defined $db_handle and defined(my $line = readline $db_handle) and ++$line_number
!ll&&!rl&&r
000
defined $db_handle and defined(my $line = readline $db_handle)
!ll&&!rl&&r
000
MC/DC0%0/3
defined $db_handle and defined(my $line = readline $db_handle) and ++$line_number
defined $db_handle defined(my $line = readline $db_handle) ++$line_number
Truth table0%0/4
A and B and C
A= defined $db_handleB= defined(my $line = readline $db_handle)C= ++$line_number
ABCresult
0XX0
10X0
1100
1111
561 ( defined ( my $line = <$db_handle> ) ) &&
562 ( ++$line_number ) ) {
563 0 chomp $line;
564 0 $line_len = length($line);
565 0 $sum_len += $line_len;
566 0 $sum_len++;
567
568 # check FASTA data
569 0 ▶ if ( ( defined ( $record_identifier ) ) &&
Branch: 3 branches
BranchTrueFalseTotal
if (defined $record_identifier and not $record_identifier =~ /<undefined>/ and &isValidFASTAdata($line) != 0) { } 0 0 0
elsif (&isValidFASTAheader($line) != 0) { } 0 0 0
elsif ($line eq '') { } 0 0 0
Condition0%0/6
defined $record_identifier and not $record_identifier =~ /<undefined>/ and &isValidFASTAdata($line) != 0
!ll&&!rl&&r
000
defined $record_identifier and not $record_identifier =~ /<undefined>/
!ll&&!rl&&r
000
MC/DC0%0/3
defined $record_identifier and not $record_identifier =~ /<undefined>/ and &isValidFASTAdata($line) != 0
defined $record_identifier not $record_identifier =~ /<undefined>/ &isValidFASTAdata($line) != 0
Truth table0%0/4
A and not(B) and C
A= defined $record_identifierB= not $record_identifier =~ /<undefined>/C= &isValidFASTAdata($line) != 0
ABCresult
0XX0
10X0
1100
1111
570 ( $record_identifier !~ /<undefined>/ ) &&
571 ( ( isValidFASTAdata($line) ) != 0 ) ) {
572
573 # check if previous line was empty
574 0 ▶ if ( $empty_line_found == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($empty_line_found == 1) 0 0 0
575 0 $self->{error_cnt}++;
576 0 $self->_errorHandler("ERROR: Empty line found at line ".
577 ($line_number - 1). " - empty lines are ".
578 "allowed only at the end of a file",
579 $DEBUG_LEVEL_5, $USR_ERR);
580 0 $empty_line_found = 0;
581 }
582
583 0 ▶ if($preceding_header_flag == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($preceding_header_flag == 1) 0 0 0
584 0 $first_data_line_length = setValidFASTAlineLength($line);
585 }
586
587 # check $last_line_length_lt_std_flag for an error on previous line
588 0 ▶ if(defined ($first_data_line_length)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $first_data_line_length) 0 0 0
589 0 ▶ if ( $last_line_length_lt_std_flag == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_line_length_lt_std_flag == 1) 0 0 0
590 0 $self->{error_cnt}++;
591 0 $self->_errorHandler("Expected: FASTA data definition " .
592 "lines should be $first_data_line_length bases " .
593 "(characters) across. Only the last line of a sequence ".
594 "data definition may be less than " .
595 "$first_data_line_length bases (characters) " .
596 "across, if applicable. See line " .
597 ($line_number - 1) . '.', $DEBUG_LEVEL_5, $USR_ERR);
598 }
599 0 $last_line_length_lt_std_flag = 0;
600
601 # check current line for over-length problem
602 0 ▶ if ( $line_len > $first_data_line_length ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line_len > $first_data_line_length) { } 0 0 0
elsif ($line_len < $first_data_line_length) { } 0 0 0
603 0 $self->{error_cnt}++;
604 0 $self->_errorHandler("Expected: FASTA data definition " .
605 "lines should be $first_data_line_length bases " .
606 "(characters) across. Only the last line of a sequence ".
607 "data definition may be less than " .
608 "$first_data_line_length bases (characters) ".
609 "across, if applicable. See line " . $line_number . '.',
610 $DEBUG_LEVEL_5,$USR_ERR);
611 }
612
613 #check current line for under-length problem; report only if not
614 #the last line in the data definition
615 elsif ( $line_len < $first_data_line_length ) {
616 0 $last_line_length_lt_std_flag = 1;
617 }
618 }
619 0 $preceding_header_flag = 0;
620 }
621 # check for FASTA header
622 elsif ( ( isValidFASTAheader($line) ) != 0 ) {
623 0 ▶ if ( ! defined ( $self->{active_record} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"active_record"}) 0 0 0
624 0 $self->{active_record} = -1;
625 }
626
627 0 $self->{active_record}++;
628
629 0 ▶ if( (defined $line_number) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line_number and $line_number > 1) 0 0 0
Condition0%0/3
defined $line_number and $line_number > 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $line_number and $line_number > 1
defined $line_number $line_number > 1
Truth table0%0/3
A and B
A= defined $line_numberB= $line_number > 1
ABresult
0X0
100
111
630 ($line_number > 1) ) {
631 0 $pos2 = (($sum_len - $line_len)-2);
632 0 $pos1 = $pos2+1;
633  
634 0 ▶ if((defined $pos1) && ( defined $string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos1 and defined $string) 0 0 0
Condition0%0/3
defined $pos1 and defined $string
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pos1 and defined $string
defined $pos1 defined $string
Truth table0%0/3
A and B
A= defined $pos1B= defined $string
ABresult
0X0
100
111
635 0 $string .= "$pos2";
636 # store the start and end of a fasta record in a hash
637 0 $self->{number_to_fp_array}->{($self->{active_record})-1} =
638 $string;
639 }
640 }
641
642 0 ▶ if(defined $pos1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos1) 0 0 0
643 0 $string = "$pos1 ";
644 }
645
646 # check if previous line was a FASTA header
647 0 ▶ if ( $preceding_header_flag == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($preceding_header_flag == 1) 0 0 0
648 0 $self->_nullRecordHandler($self->{active_record} - 1,
649 $line_number);
650 }
651
652 # check if previous line was empty
653 0 ▶ if ( $empty_line_found == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($empty_line_found == 1) 0 0 0
654 0 $self->{error_cnt}++;
655 0 $self->_errorHandler("ERROR: Empty line found at line ".
656 ($line_number - 1). " - empty lines are ".
657 "allowed only at the end of a file",
658 $DEBUG_LEVEL_5, $USR_ERR);
659 0 $empty_line_found = 0;
660 }
661 # if it's a valid FASTA header, then don't need to check again
662 # extract the record IDENTIFIER
663 0 $record_identifier = _headerToIdentifier($line);
664 0 ▶ if ( defined (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'identifier_to_number_hash'}{$record_identifier}) { } 0 0 0
665 $self->{identifier_to_number_hash}->{$record_identifier} ) ) {
666 0 $self->{error_cnt}++;
667 0 $self->_errorHandler("Expected: unique FASTA " .
668 "identifier. \'$record_identifier\' is a duplicate at " .
669 "line $line_number.", $DEBUG_LEVEL_5, $USR_ERR);
670 }
671 else {
672 $self->{identifier_to_number_hash}->{$record_identifier} =
673 0 $self->{active_record};
674 $self->{number_to_identifier_array}->{$self->{active_record}} =
675 0 $record_identifier;
676 }
677  
678 # set up the variables for parsing a new record
679 0 $last_line_length_lt_std_flag = 0;
680 0 $preceding_header_flag = 1;
681 0 $self->{num_records}++;
682 }
683 # handle empty space
684 # empty space after the last record is allowed
685 elsif($line eq "") {
686 0 $empty_line_found = 1;
687 0 next;
688 }
689 # handle error data types
690 else {
691 0 $self->{error_cnt}++;
692 # check if previous line was empty
693 0 ▶ if ( $empty_line_found == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($empty_line_found == 1) 0 0 0
694 0 $self->{error_cnt}++;
695 0 $self->_errorHandler("ERROR: Empty line found at line ".
696 ($line_number - 1). " - empty lines are ".
697 "allowed only at the end of a file",
698 $DEBUG_LEVEL_5, $USR_ERR);
699 0 $empty_line_found = 0;
700 }
701
702 # line has a separator token in it, so it may be header
703 0 ▶ if ( $line =~ /$UNBOUND_FASTA_SEPARATOR/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($line =~ /$UNBOUND_FASTA_SEPARATOR/) { } 0 0 0
elsif ($last_line_length_lt_std_flag == 1) { } 0 0 0
elsif (defined $record_identifier and not $record_identifier =~ /<undefined>/) { } 0 0 0
704 0 $self->_errorHandler("Expected: record header " .
705 "information in FASTA record header. Got: \'$line\' at " .
706 "line $line_number.", $DEBUG_LEVEL_6, $USR_ERR);
707 0 $last_line_length_lt_std_flag = 0;
708 }
709 # if last data line was small, expect this to be a header too
710 elsif ( $last_line_length_lt_std_flag == 1 ) {
711 0 $self->_errorHandler("Expected: FASTA record header " .
712 "beginning with \'>\'. Got: \'$line\' at line ".
713 "$line_number.",$DEBUG_LEVEL_6, $USR_ERR);
714 0 $last_line_length_lt_std_flag = 0;
715 }
716 ▶ elsif ( ( defined ( $record_identifier ) ) &&
Condition0%0/3
defined $record_identifier and not $record_identifier =~ /<undefined>/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record_identifier and not $record_identifier =~ /<undefined>/
defined $record_identifier not $record_identifier =~ /<undefined>/
Truth table0%0/3
A and not(B)
A= defined $record_identifierB= not $record_identifier =~ /<undefined>/
ABresult
0X0
100
111
717 ( $record_identifier !~ /<undefined>/ ) ) {
718 0 $self->_errorHandler("Expected: valid FASTA data " .
719 "definition for record identifier \'$record_identifier\'. " .
720 "Check sequence content at line $line_number for invalid " .
721 "bases (data type: invalid data).", $DEBUG_LEVEL_6,
722 $USR_ERR);
723 }
724 else {
725 0 $self->_errorHandler("Expected: FASTA record header " .
726 "followed by definition of sequence. Invalid input at " .
727 "line $line_number.", $DEBUG_LEVEL_6, $USR_ERR);
728 }
729 }
730 } # end while
731
732 0 $pos2 = $sum_len;
733 0 ▶ if((defined $pos1) && ( defined $string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos1 and defined $string) 0 0 0
Condition0%0/3
defined $pos1 and defined $string
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pos1 and defined $string
defined $pos1 defined $string
Truth table0%0/3
A and B
A= defined $pos1B= defined $string
ABresult
0X0
100
111
734 0 $string .= "$pos2";
735 # store the start and end of a fasta record in a hash
736 0 $self->{number_to_fp_array}->{$self->{active_record}} = $string;
737 }
738
739 # check terminal case data definition
740 0 ▶ if ( $preceding_header_flag == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($preceding_header_flag == 1) 0 0 0
741 0 $self->_nullRecordHandler($self->{active_record}, $line_number);
742 }
743
744 0 $self->{active_record} = -1; # set counter to the beginning
745
746 0 ▶ return ( $self->{error_cnt} == 0 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'error_cnt'} == 0 ? : 0 0 0
747 }
748  
749  
750 # $obj_instance->_nullRecordHandler($$);
751  
752 #This method handles the case of a null or equivalently empty record
753 #encountered during parsing. It logs the appropriate message to the
754 #TIGR Foundation object. The only arguments are the record number
755 #and the line number.
756  
757 0 ▶ sub _nullRecordHandler($$) {
Subroutine _nullRecordHandler: not called CC=8 SCAR=42.8
758 0 my $self = shift;
759 0 my $active_num = shift;
760 0 my $line_number = shift;
761 0 my $preceding_rec_line_number = undef;
762 0 my $record_identifier = undef;
763  
764 0 ▶ if ( defined ( $self->{number_to_identifier_array}->
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'number_to_identifier_array'}{$active_num}) { } 0 0 0
765 {$active_num} ) ) {
766 $record_identifier = $self->{number_to_identifier_array}->
767 0 {$active_num};
768 }
769 else {
770 0 $record_identifier = "<unknown>";
771 }
772
773 0 ▶ if(defined $line_number) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line_number) { } 0 0 0
774 0 ▶ if((defined $active_num) &&
Branch: 2 branches
BranchTrueFalseTotal
if (defined $active_num and $active_num < $self->{'active_record'}) { } 0 0 0
elsif (defined $active_num and $active_num == $self->{'active_record'}) { } 0 0 0
Condition0%0/3
defined $active_num and $active_num < $self->{"active_record"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $active_num and $active_num < $self->{"active_record"}
defined $active_num $active_num < $self->{"active_record"}
Truth table0%0/3
A and B
A= defined $active_numB= $active_num < $self->{"active_record"}
ABresult
0X0
100
111
775 ($active_num < ($self->{active_record}))) {
776 0 $preceding_rec_line_number = $line_number-1;
777 }
778 ▶ elsif((defined $active_num) &&
Condition0%0/3
defined $active_num and $active_num == $self->{"active_record"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $active_num and $active_num == $self->{"active_record"}
defined $active_num $active_num == $self->{"active_record"}
Truth table0%0/3
A and B
A= defined $active_numB= $active_num == $self->{"active_record"}
ABresult
0X0
100
111
779 ($active_num == ($self->{active_record}))) {
780 0 $preceding_rec_line_number = $line_number;
781 }
782 }
783 else {
784 0 $preceding_rec_line_number = "<unknown>";
785 }
786  
787 0 $self->{error_cnt}++;
788 0 ▶ if ( $self->{db_handle}->eof() == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'db_handle'}->eof == 1) { } 0 0 0
789 0 $self->_errorHandler("Expected: FASTA record header " .
790 "followed by definition of sequence. Record identifier " .
791 "\'" . $record_identifier . "\' is undefined from line " .
792 $preceding_rec_line_number . ". Got end of file after line " .
793 $line_number . ".", $DEBUG_LEVEL_5, $USR_ERR);
794 }
795 else {
796 0 $self->_errorHandler("Expected: FASTA record header " .
797 "followed by definition of sequence. Record identifier " .
798 "\'" . $record_identifier . "\' is undefined from line " .
799 $preceding_rec_line_number . ". Got FASTA header at line " .
800 $line_number . ".", $DEBUG_LEVEL_5, $USR_ERR);
801 }
802 }
803  
804  
805 # $message = $obj_instance->_errorHandler($message, $tf_level,
806 # $internal_log_flag);
807  
808 #This method handles logging to the TIGR::Foundation module and
809 #internal error record reference array. The C<$message> argument is logged
810 #to the appropriate service. The C<$tf_level> parameter specifies the
811 #logging level for TIGR::Foundation, while the C<$internal_log_flag> parameter
812 #specifies if C<$message> should be written to the internal array reference
813 #specified in C<new()>. If a TIGR::Foundation instance does not exist,
814 #no logging to that facility occurs. This method returns C<$message>.
815  
816 0 ▶ sub _errorHandler($$$) {
Subroutine _errorHandler: not called CC=8 SCAR=42.8
817
818 0 my $self = shift;
819  
820 0 my ( $message, $tf_level, $log_facility ) = @_;
821  
822 0 ▶ if ( defined ($message) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $message and defined $tf_level and defined $log_facility) 0 0 0
Condition0%0/6
defined $message and defined $tf_level and defined $log_facility
!ll&&!rl&&r
000
defined $message and defined $tf_level
!ll&&!rl&&r
000
MC/DC0%0/3
defined $message and defined $tf_level and defined $log_facility
defined $message defined $tf_level defined $log_facility
Truth table0%0/4
A and B and C
A= defined $messageB= defined $tf_levelC= defined $log_facility
ABCresult
0XX0
10X0
1100
1111
823 defined ($tf_level) &&
824 defined ($log_facility) ) {
825  
826 0 ▶ if ( defined ($self->{foundation}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"foundation"}) 0 0 0
827 0 ▶ if ( $log_facility != $USR_ERR ) { # all user errors go to .error
Branch: 1 branch
BranchTrueFalseTotal
if ($log_facility != $USR_ERR) { } 0 0 0
828 0 $self->{foundation}->logLocal($message, $tf_level);
829 }
830 else {
831 0 $self->{foundation}->logError($message);
832 }
833 }
834  
835 0 ▶ if ( ( defined ($self->{error_ref}) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"error_ref"} and $log_facility == $USR_ERR) 0 0 0
Condition0%0/3
defined $self->{"error_ref"} and $log_facility == $USR_ERR
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"error_ref"} and $log_facility == $USR_ERR
defined $self->{"error_ref"} $log_facility == $USR_ERR
Truth table0%0/3
A and B
A= defined $self->{"error_ref"}B= $log_facility == $USR_ERR
ABresult
0X0
100
111
836 ( $log_facility == $USR_ERR ) ) {
837 0 push @{$self->{error_ref}}, $message;
838 }
839 }
840 0 return $message;
841 }
842  
843 =head1 USAGE
844  
845 To use this module, load the C<TIGR::FASTA::Reader> package via the
846 C<use> function. Then, create a new instance of the object via the
847 C<new()> method, as shown below. There are several invocations possible
848 for this method since all parameters to C<new()> are optional.
849 To access records from the C<TIGR::FASTA::Reader> instance, the
850 C<TIGR::FASTA::Record> package must be loaded via the C<use> function.
851 An example script using this module follows. The C<TIGR::Foundation>
852 module is included for completeness but does not have to be used.
853  
854 #!/usr/local/bin/perl -w
855  
856 # This script accepts FASTA files with the '-i' option
857 # on the command line and validates every one in turn.
858 # Parse errors are collected to the '@errors_list' array.
859 # This program concatenates all of the records together to
860 # one output file specified with the '-o' option.
861 # NOTE: The '-i' option must be specified before every input file.
862 # NOTE: The 'TIGR::FASTA::Writer' module is intended for writing
863 # FASTA records.
864  
865 use strict;
866 use TIGR::FASTA::Reader;
867 use TIGR::FASTA::Record;
868  
869 MAIN:
870 {
871 my $tf_object = new TIGR::Foundation;
872 my @errors_list = ();
873 my @input_files = ();
874 my $output_file = undef;
875  
876 # Capture the return code from the TIGR::Foundation method
877 my $result = $tf_object->TIGR_GetOptions('i=s' => \@input_files,
878 'o=s' => \$output_file);
879 if ( $result != 1 ) {
880 $tf_object->bail("Invalid command line options.");
881 }
882  
883 # Create a TIGR::FASTA::Reader instance using TIGR::Foundation and
884 # an error message list.
885 my $fasta_reader = new TIGR::FASTA::Reader $tf_object, \@errors_list;
886  
887 if ( !( defined ( $output_file ) &&
888 open OUTFILE, ">$output_file" ) ) {
889 $tf_object->bail("Cannot open output file for writing.");
890 }
891  
892 foreach my $in_file ( @input_files ) {
893 $fasta_reader->open($in_file) or
894 $tf_object->logLocal("Cannot open or read file $in_file", 2);
895  
896 if ( scalar(@errors_list) > 0 ) { # are there parse errors?
897 while ( @errors_list ) { # get the messages from the list
898 my $message = shift @errors_list;
899 print STDERR $message, "\n";
900 }
901 }
902  
903 while ( $fasta_reader->hasNext() ) {
904 # print each record to OUTFILE
905 print OUTFILE $fasta_reader->next()->toString();
906 }
907 }
908 }
909  
910 =cut
911  
912 }
913  
914 1 1;
« lib/TIGR/HmmTools.pm ↑ Summary lib/TIGR/FASTA/Iterator.pm »