SeqFeature/Store/FeatureFileLoader.pm

filter: Statementstmt 9.2% 17 / 184 Branchbran 0.0% 0 / 104 Conditioncond 0.0% 0 / 96 MC/DCmcdc 0.0% 0 / 53 Subroutinesub 25.0% 5 / 20 Podpod 90.9% 10 / 11 totaltotal 6.8% 32 / 468 CC 94 SCAR 67.6
CC
94
Cov
4%
handle_feature
1332.0
_make_feature
1332.0
load_line
132.0
CRAP 865.7
↑ Summary SeqFeature/Store/DBI/MariaDB.pm »
1 package Bio::DB::SeqFeature::Store::FeatureFileLoader;
2 1 $Bio::DB::SeqFeature::Store::FeatureFileLoader::VERSION = '1.7.5';
3  
4 =head1 NAME
5  
6 Bio::DB::SeqFeature::Store::FeatureFileLoader -- feature file loader for Bio::DB::SeqFeature::Store
7  
8 =head1 SYNOPSIS
9  
10 use Bio::DB::SeqFeature::Store;
11 use Bio::DB::SeqFeature::Store::FeatureFileLoader;
12  
13 # Open the sequence database
14 my $db = Bio::DB::SeqFeature::Store->new( -adaptor => 'DBI::mysql',
15 -dsn => 'dbi:mysql:test',
16 -write => 1 );
17  
18 my $loader =
19 Bio::DB::SeqFeature::Store::FeatureFileLoader->new(-store => $db,
20 -verbose => 1,
21 -fast => 1);
22  
23 $loader->load('./my_genome.fff');
24  
25  
26 =head1 DESCRIPTION
27  
28 The Bio::DB::SeqFeature::Store::FeatureFileLoader object parsers
29 FeatureFile-format sequence annotation files and loads
30 Bio::DB::SeqFeature::Store databases. For certain combinations of
31 SeqFeature classes and SeqFeature::Store databases it features a "fast
32 load" mode which will greatly accelerate the loading of databases by a
33 factor of 5-10.
34  
35 FeatureFile Format (.fff) is very simple:
36  
37 mRNA B0511.1 Chr1:1..100 Type=UTR;Note="putative primase"
38 mRNA B0511.1 Chr1:101..200,300..400,500..800 Type=CDS
39 mRNA B0511.1 Chr1:801..1000 Type=UTR
40  
41 reference = Chr3
42 Cosmid B0511 516..619
43 Cosmid B0511 3185..3294
44 Cosmid B0511 10946..11208
45 Cosmid B0511 13126..13511
46 Cosmid B0511 11394..11539
47 EST yk260e10.5 15569..15724
48 EST yk672a12.5 537..618,3187..3294
49 EST yk595e6.5 552..618
50 EST yk595e6.5 3187..3294
51 EST yk846e07.3 11015..11208
52 EST yk53c10
53 yk53c10.3 15000..15500,15700..15800
54 yk53c10.5 18892..19154
55 EST yk53c10.5 16032..16105
56 SwissProt PECANEX 13153-13656 Note="Swedish fish"
57 FGENESH "Predicted gene 1" 1-205,518-616,661-735,3187-3365,3436-3846 "Pfam domain"
58 # file ends
59  
60 There are up to four columns of WHITESPACE (not necessarily tab)
61 delimited text. Embedded whitespace must be escaped using shell
62 escaping rules (quoting the column or backslashing whitespace).
63  
64 Column 1: The feature type. You may use type:subtype as a convention
65 for method:source.
66  
67 Column 2: The feature name/ID.
68  
69 Column 3: The position of this feature in base pair
70 coordinates. Ranges can be given as either
71 start-end or start..end. A chromosome position
72 can be specified using the format "reference:start..end".
73 A discontinuous feature can be specified by giving
74 multiple ranges separated by commas. Minus-strand features
75 are indicated by specifying a start > end.
76  
77 Column 4: Comment/attribute field. A single Note can be given, or
78 a series of attribute=value pairs, separated by
79 spaces or semicolons, as in "score=23;type=transmembrane"
80  
81 =head2 Specifying Positions and Ranges
82  
83 A feature position is specified using a sequence ID (a genbank
84 accession number, a chromosome name, a contig, or any other meaningful
85 reference system, followed by a colon and a position range. Ranges are
86 two integers separated by double dots or the hyphen. Examples:
87 "Chr1:516..11208", "ctgA:1-5000". Negative coordinates are allowed, as
88 in "Chr1:-187..1000".
89  
90 A discontinuous range ("split location") uses commas to separate the
91 ranges. For example:
92  
93 Gene B0511.1 Chr1:516..619,3185..3294,10946..11208
94  
95 In the case of a split location, the sequence id only has to appear in
96 front of the first range.
97  
98 Alternatively, a split location can be indicated by repeating the
99 features type and name on multiple adjacent lines:
100  
101 Gene B0511.1 Chr1:516..619
102 Gene B0511.1 Chr1:3185..3294
103 Gene B0511.1 Chr1:10946..11208
104  
105 If all the locations are on the same reference sequence, you can
106 specify a default chromosome using a "reference=E<lt>seqidE<gt>":
107  
108 reference=Chr1
109 Gene B0511.1 516..619
110 Gene B0511.1 3185..3294
111 Gene B0511.1 10946..11208
112  
113 The default seqid is in effect until the next "reference" line
114 appears.
115  
116 =head2 Feature Tags
117  
118 Tags can be added to features by adding a fourth column consisting of
119 "tag=value" pairs:
120  
121 Gene B0511.1 Chr1:516..619,3185..3294 Note="Putative primase"
122  
123 Tags and their values take any form you want, and multiple tags can be
124 separated by semicolons. You can also repeat tags multiple times:
125  
126 Gene B0511.1 Chr1:516..619,3185..3294 GO_Term=GO:100;GO_Term=GO:2087
127  
128 Several tags have special meanings:
129  
130 Tag Meaning
131 --- -------
132  
133 Type The primary tag for a subfeature.
134 Score The score of a feature or subfeature.
135 Phase The phase of a feature or subfeature.
136 URL A URL to link to (via the Bio::Graphics library).
137 Note A note to attach to the feature for display by the Bio::Graphics library.
138  
139 For example, in the common case of an mRNA, you can use the "Type" tag
140 to distinguish the parts of the mRNA into UTR and CDS:
141  
142 mRNA B0511.1 Chr1:1..100 Type=UTR
143 mRNA B0511.1 Chr1:101..200,300..400,500..800 Type=CDS
144 mRNA B0511.1 Chr1:801..1000 Type=UTR
145  
146 The top level feature's primary tag will be "mRNA", and its subparts
147 will have types UTR and CDS as indicated. Additional tags that are
148 placed in the first line of the feature will be applied to the top
149 level. In this example, the note "Putative primase" will be applied to
150 the mRNA at the top level of the feature:
151  
152 mRNA B0511.1 Chr1:1..100 Type=UTR;Note="Putative primase"
153 mRNA B0511.1 Chr1:101..200,300..400,500..800 Type=CDS
154 mRNA B0511.1 Chr1:801..1000 Type=UTR
155  
156 =head2 Feature Groups
157  
158 Features can be grouped so that they are rendered by the "group"
159 glyph. To start a group, create a two-column feature entry showing
160 the group type and a name for the group. Follow this with a list of
161 feature entries with a blank type. For example:
162  
163 EST yk53c10
164 yk53c10.3 15000-15500,15700-15800
165 yk53c10.5 18892-19154
166  
167 This example is declaring that the ESTs named yk53c10.3 and yk53c10.5
168 belong to the same group named yk53c10.
169  
170 =head2 Comments and the #include Directive
171  
172 Lines that begin with the # sign are treated as comments and
173 ignored. When a # sign appears within a line, everything to the right
174 of the symbol is also ignored, unless it looks like an HTML fragment or
175 an HTML color, e.g.:
176  
177 # this is ignored
178 [Example]
179 glyph = generic # this comment is ignored
180 bgcolor = #FF0000
181 link = http://www.google.com/search?q=$name#results
182  
183 Be careful, because the processing of # signs uses a regexp heuristic. To be safe,
184 always put a space after the # sign to make sure it is treated as a comment.
185  
186 The special comment "#include 'filename'" acts like the C preprocessor
187 directive and will insert the comments of a named file into the
188 position at which it occurs. Relative paths will be treated relative
189 to the file in which the #include occurs. Nested #include directives
190 are allowed:
191  
192 #include "/usr/local/share/my_directives.txt"
193 #include 'my_directives.txt'
194 #include chromosome3_features.gff3
195  
196 You can enclose the file path in single or double quotes as shown
197 above. If there are no spaces in the filename the quotes are optional.
198  
199 Include file processing is not very smart. Avoid creating circular
200 #include references. You have been warned!
201  
202 =head2 Caveats
203  
204 Note that this loader always creates denormalized features such that
205 subfeatures and their parents are stored as one big database
206 object. The GFF3 format and its loader is usually preferred for both
207 space and execution efficiency.
208  
209 =head1 METHODS
210  
211 =cut
212  
213  
214 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
215 1 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
216 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
217 1 ▶use Text::ParseWords 'shellwords','quotewords';
Subroutine BEGIN: called CC=1 SCAR=0.0
218  
219 1 ▶use base 'Bio::DB::SeqFeature::Store::Loader';
Subroutine BEGIN: called CC=1 SCAR=0.0
220  
221 =head2 new
222  
223 Title : new
224 Usage : $loader = Bio::DB::SeqFeature::Store::FeatureFileLoader->new(@options)
225 Function: create a new parser
226 Returns : a Bio::DB::SeqFeature::Store::FeatureFileLoader parser and loader
227 Args : several - see below
228 Status : public
229  
230 This method creates a new FeatureFile loader and establishes its connection
231 with a Bio::DB::SeqFeature::Store database. Arguments are -name=E<gt>$value
232 pairs as described in this table:
233  
234 Name Value
235 ---- -----
236  
237 -store A writable Bio::DB::SeqFeature::Store database handle.
238  
239 -seqfeature_class The name of the type of Bio::SeqFeatureI object to create
240 and store in the database (Bio::DB::SeqFeature by default)
241  
242 -sf_class A shorter alias for -seqfeature_class
243  
244 -verbose Send progress information to standard error.
245  
246 -fast If true, activate fast loading (see below)
247  
248 -chunk_size Set the storage chunk size for nucleotide/protein sequences
249 (default 2000 bytes)
250  
251 -tmp Indicate a temporary directory to use when loading non-normalized
252 features.
253  
254 When you call new(), a connection to a Bio::DB::SeqFeature::Store
255 database should already have been established and the database
256 initialized (if appropriate).
257  
258 Some combinations of Bio::SeqFeatures and Bio::DB::SeqFeature::Store
259 databases support a fast loading mode. Currently the only reliable
260 implementation of fast loading is the combination of DBI::mysql with
261 Bio::DB::SeqFeature. The other important restriction on fast loading
262 is the requirement that a feature that contains subfeatures must occur
263 in the FeatureFile file before any of its subfeatures. Otherwise the
264 subfeatures that occurred before the parent feature will not be
265 attached to the parent correctly. This restriction does not apply to
266 normal (slow) loading.
267  
268 If you use an unnormalized feature class, such as
269 Bio::SeqFeature::Generic, then the loader needs to create a temporary
270 database in which to cache features until all their parts and subparts
271 have been seen. This temporary databases uses the "bdb" adaptor. The
272 -tmp option specifies the directory in which that database will be
273 created. If not present, it defaults to the system default tmp
274 directory specified by File::Spec-E<gt>tmpdir().
275  
276 The -chunk_size option allows you to tune the representation of
277 DNA/Protein sequence in the Store database. By default, sequences are
278 split into 2000 base/residue chunks and then reassembled as
279 needed. This avoids the problem of pulling a whole chromosome into
280 memory in order to fetch a short subsequence from somewhere in the
281 middle. Depending on your usage patterns, you may wish to tune this
282 parameter using a chunk size that is larger or smaller than the
283 default.
284  
285 =cut
286  
287 # sub new {} inherited
288  
289 =head2 load
290  
291 Title : load
292 Usage : $count = $loader->load(@ARGV)
293 Function: load the indicated files or filehandles
294 Returns : number of feature lines loaded
295 Args : list of files or filehandles
296 Status : public
297  
298 Once the loader is created, invoke its load() method with a list of
299 FeatureFile or FASTA file paths or previously-opened filehandles in order to
300 load them into the database. Compressed files ending with .gz, .Z and
301 .bz2 are automatically recognized and uncompressed on the fly. Paths
302 beginning with http: or ftp: are treated as URLs and opened using the
303 LWP GET program (which must be on your path).
304  
305 FASTA files are recognized by their initial "E<gt>" character. Do not feed
306 the loader a file that is neither FeatureFile nor FASTA; I don't know what
307 will happen, but it will probably not be what you expect.
308  
309 =cut
310  
311 # sub load {} inherited
312  
313 =head2 accessors
314  
315 The following read-only accessors return values passed or created during new():
316  
317 store() the long-term Bio::DB::SeqFeature::Store object
318  
319 tmp_store() the temporary Bio::DB::SeqFeature::Store object used
320 during loading
321  
322 sfclass() the Bio::SeqFeatureI class
323  
324 fast() whether fast loading is active
325  
326 seq_chunk_size() the sequence chunk size
327  
328 verbose() verbose progress messages
329  
330 =cut
331  
332 # sub store {} inherited
333 # sub tmp_store {} inherited
334 # sub sfclass {} inherited
335 # sub fast {} inherited
336 # sub seq_chunk_size {} inherited
337 # sub verbose {} inherited
338  
339 =head2 default_seqfeature_class
340  
341 $class = $loader->default_seqfeature_class
342  
343 Return the default SeqFeatureI class (Bio::Graphics::Feature).
344  
345 =cut
346  
347 0 ▶sub default_seqfeature_class { #override
Subroutine default_seqfeature_class: not called CC=1 SCAR=6.9
Pod documented
348 0 my $self = shift;
349 0 return 'Bio::Graphics::Feature';
350 }
351  
352  
353 =head2 load_fh
354  
355 $count = $loader->load_fh($filehandle)
356  
357 Load the FeatureFile data at the other end of the filehandle and return true
358 if successful. Internally, load_fh() invokes:
359  
360 start_load();
361 do_load($filehandle);
362 finish_load();
363  
364 =cut
365  
366 # sub load_fh { } inherited
367  
368 =head2 start_load, finish_load
369  
370 These methods are called at the start and end of a filehandle load.
371  
372 =cut
373  
374 0 ▶sub create_load_data {
Subroutine create_load_data: not called CC=1 SCAR=6.9
Pod undocumented
375 0 my $self = shift;
376 0 $self->SUPER::create_load_data();
377 0 $self->{load_data}{mode} = 'fff';
378 0 $self->{load_data}{CurrentGroup} = undef;
379 }
380  
381 0 ▶sub finish_load {
Subroutine finish_load: not called CC=1 SCAR=6.9
Pod documented
382 0 my $self = shift;
383 0 $self->_store_group;
384 0 $self->SUPER::finish_load;
385 }
386  
387 =head2 load_line
388  
389 $loader->load_line($data);
390  
391 Load a line of a FeatureFile file. You must bracket this with calls to
392 start_load() and finish_load()!
393  
394 $loader->start_load();
395 $loader->load_line($_) while <FH>;
396 $loader->finish_load();
397  
398 =cut
399  
400 0 ▶sub load_line {
Subroutine load_line: not called CC=11 SCAR=48.8
Pod documented
401 0 my $self = shift;
402 0 my $line = shift;
403  
404 0 chomp($line);
405 0 ▶ return unless $line =~ /\S/; # blank line
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\S/ 0 0 0
406 0 my $load_data = $self->{load_data};
407  
408 0 ▶ $load_data->{mode} = 'fff' if /\s/; # if it has any whitespace in
Branch: 1 branch
BranchTrueFalseTotal
if /\s/ 0 0 0
409 # it, then back to fff mode
410  
411 0 ▶ if ($line =~ /^\#\s?\#\s*([\#]+)/) { ## meta instruction
Branch: 5 branches
BranchTrueFalseTotal
if ($line =~ /^\#\s?\#\s*([\#]+)/) { } 0 0 0
elsif ($line =~ /^\#/) { } 0 0 0
elsif ($line =~ /^>\s*(\S+)/) { } 0 0 0
elsif ($load_data->{'mode'} eq 'fasta') { } 0 0 0
elsif ($load_data->{'mode'} eq 'fff') { } 0 0 0
412 0 $load_data->{mode} = 'fff';
413 0 $self->handle_meta($1);
414  
415 } elsif ($line =~ /^\#/) {
416 0 $load_data->{mode} = 'fff'; # just to be safe
417 0 return; # comment
418 }
419  
420 elsif ($line =~ /^>\s*(\S+)/) { # FASTA lines are coming
421 0 $load_data->{mode} = 'fasta';
422 0 $self->start_or_finish_sequence($1);
423 }
424  
425 elsif ($load_data->{mode} eq 'fasta') {
426 0 $self->load_sequence($line);
427 }
428  
429 elsif ($load_data->{mode} eq 'fff') {
430 0 $self->handle_feature($line);
431 0 ▶ if (++$load_data->{count} % 1000 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$load_data->{"count"} % 1000 == 0) 0 0 0
432 0 my $now = $self->time();
433 0 ▶ my $nl = -t STDOUT && !$ENV{EMACS} ? "\r" : "\n";
Branch: 1 branch
BranchTrueFalseTotal
-t STDOUT && !$ENV{'EMACS'} ? : 0 0 0
Condition0%0/3
-t STDOUT and not $ENV{"EMACS"}
!ll&&!rl&&r
000
MC/DC0%0/2
-t STDOUT and not $ENV{"EMACS"}
-t STDOUT not $ENV{"EMACS"}
Truth table0%0/3
A and not(B)
A= -t STDOUTB= not $ENV{"EMACS"}
ABresult
0X0
100
111
434 $self->msg(sprintf("%d features loaded in %5.2fs...$nl",
435 0 $load_data->{count},$now - $load_data->{start_time}));
436 0 $load_data->{start_time} = $now;
437 }
438 }
439  
440 else {
441 0 $self->throw("I don't know what to do with this line:\n$line");
442 }
443 }
444  
445  
446 =head2 handle_meta
447  
448 $loader->handle_meta($meta_directive)
449  
450 This method is called to handle meta-directives such as
451 ##sequence-region. The method will receive the directive with the
452 initial ## stripped off.
453  
454 =cut
455  
456 # sub handle_meta { } inherited
457  
458 =head2 handle_feature
459  
460 $loader->handle_feature($gff3_line)
461  
462 This method is called to process a single FeatureFile line. It manipulates
463 information stored a data structure called $self-E<gt>{load_data}.
464  
465 =cut
466  
467 0 ▶sub handle_feature {
Subroutine handle_feature: not called CC=36 SCAR=71.9
Pod documented
468 0 my $self = shift;
469 0 local $_ = shift;
470  
471 0 my $ld = $self->{load_data};
472  
473 # handle reference line
474 0 ▶ if (/^reference\s*=\s*(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^reference\s*=\s*(.+)/) 0 0 0
475 0 $ld->{reference} = $1;
476 0 return;
477 }
478  
479 # parse data lines
480 0 my @tokens = quotewords('\s+',1,$_);
481 0 for (0..2) { # remove quotes from everything but last column
482 0 ▶ next unless defined $tokens[$_];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tokens[$_] 0 0 0
483 0 $tokens[$_] =~ s/^"//;
484 0 $tokens[$_] =~ s/"$//;
485 }
486  
487 0 ▶ if (@tokens < 3) { # short line; assume a group identifier
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens < 3) 0 0 0
488 0 $self->store_current_feature();
489 0 my $type = shift @tokens;
490 0 my $name = shift @tokens;
491 0 $ld->{CurrentGroup} = $self->_make_indexed_feature($name,$type,'',{_ff_group=>1});
492 0 $self->_indexit($name => 1);
493 0 return;
494 }
495  
496 0 my($type,$name,$strand,$bounds,$attributes);
497  
498 0 ▶ if ($tokens[2] =~ /^([+-.]|[+-]?[01])$/) { # old version
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[2] =~ /^([+-.]|[+-]?[01])$/) { } 0 0 0
499 0 ($type,$name,$strand,$bounds,$attributes) = @tokens;
500 } else { # new version
501 0 ($type,$name,$bounds,$attributes) = @tokens;
502 }
503  
504 # handle case of there only being one value in the last column,
505 # in which case we treat it the same as Note="value"
506 0 my $attr = $self->parse_attributes($attributes);
507  
508 # @parts is an array of ([ref,start,end],[ref,start,end],...)
509 0 my @parts = map { [/(?:(\w+):)?(-?\d+)(?:-|\.\.)(-?\d+)/]} split /(?:,| )\s*/,$bounds;
510  
511 # deal with groups -- a group is ending if $type is defined
512 # and CurrentGroup is set
513 0 ▶ if ($type && $ld->{CurrentGroup}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type and $ld->{"CurrentGroup"}) 0 0 0
Condition0%0/3
$type and $ld->{"CurrentGroup"}
!ll&&!rl&&r
000
MC/DC0%0/2
$type and $ld->{"CurrentGroup"}
$type $ld->{"CurrentGroup"}
Truth table0%0/3
A and B
A= $typeB= $ld->{"CurrentGroup"}
ABresult
0X0
100
111
514 0 $self->_store_group();
515 }
516  
517 0 ▶ $type = '' unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 0 0
518 0 ▶ $name = '' unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
519 0 ▶ $type ||= $ld->{CurrentGroup}->primary_tag if $ld->{CurrentGroup};
Branch: 1 branch
BranchTrueFalseTotal
if $ld->{"CurrentGroup"} 0 0 0
Condition0%0/3
$type ||= $ld->{"CurrentGroup"}->primary_tag
l!l&&r!l&&!r
000
MC/DC0%0/2
$type ||= $ld->{"CurrentGroup"}->primary_tag
$type $ld->{"CurrentGroup"}->primary_tag
Truth table0%0/3
A ||= B
A= $typeB= $ld->{"CurrentGroup"}->primary_tag
ABresult
1X1
011
000
520  
521 0 ▶ my $reference = $ld->{reference} || 'ChrUN';
Condition0%0/2
$ld->{'reference'} || 'ChrUN'
l!l
00
MC/DC0%0/1
$ld->{'reference'} || 'ChrUN'
$ld->{'reference'}
Truth table0%0/2
A
A= $ld->{'reference'}
Aresult
11
00
522 0 foreach (@parts) {
523 0 ▶ if (defined $_ && ref($_) eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_ and ref $_ eq "ARRAY" and defined $_->[1] and defined $_->[2]) 0 0 0
Condition0%0/9
defined $_ and ref $_ eq "ARRAY" and defined $_->[1] and defined $_->[2]
!ll&&!rl&&r
000
defined $_ and ref $_ eq "ARRAY" and defined $_->[1]
!ll&&!rl&&r
000
defined $_ and ref $_ eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/4
defined $_ and ref $_ eq "ARRAY" and defined $_->[1] and defined $_->[2]
defined $_ ref $_ eq "ARRAY" defined $_->[1] defined $_->[2]
Truth table0%0/5
A and B and C and D
A= defined $_B= ref $_ eq "ARRAY"C= defined $_->[1]D= defined $_->[2]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
524 && defined $_->[1]
525 && defined $_->[2])
526 {
527 0 ▶ $strand ||= $_->[1] <= $_->[2] ? '+' : '-';
Branch: 1 branch
BranchTrueFalseTotal
$_->[1] <= $_->[2] ? : 0 0 0
Condition0%0/3
$strand ||= $_->[1] <= $_->[2] ? "+" : "-"
l!l&&r!l&&!r
000
MC/DC0%0/2
$strand ||= $_->[1] <= $_->[2] ? "+" : "-"
$strand $_->[1] <= $_->[2] ? "+" : "-"
Truth table0%0/3
A ||= B
A= $strandB= $_->[1] <= $_->[2] ? "+" : "-"
ABresult
1X1
011
000
528 0 ▶ ($_->[1],$_->[2]) = ($_->[2],$_->[1]) if $_->[1] > $_->[2];
Branch: 1 branch
BranchTrueFalseTotal
if $_->[1] > $_->[2] 0 0 0
529 }
530 0 ▶ $reference = $_->[0] if defined $_->[0];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_->[0] 0 0 0
531 0 $_ = [@{$_}[1,2]]; # strip off the reference.
532 }
533  
534 # now @parts is an array of [start,end] and $reference contains the seqid
535  
536 # apply coordinate mapper
537 0 ▶ if ($self->{coordinate_mapper} && $reference) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"coordinate_mapper"} and $reference) 0 0 0
Condition0%0/3
$self->{"coordinate_mapper"} and $reference
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"coordinate_mapper"} and $reference
$self->{"coordinate_mapper"} $reference
Truth table0%0/3
A and B
A= $self->{"coordinate_mapper"}B= $reference
ABresult
0X0
100
111
538 0 my @remapped = $self->{coordinate_mapper}->($reference,@parts);
539 0 ▶ ($reference,@parts) = @remapped if @remapped;
Branch: 1 branch
BranchTrueFalseTotal
if @remapped 0 0 0
540 }
541  
542 # either create a new feature or add a segment to it
543 0 my $feature = $ld->{CurrentFeature};
544
545 0 $ld->{OldPartType} = $ld->{PartType};
546 0 ▶ if (exists $attr->{Type} || exists $attr->{type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr->{'Type'} or exists $attr->{'type'}) { } 0 0 0
Condition0%0/3
exists $attr->{"Type"} or exists $attr->{"type"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $attr->{"Type"} or exists $attr->{"type"}
exists $attr->{"Type"} exists $attr->{"type"}
Truth table0%0/3
A or B
A= exists $attr->{"Type"}B= exists $attr->{"type"}
ABresult
1X1
011
000
547 0 ▶ $ld->{PartType} = $attr->{Type}[0] || $attr->{type}[0];
Condition0%0/3
$attr->{'Type'}[0] || $attr->{'type'}[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr->{'Type'}[0] || $attr->{'type'}[0]
$attr->{'Type'}[0] $attr->{'type'}[0]
Truth table0%0/3
A || B
A= $attr->{'Type'}[0]B= $attr->{'type'}[0]
ABresult
1X1
011
000
548 } else {
549 0 $ld->{PartType} = $type;
550 }
551  
552 0 ▶ if ($feature) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feature) 0 0 0
553 0 local $^W = 0; # avoid uninit warning when display_name() is called
554  
555 # if this is a different feature from what we have now, then we
556 # store the current one, and create a new one
557 0 ▶ if ($feature->display_name ne $name ||
Branch: 1 branch
BranchTrueFalseTotal
if ($feature->display_name ne $name or $feature->method ne $type) { } 0 0 0
Condition0%0/3
$feature->display_name ne $name or $feature->method ne $type
l!l&&r!l&&!r
000
MC/DC0%0/2
$feature->display_name ne $name or $feature->method ne $type
$feature->display_name ne $name $feature->method ne $type
Truth table0%0/3
A or B
A= $feature->display_name ne $nameB= $feature->method ne $type
ABresult
1X1
011
000
558 $feature->method ne $type) {
559 0 $self->store_current_feature; # new feature, store old one
560 0 undef $feature;
561 } else { # create a new multipart feature
562 $self->_multilevel_feature($feature,$ld->{OldPartType})
563 0 ▶ unless $feature->get_SeqFeatures;
Branch: 1 branch
BranchTrueFalseTotal
unless $feature->get_SeqFeatures 0 0 0
564 my $part = $self->_make_feature($name,
565 $ld->{PartType},
566 $strand,
567 $attr,
568 $reference,
569 0 @{$parts[0]});
570 0 $feature->add_SeqFeature($part);
571 }
572 }
573  
574 $feature ||= $self->_make_indexed_feature($name,
575 $type, # side effect is to set CurrentFeature
576 $strand,
577 $attr,
578 $reference,
579 0 ▶ @{$parts[0]});
Condition0%0/3
$feature ||= $self->_make_indexed_feature($name, $type, $strand, $attr, $reference, @{$parts[0];})
l!l&&r!l&&!r
000
MC/DC0%0/2
$feature ||= $self->_make_indexed_feature($name, $type, $strand, $attr, $reference, @{$parts[0];})
$feature $self->_make_indexed_feature($name, $type, $strand, $attr, $reference, @{$parts[0];})
Truth table0%0/3
A ||= B
A= $featureB= $self->_make_indexed_feature($name, $type, $strand, $attr, $reference, @{$parts[0];})
ABresult
1X1
011
000
580  
581 # add more segments to the current feature
582 0 ▶ if (@parts > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts > 1) 0 0 0
583 0 for my $part (@parts) {
584 0 ▶ $type ||= $feature->primary_tag;
Condition0%0/3
$type ||= $feature->primary_tag
l!l&&r!l&&!r
000
MC/DC0%0/2
$type ||= $feature->primary_tag
$type $feature->primary_tag
Truth table0%0/3
A ||= B
A= $typeB= $feature->primary_tag
ABresult
1X1
011
000
585 my $sp = $self->_make_feature($name,
586 $ld->{PartType},
587 $strand,
588 $attr,
589 $reference,
590 0 @{$part});
591 0 $feature->add_SeqFeature($sp);
592 }
593 }
594 }
595  
596 0 ▶sub _multilevel_feature { # turn a single-level feature into a multilevel one
Subroutine _multilevel_feature: not called CC=4 SCAR=30.0
597 0 my $self = shift;
598 0 my $f = shift;
599 0 my $type = shift;
600 0 my %attributes = $f->attributes;
601 0 ▶ $attributes{Score} = [$f->score] if defined $f->score;
Branch: 1 branch
BranchTrueFalseTotal
if defined $f->score 0 0 0
602 0 ▶ $attributes{Phase} = [$f->phase] if defined $f->phase;
Branch: 1 branch
BranchTrueFalseTotal
if defined $f->phase 0 0 0
603 0 ▶ my @args = ($f->display_name,
Condition0%0/3
$type || $f->type
l!l&&r!l&&!r
000
MC/DC0%0/2
$type || $f->type
$type $f->type
Truth table0%0/3
A || B
A= $typeB= $f->type
ABresult
1X1
011
000
604 $type||$f->type,
605 $f->strand,
606 \%attributes,
607 $f->seq_id,
608 $f->start,
609 $f->end);
610 0 my $subpart = $self->_make_feature(@args);
611 0 $f->add_SeqFeature($subpart);
612 }
613  
614 0 ▶sub _make_indexed_feature {
Subroutine _make_indexed_feature: not called CC=1 SCAR=6.9
615 0 my $self = shift;
616 0 my $f = $self->_make_feature(@_);
617 0 my $name = $f->display_name;
618 0 $self->{load_data}{CurrentFeature} = $f;
619 0 $self->{load_data}{CurrentID} = $name;
620 0 $self->_indexit($name => 1);
621 0 return $f;
622 }
623  
624 0 ▶sub _make_feature {
Subroutine _make_feature: not called CC=36 SCAR=71.9
625 0 my $self = shift;
626 0 my ($name,$type,$strand,$attributes,$ref,$start,$end) = @_;
627  
628 # some basic error checking
629 0 ▶ $self->throw("syntax error at line $.: '$_'")
Branch: 1 branch
BranchTrueFalseTotal
if $ref and not defined $start or $ref and not defined $end or $start and not $start =~ /^[-\d]+$/ or $end and not $end =~ /^[-\d]+$/ or not defined $type or not defined $name 0 0 0
Condition0%0/27
$ref and not defined $start or $ref and not defined $end or $start and not $start =~ /^[-\d]+$/ or $end and not $end =~ /^[-\d]+$/ or not defined $type or not defined $name
l!l&&r!l&&!r
000
$ref and not defined $start or $ref and not defined $end or $start and not $start =~ /^[-\d]+$/ or $end and not $end =~ /^[-\d]+$/ or not defined $type
l!l&&r!l&&!r
000
$ref and not defined $start or $ref and not defined $end or $start and not $start =~ /^[-\d]+$/ or $end and not $end =~ /^[-\d]+$/
l!l&&r!l&&!r
000
$ref and not defined $start or $ref and not defined $end or $start and not $start =~ /^[-\d]+$/
l!l&&r!l&&!r
000
$ref and not defined $start or $ref and not defined $end
l!l&&r!l&&!r
000
$ref and not defined $start
!ll&&!rl&&r
000
$ref and not defined $end
!ll&&!rl&&r
000
$start and not $start =~ /^[-\d]+$/
!ll&&!rl&&r
000
$end and not $end =~ /^[-\d]+$/
!ll&&!rl&&r
000
MC/DC0%0/10
$ref and not defined $start or $ref and not defined $end or $start and not $start =~ /^[-\d]+$/ or $end and not $end =~ /^[-\d]+$/ or not defined $type or not defined $name
$ref not defined $start $ref not defined $end $start not $start =~ /^[-\d]+$/ $end not $end =~ /^[-\d]+$/ not defined $type not defined $name
Truth table0%0/63
A and not(B) or C and not(D) or E and not(F) or G and not(H) or not(I) or not(J)
A= $refB= not defined $startC= $refD= not defined $endE= $startF= not $start =~ /^[-\d]+$/G= $endH= not $end =~ /^[-\d]+$/I= not defined $typeJ= not defined $name
ABCDEFGHIJresult
11XXXXXXXX1
0X11XXXXXX1
1011XXXXXX1
0X0X11XXXX1
0X1011XXXX1
100X11XXXX1
101011XXXX1
0X0X0X11XX1
0X0X1011XX1
0X100X11XX1
0X101011XX1
100X0X11XX1
100X1011XX1
10100X11XX1
10101011XX1
0X0X0X0X1X1
0X0X0X101X1
0X0X100X1X1
0X0X10101X1
0X100X0X1X1
0X100X101X1
0X10100X1X1
0X1010101X1
100X0X0X1X1
100X0X101X1
100X100X1X1
100X10101X1
10100X0X1X1
10100X101X1
1010100X1X1
101010101X1
0X0X0X0X011
0X0X0X10011
0X0X100X011
0X0X1010011
0X100X0X011
0X100X10011
0X10100X011
0X101010011
100X0X0X011
100X0X10011
100X100X011
100X1010011
10100X0X011
10100X10011
1010100X011
10101010011
0X0X0X0X000
0X0X0X10000
0X0X100X000
0X0X1010000
0X100X0X000
0X100X10000
0X10100X000
0X101010000
100X0X0X000
100X0X10000
100X100X000
100X1010000
10100X0X000
10100X10000
1010100X000
10101010000
630 if ($ref && !defined $start)
631 or ($ref && !defined $end)
632 or ($start && $start !~ /^[-\d]+$/)
633 or ($end && $end !~ /^[-\d]+$/)
634 or !defined $type
635 or !defined $name;
636  
637 0 ▶ $strand ||= '';
Condition0%0/2
$strand ||= ""
l!l
00
MC/DC0%0/1
$strand ||= ""
$strand
Truth table0%0/2
A
A= $strand
Aresult
11
00
638  
639 0 ▶ my @args = (-name => $name,
Branch: 6 branches
BranchTrueFalseTotal
$strand eq '+' ? : 0 0 0
$strand eq '-' ? : 0 0 0
$strand eq '' ? : 0 0 0
$strand eq '.' ? : 0 0 0
$strand == 1 ? : 0 0 0
$strand == -1 ? : 0 0 0
640 -strand => $strand eq '+' ? 1
641 :$strand eq '-' ? -1
642 :$strand eq '' ? 0
643 :$strand eq '.' ? 0
644 :$strand == 1 ? 1
645 :$strand == -1 ? -1
646 :0,
647 -attributes => $attributes,
648 );
649  
650 0 ▶ if (my ($method,$source) = $type =~ /(\S+):(\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $type =~ /(\S+):(\S+)/) { } 0 0 0
651 0 push @args,(-primary_tag => $method,
652 -source => $source);
653 } else {
654 0 push @args,(-primary_tag => $type);
655 }
656  
657 0 ▶ push @args,(-seq_id => $ref) if defined $ref;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ref 0 0 0
658 0 ▶ push @args,(-start => $start) if defined $start;
Branch: 1 branch
BranchTrueFalseTotal
if defined $start 0 0 0
659 0 ▶ push @args,(-end => $end) if defined $end;
Branch: 1 branch
BranchTrueFalseTotal
if defined $end 0 0 0
660  
661 # pull out special attributes
662 0 ▶ if (my $score = $attributes->{Score} || $attributes->{score}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $score = $attributes->{"Score"} || $attributes->{"score"}) 0 0 0
Condition0%0/3
$attributes->{'Score'} || $attributes->{'score'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attributes->{'Score'} || $attributes->{'score'}
$attributes->{'Score'} $attributes->{'score'}
Truth table0%0/3
A || B
A= $attributes->{'Score'}B= $attributes->{'score'}
ABresult
1X1
011
000
663 0 push @args,(-score => $score->[0]);
664 0 delete $attributes->{$_} foreach qw(Score score);
665 }
666  
667 0 ▶ if (my $note = $attributes->{Note} || $attributes->{note}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $note = $attributes->{"Note"} || $attributes->{"note"}) 0 0 0
Condition0%0/3
$attributes->{'Note'} || $attributes->{'note'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attributes->{'Note'} || $attributes->{'note'}
$attributes->{'Note'} $attributes->{'note'}
Truth table0%0/3
A || B
A= $attributes->{'Note'}B= $attributes->{'note'}
ABresult
1X1
011
000
668 0 push @args,(-desc => join '; ',@$note);
669 0 delete $attributes->{$_} foreach qw(Note note);
670 }
671  
672 0 ▶ if (my $url = $attributes->{url} || $attributes->{Url}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $url = $attributes->{"url"} || $attributes->{"Url"}) 0 0 0
Condition0%0/3
$attributes->{'url'} || $attributes->{'Url'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attributes->{'url'} || $attributes->{'Url'}
$attributes->{'url'} $attributes->{'Url'}
Truth table0%0/3
A || B
A= $attributes->{'url'}B= $attributes->{'Url'}
ABresult
1X1
011
000
673 0 push @args,(-url => $url->[0]);
674 0 delete $attributes->{$_} foreach qw (Url url);
675 }
676  
677 0 ▶ if (my $phase = $attributes->{phase} || $attributes->{Phase}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $phase = $attributes->{"phase"} || $attributes->{"Phase"}) 0 0 0
Condition0%0/3
$attributes->{'phase'} || $attributes->{'Phase'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attributes->{'phase'} || $attributes->{'Phase'}
$attributes->{'phase'} $attributes->{'Phase'}
Truth table0%0/3
A || B
A= $attributes->{'phase'}B= $attributes->{'Phase'}
ABresult
1X1
011
000
678 0 push @args,(-phase => $phase->[0]);
679 0 delete $attributes->{$_} foreach qw (Phase phase);
680 }
681  
682 0 ▶ $self->_indexit($name=>1)
Branch: 1 branch
BranchTrueFalseTotal
if $self->index_subfeatures and $name 0 0 0
Condition0%0/3
$self->index_subfeatures and $name
!ll&&!rl&&r
000
MC/DC0%0/2
$self->index_subfeatures and $name
$self->index_subfeatures $name
Truth table0%0/3
A and B
A= $self->index_subfeaturesB= $name
ABresult
0X0
100
111
683 if $self->index_subfeatures && $name;
684  
685 0 return $self->sfclass->new(@args);
686 }
687  
688 =head2 store_current_feature
689  
690 $loader->store_current_feature()
691  
692 This method is called to store the currently active feature in the
693 database. It uses a data structure stored in $self-E<gt>{load_data}.
694  
695 =cut
696  
697 0 ▶sub store_current_feature { # overridden
Subroutine store_current_feature: not called CC=4 SCAR=30.0
Pod documented
698 0 my $self = shift;
699  
700 # handle open groups
701 # if there is an open group, then we simply add the current
702 # feature to the group.
703 0 my $ld = $self->{load_data};
704 0 ▶ if ($ld->{CurrentGroup} && $ld->{CurrentFeature}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ld->{'CurrentGroup'} and $ld->{'CurrentFeature'}) { } 0 0 0
Condition0%0/3
$ld->{"CurrentGroup"} and $ld->{"CurrentFeature"}
!ll&&!rl&&r
000
MC/DC0%0/2
$ld->{"CurrentGroup"} and $ld->{"CurrentFeature"}
$ld->{"CurrentGroup"} $ld->{"CurrentFeature"}
Truth table0%0/3
A and B
A= $ld->{"CurrentGroup"}B= $ld->{"CurrentFeature"}
ABresult
0X0
100
111
705 $ld->{CurrentGroup}->add_SeqFeature($ld->{CurrentFeature})
706 0 ▶ unless $ld->{CurrentGroup} eq $ld->{CurrentFeature}; # paranoia - shouldn't happen
Branch: 1 branch
BranchTrueFalseTotal
unless $ld->{"CurrentGroup"} eq $ld->{"CurrentFeature"} 0 0 0
707 0 return;
708 }
709 else {
710 0 $self->SUPER::store_current_feature();
711 }
712 }
713  
714 0 ▶sub _store_group {
Subroutine _store_group: not called CC=3 SCAR=24.8
715 0 my $self = shift;
716 0 my $ld = $self->{load_data};
717 0 ▶ my $group = $ld->{CurrentGroup} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $group = $ld->{"CurrentGroup"} or return 0 0 0
718 # if there is an unattached feature, then add it
719 0 ▶ $self->store_current_feature() if $ld->{CurrentFeature};
Branch: 1 branch
BranchTrueFalseTotal
if $ld->{"CurrentFeature"} 0 0 0
720 0 $ld->{CurrentFeature} = $group;
721 0 $ld->{CurrentID} = $group->display_name;
722 0 $self->_indexit($ld->{CurrentID} => 1);
723 0 undef $ld->{CurrentGroup};
724 0 $self->store_current_feature();
725 }
726  
727 =head2 build_object_tree
728  
729 $loader->build_object_tree()
730  
731 This method gathers together features and subfeatures and builds the
732 graph that connects them.
733  
734 =cut
735  
736 ###
737 # put objects together
738 #
739 0 ▶sub build_object_tree {
Subroutine build_object_tree: not called CC=1 SCAR=6.9
Pod documented
740 0 croak "We shouldn't be building an object tree in the FeatureFileLoader";
741 }
742  
743 =head2 build_object_tree_in_tables
744  
745 $loader->build_object_tree_in_tables()
746  
747 This method gathers together features and subfeatures and builds the
748 graph that connects them, assuming that parent/child relationships
749 will be stored in a database table.
750  
751 =cut
752  
753 0 ▶sub build_object_tree_in_tables {
Subroutine build_object_tree_in_tables: not called CC=1 SCAR=6.9
Pod documented
754 0 croak "We shouldn't be building an object tree in the FeatureFileLoader";
755 }
756  
757 =head2 build_object_tree_in_features
758  
759 $loader->build_object_tree_in_features()
760  
761 This method gathers together features and subfeatures and builds the
762 graph that connects them, assuming that parent/child relationships are
763 stored in the seqfeature objects themselves.
764  
765 =cut
766  
767 0 ▶sub build_object_tree_in_features {
Subroutine build_object_tree_in_features: not called CC=1 SCAR=6.9
Pod documented
768 0 croak "We shouldn't be building an object tree in the FeatureFileLoader";
769 }
770  
771 =head2 attach_children
772  
773 $loader->attach_children($store,$load_data,$load_id,$feature)
774  
775 This recursively adds children to features and their subfeatures. It
776 is called when subfeatures are directly contained within other
777 features, rather than stored in a relational table.
778  
779 =cut
780  
781 0 ▶sub attach_children {
Subroutine attach_children: not called CC=1 SCAR=6.9
Pod documented
782 0 croak "We shouldn't be attaching children in the
783 FeatureFileLoader!";
784 }
785  
786 =head2 parse_attributes
787  
788 @attributes = $loader->parse_attributes($attribute_line)
789  
790 This method parses the information contained in the $attribute_line
791 into a flattened hash (array). It may return one element, in which case it is
792 an implicit
793  
794 =cut
795  
796 0 ▶sub parse_attributes {
Subroutine parse_attributes: not called CC=6 SCAR=37.4
Pod documented
797 0 my $self = shift;
798 0 my $att = shift;
799  
800 0 ▶ $att ||= ''; # to prevent uninit variable warnings from quotewords()
Condition0%0/2
$att ||= ""
l!l
00
MC/DC0%0/1
$att ||= ""
$att
Truth table0%0/2
A
A= $att
Aresult
11
00
801  
802 0 my @pairs = quotewords('[;\s]',1,$att);
803 0 my %attributes;
804 0 for my $pair (@pairs) {
805 0 ▶ unless ($pair =~ /=/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pair =~ /=/) { } 0 0 0
806 0 ▶ push @{$attributes{Note}},(quotewords('',0,$pair))[0] || $pair;
Condition0%0/3
(quotewords('', 0, $pair))[0] || $pair
l!l&&r!l&&!r
000
MC/DC0%0/2
(quotewords('', 0, $pair))[0] || $pair
(quotewords('', 0, $pair))[0] $pair
Truth table0%0/3
A || B
A= (quotewords('', 0, $pair))[0]B= $pair
ABresult
1X1
011
000
807 } else {
808 0 my ($tag,$value) = quotewords('\s*=\s*',0,$pair);
809 0 ▶ $tag = 'Note' if $tag eq 'description';
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "description" 0 0 0
810 0 push @{$attributes{$tag}},$value;
811 }
812 }
813 0 return \%attributes;
814 }
815  
816 =head2 start_or_finish_sequence
817  
818 $loader->start_or_finish_sequence('Chr9')
819  
820 This method is called at the beginning and end of a fasta section.
821  
822 =cut
823  
824  
825 1 1;
826  
827 __END__
↑ Summary SeqFeature/Store/DBI/MariaDB.pm »