SeqFeature/Store/Loader.pm

filter: Statementstmt 14.1% 32 / 227 Branchbran 0.0% 0 / 88 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 21.2% 10 / 47 Podpod 67.6% 23 / 34 totaltotal 14.2% 65 / 455 CC 59 SCAR 40.8
CC
59
Cov
9%
new
272.0
DESTROY
90.0
open_fh
52.9
CRAP 58.9
« SeqFeature/NormalizedFeature.pm ↑ Summary SeqFeature.pm »
1 package Bio::DB::SeqFeature::Store::Loader;
2 2 $Bio::DB::SeqFeature::Store::Loader::VERSION = '1.7.5';
3  
4 =head1 NAME
5  
6 Bio::DB::SeqFeature::Store::Loader -- Loader
7  
8 =head1 SYNOPSIS
9  
10 # non-instantiable base class
11  
12 =head1 DESCRIPTION
13  
14 This is the base class for Bio::DB::SeqFeature::Loader::GFF3Loader,
15 Bio::DB::SeqFeature::Loader::GFFLoader, and
16 Bio::DB::SeqFeature::FeatureFileLoader. Please see the manual pages
17 for these modules.
18  
19 =cut
20  
21  
22 # load utility - incrementally load the store based on GFF3 file
23 #
24 # two modes:
25 # slow mode -- features can occur in any order in the GFF3 file
26 # fast mode -- all features with same ID must be contiguous in GFF3 file
27  
28 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶use Bio::DB::GFF::Util::Rearrange;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use Bio::DB::SeqFeature::Store;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use File::Temp 'tempdir';
Subroutine BEGIN: called CC=1 SCAR=0.0
35 2 ▶use base 'Bio::Root::Root';
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 2 ▶use constant DEFAULT_SEQ_CHUNK_SIZE => 2000;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 =head2 new
40  
41 Title : new
42 Usage : $loader = Bio::DB::SeqFeature::Store::GFF3Loader->new(@options)
43 Function: create a new parser
44 Returns : a Bio::DB::SeqFeature::Store::GFF3Loader gff3 parser and loader
45 Args : several - see below
46 Status : public
47  
48 This method creates a new GFF3 loader and establishes its connection
49 with a Bio::DB::SeqFeature::Store database. Arguments are -name=E<gt>$value
50 pairs as described in this table:
51  
52 Name Value
53 ---- -----
54  
55 -store A writable Bio::DB::SeqFeature::Store database handle.
56  
57 -seqfeature_class The name of the type of Bio::SeqFeatureI object to create
58 and store in the database (Bio::DB::SeqFeature by default)
59  
60 -sf_class A shorter alias for -seqfeature_class
61  
62 -verbose Send progress information to standard error.
63  
64 -fast If true, activate fast loading (see below)
65  
66 -chunk_size Set the storage chunk size for nucleotide/protein sequences
67 (default 2000 bytes)
68  
69 -tmp Indicate a temporary directory to use when loading non-normalized
70 features.
71  
72 -map_coords A code ref that will transform a list of ($ref,[$start1,$end1]...)
73 coordinates into a list of ($newref,[$newstart1,$newend1]...)
74  
75 -index_subfeatures Indicate true if subfeatures should be indexed. Default is true.
76  
77 -summary_stats Rebuild summary stats at the end of loading (not incremental,
78 so takes a long time)
79  
80 When you call new(), a connection to a Bio::DB::SeqFeature::Store
81 database should already have been established and the database
82 initialized (if appropriate).
83  
84 Some combinations of Bio::SeqFeatures and Bio::DB::SeqFeature::Store
85 databases support a fast loading mode. Currently the only reliable
86 implementation of fast loading is the combination of DBI::mysql with
87 Bio::DB::SeqFeature. The other important restriction on fast loading
88 is the requirement that a feature that contains subfeatures must occur
89 in the GFF3 file before any of its subfeatures. Otherwise the
90 subfeatures that occurred before the parent feature will not be
91 attached to the parent correctly. This restriction does not apply to
92 normal (slow) loading.
93  
94 If you use an unnormalized feature class, such as
95 Bio::SeqFeature::Generic, then the loader needs to create a temporary
96 database in which to cache features until all their parts and subparts
97 have been seen. This temporary databases uses the "berkeleydb" adaptor. The
98 -tmp option specifies the directory in which that database will be
99 created. If not present, it defaults to the system default tmp
100 directory specified by File::Spec-E<gt>tmpdir().
101  
102 The -chunk_size option allows you to tune the representation of
103 DNA/Protein sequence in the Store database. By default, sequences are
104 split into 2000 base/residue chunks and then reassembled as
105 needed. This avoids the problem of pulling a whole chromosome into
106 memory in order to fetch a short subsequence from somewhere in the
107 middle. Depending on your usage patterns, you may wish to tune this
108 parameter using a chunk size that is larger or smaller than the
109 default.
110  
111 =cut
112  
113 0 ▶sub new {
Subroutine new: not called CC=16 SCAR=56.1
Pod documented
114 0 my $self = shift;
115 0 my ($store,$seqfeature_class,$tmpdir,$verbose,$fast,
116 $seq_chunk_size,$coordinate_mapper,$index_subfeatures,$summary_stats,$no_close_fasta) =
117 rearrange(['STORE',
118 ['SF_CLASS','SEQFEATURE_CLASS'],
119 ['TMP','TMPDIR'],
120 'VERBOSE',
121 'FAST',
122 'CHUNK_SIZE',
123 'MAP_COORDS',
124 'INDEX_SUBFEATURES',
125 'SUMMARY_STATS',
126 'NO_CLOSE_FASTA',
127 ],@_);
128  
129  
130 0 ▶ $seqfeature_class ||= $self->default_seqfeature_class;
Condition0%0/3
$seqfeature_class ||= $self->default_seqfeature_class
l!l&&r!l&&!r
000
MC/DC0%0/2
$seqfeature_class ||= $self->default_seqfeature_class
$seqfeature_class $self->default_seqfeature_class
Truth table0%0/3
A ||= B
A= $seqfeature_classB= $self->default_seqfeature_class
ABresult
1X1
011
000
131 0 ▶ eval "require $seqfeature_class" unless $seqfeature_class->can('new');
Branch: 1 branch
BranchTrueFalseTotal
unless $seqfeature_class->can("new") 0 0 0
132 0 ▶ $self->throw($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
133  
134 0 ▶ my $normalized = $seqfeature_class->can('subfeatures_are_normalized')
Condition0%0/3
$seqfeature_class->can('subfeatures_are_normalized') && $seqfeature_class->subfeatures_are_normalized
!ll&&!rl&&r
000
MC/DC0%0/2
$seqfeature_class->can('subfeatures_are_normalized') && $seqfeature_class->subfeatures_are_normalized
$seqfeature_class->can('subfeatures_are_normalized') $seqfeature_class->subfeatures_are_normalized
Truth table0%0/3
A && B
A= $seqfeature_class->can('subfeatures_are_normalized')B= $seqfeature_class->subfeatures_are_normalized
ABresult
0X0
100
111
135 && $seqfeature_class->subfeatures_are_normalized;
136  
137 0 ▶ my $in_table = $seqfeature_class->can('subfeatures_are_stored_in_a_table')
Condition0%0/3
$seqfeature_class->can('subfeatures_are_stored_in_a_table') && $seqfeature_class->subfeatures_are_stored_in_a_table
!ll&&!rl&&r
000
MC/DC0%0/2
$seqfeature_class->can('subfeatures_are_stored_in_a_table') && $seqfeature_class->subfeatures_are_stored_in_a_table
$seqfeature_class->can('subfeatures_are_stored_in_a_table') $seqfeature_class->subfeatures_are_stored_in_a_table
Truth table0%0/3
A && B
A= $seqfeature_class->can('subfeatures_are_stored_in_a_table')B= $seqfeature_class->subfeatures_are_stored_in_a_table
ABresult
0X0
100
111
138 && $seqfeature_class->subfeatures_are_stored_in_a_table;
139  
140 0 ▶ if ($fast) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fast) 0 0 0
141 0 ▶ my $canfast = $normalized && $in_table;
Condition0%0/3
$normalized && $in_table
!ll&&!rl&&r
000
MC/DC0%0/2
$normalized && $in_table
$normalized $in_table
Truth table0%0/3
A && B
A= $normalizedB= $in_table
ABresult
0X0
100
111
142 0 ▶ warn <<END unless $canfast;
Branch: 1 branch
BranchTrueFalseTotal
unless $canfast 0 0 0
143 Only features that support the Bio::DB::SeqFeature::NormalizedTableFeature interface
144 can be loaded using the -fast method. Reverting to slower feature-by-feature method.
145 END
146 0 ▶ $fast &&= $canfast;
Condition0%0/3
$fast &&= $canfast
!ll&&!rl&&r
000
MC/DC0%0/2
$fast &&= $canfast
$fast $canfast
Truth table0%0/3
A &&= B
A= $fastB= $canfast
ABresult
0X0
100
111
147 }
148  
149 # try to bring in highres time() function
150 0 eval "require Time::HiRes";
151  
152 0 ▶ $tmpdir ||= File::Spec->tmpdir();
Condition0%0/3
$tmpdir ||= "File::Spec"->tmpdir
l!l&&r!l&&!r
000
MC/DC0%0/2
$tmpdir ||= "File::Spec"->tmpdir
$tmpdir "File::Spec"->tmpdir
Truth table0%0/3
A ||= B
A= $tmpdirB= "File::Spec"->tmpdir
ABresult
1X1
011
000
153  
154 0 my ($tmp_store,$temp_load);
155 0 ▶ unless ($normalized) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($normalized) 0 0 0
156  
157 # remember the temporary directory in order to delete it on exit
158 0 $temp_load = tempdir(
159 'BioDBSeqFeature_XXXXXXX',
160 DIR=>$tmpdir,
161 CLEANUP=>1
162 );
163  
164 0 ▶ $tmp_store = Bio::DB::SeqFeature::Store->new(-adaptor => 'berkeleydb',
Branch: 1 branch
BranchTrueFalseTotal
unless $normalized 0 0 0
165 -temporary=> 1,
166 -dsn => $temp_load,
167 -cache => 1,
168 -write => 1)
169 unless $normalized;
170 }
171  
172 0 ▶ $index_subfeatures = 1 unless defined $index_subfeatures;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index_subfeatures 0 0 0
173  
174 0 ▶ return bless {
Condition0%0/5
$seq_chunk_size || 2000
l!l
00
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/1
$seq_chunk_size || 2000
$seq_chunk_size
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/2
A
A= $seq_chunk_size
Aresult
11
00
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
175 store => $store,
176 tmp_store => $tmp_store,
177 seqfeature_class => $seqfeature_class,
178 fast => $fast,
179 seq_chunk_size => $seq_chunk_size || DEFAULT_SEQ_CHUNK_SIZE,
180 verbose => $verbose,
181 load_data => {},
182 tmpdir => $tmpdir,
183 temp_load => $temp_load,
184 subfeatures_normalized => $normalized,
185 subfeatures_in_table => $in_table,
186 coordinate_mapper => $coordinate_mapper,
187 index_subfeatures => $index_subfeatures,
188 summary_stats => $summary_stats,
189 no_close_fasta => $no_close_fasta,
190 },ref($self) || $self;
191 }
192  
193 0 ▶sub coordinate_mapper {
Subroutine coordinate_mapper: not called CC=2 SCAR=17.9
Pod undocumented
194 0 my $self = shift;
195 0 my $d = $self->{coordinate_mapper};
196 0 ▶ $self->{coordinate_mapper} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
197 0 $d;
198 }
199  
200 0 ▶sub index_subfeatures {
Subroutine index_subfeatures: not called CC=2 SCAR=17.9
Pod undocumented
201 0 my $self = shift;
202 0 my $d = $self->{index_subfeatures};
203 0 ▶ $self->{index_subfeatures} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
204 0 $d;
205 }
206  
207  
208 0 ▶sub summary_stats {
Subroutine summary_stats: not called CC=2 SCAR=17.9
Pod undocumented
209 0 my $self = shift;
210 0 my $d = $self->{summary_stats};
211 0 ▶ $self->{summary_stats} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
212 0 $d;
213 }
214  
215 =head2 load
216  
217 Title : load
218 Usage : $count = $loader->load(@ARGV)
219 Function: load the indicated files or filehandles
220 Returns : number of feature lines loaded
221 Args : list of files or filehandles
222 Status : public
223  
224 Once the loader is created, invoke its load() method with a list of
225 GFF3 or FASTA file paths or previously-opened filehandles in order to
226 load them into the database. Compressed files ending with .gz, .Z and
227 .bz2 are automatically recognized and uncompressed on the fly. Paths
228 beginning with http: or ftp: are treated as URLs and opened using the
229 LWP GET program (which must be on your path).
230  
231 FASTA files are recognized by their initial "E<gt>" character. Do not feed
232 the loader a file that is neither GFF3 nor FASTA; I don't know what
233 will happen, but it will probably not be what you expect.
234  
235 =cut
236  
237 0 ▶sub load {
Subroutine load: not called CC=4 SCAR=30.0
Pod documented
238 0 my $self = shift;
239 0 my $start = $self->time();
240 0 my $count = 0;
241  
242 0 for my $file_or_fh (@_) {
243 0 $self->msg("loading $file_or_fh...\n");
244 0 ▶ my $fh = $self->open_fh($file_or_fh) or $self->throw("Couldn't open $file_or_fh: $!");
Branch: 1 branch
BranchTrueFalseTotal
my $fh = $self->open_fh($file_or_fh) or $self->throw("Couldn't open ${file_or_fh}: $!") 0 0 0
245 0 $count += $self->load_fh($fh);
246 0 $self->msg(sprintf "load time: %5.2fs\n",$self->time()-$start);
247 }
248
249 0 ▶ if ($self->summary_stats) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->summary_stats) 0 0 0
250 0 $self->msg("Building summary statistics for coverage graphs...");
251 0 my $start = $self->time();
252 0 $self->build_summary;
253 0 $self->msg(sprintf "coverage graph build time: %5.2fs\n",$self->time()-$start);
254 }
255 0 $self->msg(sprintf "total load time: %5.2fs\n",$self->time()-$start);
256 0 $count;
257 }
258  
259 =head2 accessors
260  
261 The following read-only accessors return values passed or created during new():
262  
263 store() the long-term Bio::DB::SeqFeature::Store object
264  
265 tmp_store() the temporary Bio::DB::SeqFeature::Store object used
266 during loading
267  
268 sfclass() the Bio::SeqFeatureI class
269  
270 fast() whether fast loading is active
271  
272 seq_chunk_size() the sequence chunk size
273  
274 verbose() verbose progress messages
275  
276 =cut
277  
278 0 ▶sub store { shift->{store} }
Subroutine store: not called CC=1 SCAR=6.9
Pod undocumented
279 0 ▶sub tmp_store { shift->{tmp_store} }
Subroutine tmp_store: not called CC=1 SCAR=6.9
Pod undocumented
280 0 ▶sub sfclass { shift->{seqfeature_class} }
Subroutine sfclass: not called CC=1 SCAR=6.9
Pod undocumented
281 0 ▶sub fast { shift->{fast} }
Subroutine fast: not called CC=1 SCAR=6.9
Pod undocumented
282 0 ▶sub seq_chunk_size { shift->{seq_chunk_size} }
Subroutine seq_chunk_size: not called CC=1 SCAR=6.9
Pod undocumented
283 0 ▶sub verbose { shift->{verbose} }
Subroutine verbose: not called CC=1 SCAR=6.9
Pod documented
284  
285 =head2 Internal Methods
286  
287 The following methods are used internally and may be overridden by
288 subclasses.
289  
290 =over 4
291  
292 =item default_seqfeature_class
293  
294 $class = $loader->default_seqfeature_class
295  
296 Return the default SeqFeatureI class (Bio::DB::SeqFeature).
297  
298 =cut
299  
300 0 ▶sub default_seqfeature_class {
Subroutine default_seqfeature_class: not called CC=1 SCAR=6.9
Pod documented
301 0 my $self = shift;
302 0 return 'Bio::DB::SeqFeature';
303 }
304  
305 =item subfeatures_normalized
306  
307 $flag = $loader->subfeatures_normalized([$new_flag])
308  
309 Get or set a flag that indicates that the subfeatures are
310 normalized. This is deduced from the SeqFeature class information.
311  
312 =cut
313  
314 0 ▶sub subfeatures_normalized {
Subroutine subfeatures_normalized: not called CC=2 SCAR=17.9
Pod documented
315 0 my $self = shift;
316 0 my $d = $self->{subfeatures_normalized};
317 0 ▶ $self->{subfeatures_normalized} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
318 0 $d;
319 }
320  
321 =item subfeatures_in_table
322  
323 $flag = $loader->subfeatures_in_table([$new_flag])
324  
325 Get or set a flag that indicates that feature/subfeature relationships
326 are stored in a table. This is deduced from the SeqFeature class and
327 Store information.
328  
329 =cut
330  
331 0 ▶sub subfeatures_in_table {
Subroutine subfeatures_in_table: not called CC=2 SCAR=17.9
Pod documented
332 0 my $self = shift;
333 0 my $d = $self->{subfeatures_in_table};
334 0 ▶ $self->{subfeatures_in_table} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
335 0 $d;
336 }
337  
338 =item load_fh
339  
340 $count = $loader->load_fh($filehandle)
341  
342 Load the GFF3 data at the other end of the filehandle and return true
343 if successful. Internally, load_fh() invokes:
344  
345 start_load();
346 do_load($filehandle);
347 finish_load();
348  
349 =cut
350  
351 0 ▶sub load_fh {
Subroutine load_fh: not called CC=1 SCAR=6.9
Pod documented
352 0 my $self = shift;
353 0 my $fh = shift;
354 0 $self->start_load();
355 0 my $count = $self->do_load($fh);
356 0 $self->finish_load();
357 0 $count;
358 }
359  
360  
361 =item start_load, finish_load
362  
363 These methods are called at the start and end of a filehandle load.
364  
365 =cut
366  
367 0 ▶sub start_load {
Subroutine start_load: not called CC=2 SCAR=17.9
Pod documented
368 0 my $self = shift;
369 0 $self->create_load_data;
370 0 ▶ $self->store->start_bulk_update() if $self->fast;
Branch: 1 branch
BranchTrueFalseTotal
if $self->fast 0 0 0
371 }
372  
373 0 ▶sub create_load_data {
Subroutine create_load_data: not called CC=1 SCAR=6.9
Pod undocumented
374 0 my $self = shift;
375 0 $self->{load_data}{CurrentFeature} = undef;
376 0 $self->{load_data}{CurrentID} = undef;
377 0 $self->{load_data}{IndexIt} = {};
378 0 $self->{load_data}{Local2GlobalID} = {};
379 0 $self->{load_data}{count} = 0;
380 0 $self->{load_data}{mode} = undef;
381 0 $self->{load_data}{start_time} = 0;
382 }
383  
384 0 ▶sub delete_load_data {
Subroutine delete_load_data: not called CC=1 SCAR=6.9
Pod undocumented
385 0 my $self = shift;
386 0 delete $self->{load_data};
387 }
388  
389 0 ▶sub finish_load {
Subroutine finish_load: not called CC=2 SCAR=17.9
Pod documented
390 0 my $self = shift;
391  
392 0 $self->store_current_feature(); # during fast loading, we will have a feature left at the very end
393 0 $self->start_or_finish_sequence(); # finish any half-loaded sequences
394  
395 0 ▶ if ($self->fast) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fast) 0 0 0
396 0 $self->{load_data}{start_time} = $self->time();
397 0 $self->store->finish_bulk_update;
398 }
399 0 $self->msg(sprintf "%5.2fs\n",$self->time()-$self->{load_data}{start_time});
400 0 eval {$self->store->commit};
401  
402 # don't delete load data so that caller can ask for the loaded IDs
403 # $self->delete_load_data;
404 }
405  
406 =item build_summary
407  
408 $loader->build_summary
409  
410 Call this to rebuild the summary coverage statistics. This is done automatically
411 if new() was passed a true value for -summary_stats at create time.
412  
413 =cut
414  
415 0 ▶sub build_summary {
Subroutine build_summary: not called CC=1 SCAR=6.9
Pod documented
416 0 my $self = shift;
417 0 $self->store->build_summary_statistics;
418 }
419  
420 =item do_load
421  
422 $count = $loader->do_load($fh)
423  
424 This is called by load_fh() to load the GFF3 file's filehandle and
425 return the number of lines loaded.
426  
427 =cut
428  
429 0 ▶sub do_load {
Subroutine do_load: not called CC=2 SCAR=17.9
Pod documented
430 0 my $self = shift;
431 0 my $fh = shift;
432  
433 0 $self->{load_data}{start_time} = $self->time();
434 0 $self->{load_data}->{millenium_time} = $self->{load_data}{start_time};
435 0 ▶ $self->load_line($_) while <$fh>;
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = readline $fh) and do { $self->load_line($_) } 0 0 0
436 $self->msg(sprintf "%d features loaded in %5.2fs%s\r",
437 $self->{load_data}->{count},
438 $self->time()-$self->{load_data}{start_time},
439 0 ' 'x80
440 );
441 0 $self->{load_data}{count};
442 }
443  
444 =item load_line
445  
446 $loader->load_line($data);
447  
448 Load a line of a GFF3 file. You must bracket this with calls to
449 start_load() and finish_load()!
450  
451 $loader->start_load();
452 $loader->load_line($_) while <FH>;
453 $loader->finish_load();
454  
455 =cut
456  
457 0 ▶sub load_line {
Subroutine load_line: not called CC=1 SCAR=6.9
Pod documented
458 0 my $self = shift;
459 0 my $line = shift;
460 # don't do anything
461 }
462  
463  
464 =item handle_feature
465  
466 $loader->handle_feature($data_line)
467  
468 This method is called to process a single data line. It manipulates
469 information stored a data structure called $self-E<gt>{load_data}.
470  
471 =cut
472  
473 0 ▶sub handle_feature {
Subroutine handle_feature: not called CC=1 SCAR=6.9
Pod documented
474 0 my $self = shift;
475 0 my $line = shift;
476 # do nothing
477 }
478  
479 =item handle_meta
480  
481 $loader->handle_meta($data_line)
482  
483 This method is called to process a single data line. It manipulates
484 information stored a data structure called $self-E<gt>{load_data}.
485  
486 =cut
487  
488 0 ▶sub handle_meta {
Subroutine handle_meta: not called CC=1 SCAR=6.9
Pod documented
489 0 my $self = shift;
490 0 my $line = shift;
491 # do nothing
492 }
493  
494 0 ▶sub _indexit {
Subroutine _indexit: not called CC=3 SCAR=24.8
495 0 my $self = shift;
496 0 my $id = shift;
497 0 ▶ $id ||= ''; # avoid uninit warnings
Condition0%0/2
$id ||= ""
l!l
00
MC/DC0%0/1
$id ||= ""
$id
Truth table0%0/2
A
A= $id
Aresult
11
00
498 0 my $indexhash = $self->{load_data}{IndexIt};
499 0 ▶ $indexhash->{$id} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
500 0 return $indexhash->{$id};
501 }
502  
503 0 ▶sub _local2global {
Subroutine _local2global: not called CC=3 SCAR=24.8
504 0 my $self = shift;
505 0 my $id = shift;
506 0 ▶ $id ||= ''; # avoid uninit warnings
Condition0%0/2
$id ||= ""
l!l
00
MC/DC0%0/1
$id ||= ""
$id
Truth table0%0/2
A
A= $id
Aresult
11
00
507 0 my $indexhash = $self->{load_data}{Local2GlobalID};
508 0 ▶ $indexhash->{$id} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
509 0 return $indexhash->{$id};
510 }
511  
512 =item store_current_feature
513  
514 $loader->store_current_feature()
515  
516 This method is called to store the currently active feature in the
517 database. It uses a data structure stored in $self-E<gt>{load_data}.
518  
519 =cut
520  
521 0 ▶sub store_current_feature {
Subroutine store_current_feature: not called CC=5 SCAR=34.0
Pod documented
522 0 my $self = shift;
523  
524 0 my $ld = $self->{load_data};
525 0 ▶ defined $ld->{CurrentFeature} or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $ld->{"CurrentFeature"} or return 0 0 0
526 0 my $f = $ld->{CurrentFeature};
527  
528 0 my $normalized = $self->subfeatures_normalized;
529 0 my $indexed = $self->_indexit($ld->{CurrentID});
530  
531 # logic is as follows:
532 # 1. If the feature is an indexed feature, then we store it into the main database
533 # so that it can be searched. It doesn't matter whether it is a top-level feature
534 # or a subfeature.
535 # 2. If the feature class is normalized, but not indexed, then we store it into the
536 # main database using the "no_index" method. This will make it accessible to
537 # queries on the top level parent, but it won't come up by itself in range or
538 # attribute searches.
539 # 3. Otherwise, this is an unindexed subfeature; we store it in the temporary database
540 # until the object build step, at which point it gets integrated into its object tree
541 # and copied into the main database.
542  
543 0 ▶ if ($indexed) {
Branch: 2 branches
BranchTrueFalseTotal
if ($indexed) { } 0 0 0
elsif ($normalized) { } 0 0 0
544 0 $self->store->store($f);
545 }
546  
547 elsif ($normalized) {
548 0 $self->store->store_noindex($f)
549 }
550  
551 else {
552 0 $self->tmp_store->store_noindex($f)
553 }
554
555 0 my $id = $f->primary_id; # assigned by store()
556  
557 0 $self->_local2global($ld->{CurrentID} => $id);
558 0 ▶ $self->_indexit($ld->{CurrentID} => 0)if $normalized; # no need to remember this
Branch: 1 branch
BranchTrueFalseTotal
if $normalized 0 0 0
559 0 undef $ld->{CurrentID};
560 0 undef $ld->{CurrentFeature};
561 }
562  
563 =item parse_attributes
564  
565 ($reserved,$unreserved) = $loader->parse_attributes($attribute_line)
566  
567 This method parses the information contained in the $attribute_line
568 into two hashrefs, one containing the values of reserved attribute
569 tags (e.g. ID) and the other containing the values of unreserved ones.
570  
571 =cut
572  
573 0 ▶sub parse_attributes {
Subroutine parse_attributes: not called CC=1 SCAR=6.9
Pod documented
574 0 my $self = shift;
575 0 my $att = shift;
576 # do nothing
577 }
578  
579 =item start_or_finish_sequence
580  
581 $loader->start_or_finish_sequence('Chr9')
582  
583 This method is called at the beginning and end of a fasta section.
584  
585 =cut
586  
587 # this gets called at the beginning and end of a fasta section
588 0 ▶sub start_or_finish_sequence {
Subroutine start_or_finish_sequence: not called CC=4 SCAR=30.0
Pod documented
589 0 my $self = shift;
590 0 my $seqid = shift;
591 0 ▶ if (my $sl = $self->{fasta_load}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sl = $self->{"fasta_load"}) 0 0 0
592 0 ▶ if (defined $sl->{seqid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sl->{"seqid"}) 0 0 0
593 0 $self->store->insert_sequence($sl->{seqid},$sl->{sequence},$sl->{offset});
594 0 delete $self->{fasta_load};
595 }
596 }
597 0 ▶ if (defined $seqid) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $seqid) 0 0 0
598 0 $self->{fasta_load} = {seqid => $seqid,
599 offset => 0,
600 sequence => ''};
601 }
602 }
603  
604 =item load_sequence
605  
606 $loader->load_sequence('gatttcccaaa')
607  
608 This method is called to load some amount of sequence after
609 start_or_finish_sequence() is first called.
610  
611 =cut
612  
613 0 ▶sub load_sequence {
Subroutine load_sequence: not called CC=3 SCAR=24.8
Pod documented
614 0 my $self = shift;
615 0 my $seq = shift;
616 0 ▶ my $sl = $self->{fasta_load} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sl = $self->{"fasta_load"} or return 0 0 0
617 0 my $cs = $self->seq_chunk_size;
618 0 $sl->{sequence} .= $seq;
619 0 ▶ while (length $sl->{sequence} >= $cs) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $sl->{"sequence"} >= $cs) 0 0 0
620 0 my $chunk = substr($sl->{sequence},0,$cs);
621 0 $self->store->insert_sequence($sl->{seqid},$chunk,$sl->{offset});
622 0 $sl->{offset} += length $chunk;
623 0 substr($sl->{sequence},0,$cs) = '';
624 }
625 }
626  
627 =item open_fh
628  
629 my $io_file = $loader->open_fh($filehandle_or_path)
630  
631 This method opens up the indicated file or pipe, using some
632 intelligence to recognized compressed files and URLs and doing the
633 right thing.
634  
635 =cut
636  
637  
638 0 ▶sub open_fh {
Subroutine open_fh: not called CC=8 SCAR=39.7
Pod documented
639 0 my $self = shift;
640 0 my $thing = shift;
641  
642 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
643  
644 0 ▶ return $thing if defined fileno($thing);
Branch: 1 branch
BranchTrueFalseTotal
if defined fileno $thing 0 0 0
645 0 ▶ return IO::File->new("gunzip -c $thing |") if $thing =~ /\.gz$/;
Branch: 1 branch
BranchTrueFalseTotal
if $thing =~ /\.gz$/ 0 0 0
646 0 ▶ return IO::File->new("uncompress -c $thing |") if $thing =~ /\.Z$/;
Branch: 1 branch
BranchTrueFalseTotal
if $thing =~ /\.Z$/ 0 0 0
647 0 ▶ return IO::File->new("bunzip2 -c $thing |") if $thing =~ /\.bz2$/;
Branch: 1 branch
BranchTrueFalseTotal
if $thing =~ /\.bz2$/ 0 0 0
648 0 ▶ return IO::File->new("GET $thing |") if $thing =~ /^(http|ftp):/;
Branch: 1 branch
BranchTrueFalseTotal
if $thing =~ /^(http|ftp):/ 0 0 0
649 0 ▶ return $thing if ref $thing && $thing->isa('IO::String');
Branch: 1 branch
BranchTrueFalseTotal
if ref $thing and $thing->isa("IO::String") 0 0 0
Condition0%0/3
ref $thing and $thing->isa("IO::String")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $thing and $thing->isa("IO::String")
ref $thing $thing->isa("IO::String")
Truth table0%0/3
A and B
A= ref $thingB= $thing->isa("IO::String")
ABresult
0X0
100
111
650 0 return IO::File->new($thing);
651 }
652  
653 0 ▶sub msg {
Subroutine msg: not called CC=2 SCAR=17.9
Pod undocumented
654 0 my $self = shift;
655 0 my @msg = @_;
656 0 ▶ return unless $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->verbose 0 0 0
657 0 print STDERR @msg;
658 }
659  
660 =item loaded_ids
661  
662 my $ids = $loader->loaded_ids;
663 my $id_cnt = @$ids;
664  
665 After performing a load, this returns an array ref containing all the
666 feature primary ids that were created during the load.
667  
668 =cut
669  
670 0 ▶sub loaded_ids {
Subroutine loaded_ids: not called CC=2 SCAR=17.9
Pod documented
671 0 my $self = shift;
672 0 my @ids = values %{$self->{load_data}{Local2GlobalID}}
673 0 ▶ if $self->{load_data};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"load_data"} 0 0 0
674 0 return \@ids;
675 }
676  
677 =item local_ids
678  
679 my $ids = $self->local_ids;
680 my $id_cnt = @$ids;
681  
682 After performing a load, this returns an array ref containing all the
683 load file IDs that were contained within the file just loaded.
684  
685 =cut
686  
687 0 ▶sub local_ids {
Subroutine local_ids: not called CC=2 SCAR=17.9
Pod documented
688 0 my $self = shift;
689 0 my @ids = keys %{$self->{load_data}{Local2GlobalID}}
690 0 ▶ if $self->{load_data};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"load_data"} 0 0 0
691 0 return \@ids;
692 }
693  
694 =item time
695  
696 my $time = $loader->time
697  
698 This method returns the current time in seconds, using Time::HiRes if available.
699  
700 =cut
701  
702 0 ▶sub time {
Subroutine time: not called CC=2 SCAR=17.9
Pod documented
703 0 ▶ return Time::HiRes::time() if Time::HiRes->can('time');
Branch: 1 branch
BranchTrueFalseTotal
if "Time::HiRes"->can("time") 0 0 0
704 0 return time();
705 }
706  
707 =item unescape
708  
709 my $unescaped = GFF3Loader::unescape($escaped)
710  
711 This is an internal utility. It is the same as CGI::Util::unescape,
712 but doesn't change pluses into spaces and ignores unicode escapes.
713  
714 =cut
715  
716 0 ▶sub unescape {
Subroutine unescape: not called CC=1 SCAR=6.9
Pod documented
717 0 my $self = shift;
718 0 my $todecode = shift;
719 0 $todecode =~ s/%([0-9a-fA-F]{2})/chr hex($1)/ge;
720 0 return $todecode;
721 }
722  
723 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=9 SCAR=45.0
724 0 my $self = shift;
725 # Close filehandles, so temporal files can be properly deleted
726 0 my $store = $self->store;
727 0 ▶ if ( $store->isa('Bio::DB::SeqFeature::Store::memory')
Branch: 2 branches
BranchTrueFalseTotal
if ($store->isa('Bio::DB::SeqFeature::Store::memory') or $store->isa('Bio::DB::SeqFeature::Store::berkeleydb3')) { } 0 0 0
elsif ($store->isa('Bio::DB::SeqFeature::Store::DBI::SQLite')) { } 0 0 0
Condition0%0/3
$store->isa("Bio::DB::SeqFeature::Store::memory") or $store->isa("Bio::DB::SeqFeature::Store::berkeleydb3")
l!l&&r!l&&!r
000
MC/DC0%0/2
$store->isa("Bio::DB::SeqFeature::Store::memory") or $store->isa("Bio::DB::SeqFeature::Store::berkeleydb3")
$store->isa("Bio::DB::SeqFeature::Store::memory") $store->isa("Bio::DB::SeqFeature::Store::berkeleydb3")
Truth table0%0/3
A or B
A= $store->isa("Bio::DB::SeqFeature::Store::memory")B= $store->isa("Bio::DB::SeqFeature::Store::berkeleydb3")
ABresult
1X1
011
000
728 or $store->isa('Bio::DB::SeqFeature::Store::berkeleydb3')
729 ) {
730 0 $store->private_fasta_file->close;
731  
732 0 ▶ if ($store->{fasta_db} && !$self->{no_close_fasta}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($store->{"fasta_db"} and not $self->{"no_close_fasta"}) 0 0 0
Condition0%0/3
$store->{"fasta_db"} and not $self->{"no_close_fasta"}
!ll&&!rl&&r
000
MC/DC0%0/2
$store->{"fasta_db"} and not $self->{"no_close_fasta"}
$store->{"fasta_db"} not $self->{"no_close_fasta"}
Truth table0%0/3
A and not(B)
A= $store->{"fasta_db"}B= not $self->{"no_close_fasta"}
ABresult
0X0
100
111
733 0 ▶ while (my ($file, $fh) = each %{ $store->{fasta_db}->{fhcache} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$store{"fasta_db"}{"fhcache"};}) 0 0 0
734 0 $fh->close;
735 }
736 0 $store->{fasta_db}->_close_index($store->{fasta_db}->{offsets});
737 }
738 }
739 elsif ($store->isa('Bio::DB::SeqFeature::Store::DBI::SQLite')) {
740 0 ▶ if (%DBI::installed_drh) {
Branch: 1 branch
BranchTrueFalseTotal
if (%DBI::installed_drh) 0 0 0
741 0 DBI->disconnect_all;
742 0 %DBI::installed_drh = ();
743 }
744 0 undef $store->{dbh};
745 }
746  
747 0 ▶ if (my $ld = $self->{temp_load}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ld = $self->{"temp_load"}) 0 0 0
748 0 unlink $ld;
749 }
750 }
751  
752 2 1;
753 __END__
« SeqFeature/NormalizedFeature.pm ↑ Summary SeqFeature.pm »