GFF/Adaptor/memory.pm

filter: Statementstmt 79.5% 307 / 386 Branchbran 61.0% 105 / 172 Conditioncond 46.7% 58 / 124 MC/DCmcdc 27.2% 21 / 77 Subroutinesub 88.8% 32 / 36 Podpod 76.4% 13 / 17 totaltotal 66.0% 536 / 812 CC 152 SCAR 32.2
CC
152
Cov
69%
search_notes
110.0
_feature_by_name
57.5
load_or_store_fasta
56.0
CRAP 25.1
« GFF/Adaptor/dbi/mysql.pm ↑ Summary GFF/Adaptor/dbi/iterator.pm »
1 package Bio::DB::GFF::Adaptor::memory;
2 4 $Bio::DB::GFF::Adaptor::memory::VERSION = '1.7.4';
3 =head1 NAME
4  
5 Bio::DB::GFF::Adaptor::memory -- Bio::DB::GFF database adaptor for in-memory databases
6  
7 =head1 SYNOPSIS
8  
9 use Bio::DB::GFF;
10 my $db = Bio::DB::GFF->new(-adaptor=> 'memory',
11 -gff => 'my_features.gff',
12 -fasta => 'my_dna.fa'
13 );
14  
15 or
16  
17 my $db = Bio::DB::GFF->new(-adaptor=>'memory');
18 $db->load_gff_file('my_features.gff');
19 $db->load_fasta_file('my_dna.fa');
20  
21 See L<Bio::DB::GFF> for other methods.
22  
23 =head1 DESCRIPTION
24  
25 This adaptor implements an in-memory version of Bio::DB::GFF. It can be used to
26 store and retrieve SHORT GFF files. It inherits from Bio::DB::GFF.
27  
28 =head1 CONSTRUCTOR
29  
30 Use Bio::DB::GFF-E<gt>new() to construct new instances of this class.
31 Three named arguments are recommended:
32  
33 Argument Description
34  
35 -adaptor Set to "memory" to create an instance of this class.
36 -gff Read the indicated file or directory of .gff file.
37 -fasta Read the indicated file or directory of fasta files.
38 -dir Indicates a directory containing .gff and .fa files
39  
40 If you use the -dir option and the indicated directory is writable by
41 the current process, then this library will create a FASTA file index
42 that greatly diminishes the memory usage of this module.
43  
44 Alternatively you may create an empty in-memory object using just the
45 -adaptor=E<gt>'memory' argument and then call the load_gff_file() and
46 load_fasta_file() methods to load GFF and/or sequence
47 information. This is recommended in CGI/mod_perl/fastCGI environments
48 because these methods do not modify STDIN, unlike the constructor.
49  
50 =head1 METHODS
51  
52 See L<Bio::DB::GFF> for inherited methods.
53  
54 =head1 BUGS
55  
56 none ;-)
57  
58 =head1 SEE ALSO
59  
60 L<Bio::DB::GFF>, L<bioperl>
61  
62 =head1 AUTHOR
63  
64 Shuly Avraham E<lt>avraham@cshl.orgE<gt>.
65  
66 Copyright (c) 2002 Cold Spring Harbor Laboratory.
67  
68 This library is free software; you can redistribute it and/or modify
69 it under the same terms as Perl itself.
70  
71 =cut
72  
73 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
74 # AUTHOR: Shulamit Avraham
75 # This module needs to be cleaned up and documented
76  
77 # Bio::DB::GFF::Adaptor::memory -- in-memory db adaptor
78 # implements the low level handling of data which stored in memory.
79 # This adaptor implements a specific in memory schema that is compatible with Bio::DB::GFF.
80 # Inherits from Bio::DB::GFF.
81  
82  
83 4 ▶use Bio::DB::GFF::Util::Rearrange; # for rearrange()
Subroutine BEGIN: called CC=1 SCAR=0.0
84 4 ▶use Bio::DB::GFF::Adaptor::memory::iterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 4 ▶use File::Basename 'dirname';
Subroutine BEGIN: called CC=1 SCAR=0.0
86 4 ▶use Bio::DB::GFF::Adaptor::memory::feature_serializer qw(@hash2array_map);
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88  
89 4 ▶use constant MAX_SEGMENT => 1_000_000_000; # the largest a segment can get
Subroutine BEGIN: called CC=1 SCAR=0.0
90  
91 4 ▶use base qw(Bio::DB::GFF);
Subroutine BEGIN: called CC=1 SCAR=0.0
92  
93 5 ▶sub new {
Subroutine new: called CC=6 SCAR=19.9
Pod documented
94 5 my $class = shift ;
95 5 my ($file,$fasta,$dbdir,$preferred_groups) = rearrange([
96 [qw(GFF FILE)],
97 'FASTA',
98 [qw(DSN DB DIR DIRECTORY)],
99 'PREFERRED_GROUPS',
100 ],@_);
101  
102 # fill in object
103 5 my $self = bless{ data => [] },$class;
104 5 ▶ $self->preferred_groups($preferred_groups) if defined $preferred_groups;
Branch: 1 branch
BranchTrueFalseTotal
if defined $preferred_groups 0 5 5
105 5 ▶ $file ||= $dbdir;
Condition33%1/3
$file ||= $dbdir
l!l&&r!l&&!r
005
MC/DC0%0/2
$file ||= $dbdir
$file $dbdir
Truth table33%1/3
A ||= B
A= $fileB= $dbdir
ABresult
1X1
011
000
106 5 ▶ $fasta ||= $dbdir;
Condition33%1/3
$fasta ||= $dbdir
l!l&&r!l&&!r
005
MC/DC0%0/2
$fasta ||= $dbdir
$fasta $dbdir
Truth table33%1/3
A ||= B
A= $fastaB= $dbdir
ABresult
1X1
011
000
107 5 ▶ $self->load_gff($file) if $file;
Branch: 1 branch
BranchTrueFalseTotal
if $file 0 5 5
108 5 ▶ $self->load_or_store_fasta($fasta) if $fasta;
Branch: 1 branch
BranchTrueFalseTotal
if $fasta 0 5 5
109 5 return $self;
110 }
111  
112 0 ▶sub load_or_store_fasta {
Subroutine load_or_store_fasta: not called CC=7 SCAR=40.3
Pod undocumented
113 0 my $self = shift;
114 0 my $fasta = shift;
115 0 ▶ if ((-f $fasta && -w dirname($fasta))
Branch: 1 branch
BranchTrueFalseTotal
if (-f $fasta and -w dirname($fasta) or -d $fasta and -w $fasta) { } 0 0 0
Condition0%0/9
-f $fasta and -w dirname($fasta) or -d $fasta and -w $fasta
l!l&&r!l&&!r
000
-f $fasta and -w dirname($fasta)
!ll&&!rl&&r
000
-d $fasta and -w $fasta
!ll&&!rl&&r
000
MC/DC0%0/4
-f $fasta and -w dirname($fasta) or -d $fasta and -w $fasta
-f $fasta -w dirname($fasta) -d $fasta -w $fasta
Truth table0%0/7
A and B or C and D
A= -f $fastaB= -w dirname($fasta)C= -d $fastaD= -w $fasta
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
116 or
117 (-d $fasta && -w $fasta)) {
118 0 require Bio::DB::Fasta;
119 0 ▶ my $dna_db = eval {Bio::DB::Fasta->new($fasta);}
Branch: 1 branch
BranchTrueFalseTotal
my $dna_db = eval { do { "Bio::DB::Fasta"->new($fasta) } } or warn "$@\nCan't open sequence file(s). Use -gff instead of -dir if you wish to load features without sequence.\n" 0 0 0
120 or warn "$@\nCan't open sequence file(s). Use -gff instead of -dir if you wish to load features without sequence.\n";
121 0 ▶ $dna_db && $self->dna_db($dna_db);
Branch: 1 branch
BranchTrueFalseTotal
$dna_db and $self->dna_db($dna_db) 0 0 0
122 } else {
123 0 $self->load_fasta($fasta);
124 }
125 }
126  
127 120 ▶sub dna_db {
Subroutine dna_db: called CC=2 SCAR=7.0
Pod undocumented
128 120 my $self = shift;
129 120 my $d = $self->{dna_db};
130 120 ▶ $self->{dna_db} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 120 120
131 120 $d;
132 }
133  
134 2620 ▶sub insert_sequence {
Subroutine insert_sequence: called CC=1 SCAR=0.0
Pod undocumented
135 2620 my $self = shift;
136 2620 my($id,$offset,$seq) = @_;
137 2620 $self->{dna}{$id} .= $seq;
138 }
139  
140 # low-level fetch of a DNA substring given its
141 # name, class and the desired range.
142 120 ▶sub get_dna {
Subroutine get_dna: called CC=8 SCAR=21.1
Pod documented
143 120 my $self = shift;
144 120 my ($id,$start,$stop,$class) = @_;
145 120 ▶ if (my $dna_db = $self->dna_db) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dna_db = $self->dna_db) 0 120 120
146 0 return $dna_db->seq($id,$start=>$stop);
147 }
148 120 ▶ return '' unless $self->{dna};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"dna"} 0 120 120
149  
150 120 ▶ return $self->{dna}{$id} unless defined $start || defined $stop;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start or defined $stop 5 115 120
Condition66%2/3
defined $start or defined $stop
l!l&&r!l&&!r
11505
MC/DC50%1/2
defined $start or defined $stop
defined $start defined $stop
Truth table66%2/3
A or B
A= defined $startB= defined $stop
ABresult
1X1
011
000
151 115 ▶ $start = 1 if !defined $start;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start 0 115 115
152  
153 115 my $reversed = 0;
154 115 ▶ if ($start > $stop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start > $stop) 55 60 115
155 55 $reversed++;
156 55 ($start,$stop) = ($stop,$start);
157 }
158 115 my $dna = substr($self->{dna}{$id},$start-1,$stop-$start+1);
159 115 ▶ if ($reversed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reversed) 55 60 115
160 55 $dna =~ tr/gatcGATC/ctagCTAG/;
161 55 $dna = reverse $dna;
162 }
163  
164 115 $dna;
165 }
166  
167 5 ▶sub setup_load {
Subroutine setup_load: called CC=1 SCAR=0.0
Pod documented
168 5 my $self = shift;
169 5 $self->{tmp} = {};
170 5 $self->{data} = [];
171 5 1;
172 }
173  
174 5 ▶sub finish_load {
Subroutine finish_load: called CC=3 SCAR=11.0
Pod documented
175 5 my $self = shift;
176 5 my $idx = 0;
177 5 foreach my $arrayref (values %{$self->{tmp}}) {
178 92 foreach (@$arrayref) {$_->{feature_id} = $idx++; }
179 92 push @{$self->{data}},@$arrayref;
180 }
181 5 1;
182 }
183  
184 # this method loads the feature as a hash into memory -
185 # keeps an array of features-hashes as an in-memory db
186 175 ▶sub load_gff_line {
Subroutine load_gff_line: called CC=6 SCAR=19.0
Pod documented
187 175 my $self = shift;
188 175 my $feature_hash = shift;
189 175 ▶ $feature_hash->{strand} = '' if $feature_hash->{strand} && $feature_hash->{strand} eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $feature_hash->{"strand"} and $feature_hash->{"strand"} eq "." 0 175 175
Condition66%2/3
$feature_hash->{"strand"} and $feature_hash->{"strand"} eq "."
!ll&&!rl&&r
551200
MC/DC0%0/2
$feature_hash->{"strand"} and $feature_hash->{"strand"} eq "."
$feature_hash->{"strand"} $feature_hash->{"strand"} eq "."
Truth table66%2/3
A and B
A= $feature_hash->{"strand"}B= $feature_hash->{"strand"} eq "."
ABresult
0X0
100
111
190 175 ▶ $feature_hash->{phase} = '' if $feature_hash->{phase} && $feature_hash->{phase} eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $feature_hash->{"phase"} and $feature_hash->{"phase"} eq "." 0 175 175
Condition66%2/3
$feature_hash->{"phase"} and $feature_hash->{"phase"} eq "."
!ll&&!rl&&r
17050
MC/DC0%0/2
$feature_hash->{"phase"} and $feature_hash->{"phase"} eq "."
$feature_hash->{"phase"} $feature_hash->{"phase"} eq "."
Truth table66%2/3
A and B
A= $feature_hash->{"phase"}B= $feature_hash->{"phase"} eq "."
ABresult
0X0
100
111
191 175 ▶ $feature_hash->{gclass} = 'Sequence' unless length $feature_hash->{gclass} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless length $feature_hash->{"gclass"} > 0 0 175 175
192 # sort by group please
193 175 push @{$self->{tmp}{$feature_hash->{gclass},$feature_hash->{gname}}},$feature_hash;
194 }
195  
196 # given sequence name, return (reference,start,stop,strand)
197 193 ▶sub get_abscoords {
Subroutine get_abscoords: called CC=23 SCAR=33.3
Pod documented
198 193 my $self = shift;
199 193 my ($name,$class,$refseq) = @_;
200 193 my %refs;
201 my $regexp;
202
203 193 ▶ if ($name =~ /[*?]/) { # uh oh regexp time
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /[*?]/) 0 193 193
204 0 $name = quotemeta($name);
205 0 $name =~ s/\\\*/.*/g;
206 0 $name =~ s/\\\?/.?/g;
207 0 $regexp++;
208 }
209  
210 # Find all features that have the requested name and class.
211 # Sort them by reference point.
212 193 for my $feature (@{$self->{data}}) {
213  
214 6560 my $no_match_class_name;
215 my $empty_class_name;
216 my $class_matches = !defined($feature->{gclass}) ||
217 length($feature->{gclass}) == 0 ||
218 6560 ▶ $feature->{gclass} eq $class;
Condition50%3/6
!defined($feature->{'gclass'}) || length $feature->{'gclass'} == 0 || $feature->{'gclass'} eq $class
l!l&&r!l&&!r
010655495
not defined $feature->{"gclass"} or length $feature->{"gclass"} == 0
l!l&&r!l&&!r
006560
MC/DC33%1/3
!defined($feature->{'gclass'}) || length $feature->{'gclass'} == 0 || $feature->{'gclass'} eq $class
not defined $feature->{"gclass"} length $feature->{"gclass"} == 0 $feature->{'gclass'} eq $class
Truth table50%2/4
not(A) or B || C
A= not defined $feature->{"gclass"}B= length $feature->{"gclass"} == 0C= $feature->{'gclass'} eq $class
ABCresult
1XX1
01X1
0011
0000
219  
220 6560 ▶ if (defined $feature->{gname}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $feature->{'gname'}) { } 6560 0 6560
221 my $matches = $class_matches
222 6560 ▶ && ($regexp ? $feature->{gname} =~ /$name/i : lc($feature->{gname}) eq lc($name));
Branch: 1 branch
BranchTrueFalseTotal
$regexp ? : 0 1065 1065
Condition100%3/3
$class_matches && ($regexp ? $feature->{'gname'} =~ /$name/i : lc $feature->{'gname'} eq lc $name)
!ll&&!rl&&r
5495675390
MC/DC100%2/2
$class_matches && ($regexp ? $feature->{'gname'} =~ /$name/i : lc $feature->{'gname'} eq lc $name)
$class_matches ($regexp ? $feature->{'gname'} =~ /$name/i : lc $feature->{'gname'} eq lc $name)
Truth table100%3/3
A && B
A= $class_matchesB= ($regexp ? $feature->{'gname'} =~ /$name/i : lc $feature->{'gname'} eq lc $name)
ABresult
0X0
100
111
223 6560 $no_match_class_name = !$matches; # to accomodate Shuly's interesting logic
224 }
225  
226 else{
227 0 $empty_class_name = 1;
228 }
229  
230 6560 ▶ if ($no_match_class_name){
Branch: 1 branch
BranchTrueFalseTotal
if ($no_match_class_name) 6170 390 6560
231 6170 my $feature_attributes = $feature->{attributes};
232 6170 my $attributes = {Alias => $name};
233 6170 ▶ if (!$self->_matching_attributes($feature_attributes,$attributes)){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_matching_attributes($feature_attributes, $attributes)) 6165 5 6170
234 6165 next;
235 }
236 }
237  
238 395 push @{$refs{$feature->{ref}}},$feature;
239 }
240  
241 # find out how many reference points we recovered
242 193 ▶ if (! %refs) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%refs) 8 185 193
243 8 $self->error("$name not found in database");
244 8 return;
245 }
246  
247 # compute min and max
248 185 my ($ref) = keys %refs;
249 185 my @found = @{$refs{$ref}};
250 185 my ($strand,$start,$stop);
251  
252 185 my @found_segments;
253 185 foreach my $ref (keys %refs) {
254 185 ▶ next if defined($refseq) and lc($ref) ne lc($refseq);
Branch: 1 branch
BranchTrueFalseTotal
if defined $refseq and lc $ref ne lc $refseq 0 185 185
Condition33%1/3
defined $refseq and lc $ref ne lc $refseq
!ll&&!rl&&r
18500
MC/DC0%0/2
defined $refseq and lc $ref ne lc $refseq
defined $refseq lc $ref ne lc $refseq
Truth table33%1/3
A and B
A= defined $refseqB= lc $ref ne lc $refseq
ABresult
0X0
100
111
255 185 my @found = @{$refs{$ref}};
256 185 my ($strand,$start,$stop,$name);
257 185 foreach (@found) {
258 395 ▶ $strand ||= $_->{strand};
Condition100%3/3
$strand ||= $_->{"strand"}
l!l&&r!l&&!r
21080105
MC/DC100%2/2
$strand ||= $_->{"strand"}
$strand $_->{"strand"}
Truth table100%3/3
A ||= B
A= $strandB= $_->{"strand"}
ABresult
1X1
011
000
259 395 ▶ $strand = '+' if $strand && $strand eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $strand and $strand eq "." 0 395 395
Condition66%2/3
$strand and $strand eq "."
!ll&&!rl&&r
1052900
MC/DC0%0/2
$strand and $strand eq "."
$strand $strand eq "."
Truth table66%2/3
A and B
A= $strandB= $strand eq "."
ABresult
0X0
100
111
260 395 ▶ $start = $_->{start} if !defined($start) || $start > $_->{start};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $start or $start > $_->{"start"} 185 210 395
Condition66%2/3
not defined $start or $start > $_->{"start"}
l!l&&r!l&&!r
1850210
MC/DC50%1/2
not defined $start or $start > $_->{"start"}
not defined $start $start > $_->{"start"}
Truth table66%2/3
not(A) or B
A= not defined $startB= $start > $_->{"start"}
ABresult
1X1
011
000
261 395 ▶ $stop = $_->{stop} if !defined($stop) || $stop < $_->{stop};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $stop or $stop < $_->{"stop"} 185 210 395
Condition66%2/3
not defined $stop or $stop < $_->{"stop"}
l!l&&r!l&&!r
1850210
MC/DC50%1/2
not defined $stop or $stop < $_->{"stop"}
not defined $stop $stop < $_->{"stop"}
Truth table66%2/3
not(A) or B
A= not defined $stopB= $stop < $_->{"stop"}
ABresult
1X1
011
000
262 395 ▶ $name ||= $_->{gname};
Condition66%2/3
$name ||= $_->{"gname"}
l!l&&r!l&&!r
2101850
MC/DC0%0/2
$name ||= $_->{"gname"}
$name $_->{"gname"}
Truth table66%2/3
A ||= B
A= $nameB= $_->{"gname"}
ABresult
1X1
011
000
263 }
264 185 push @found_segments,[$ref,$class,$start,$stop,$strand,$name];
265  
266 }
267  
268 185 return \@found_segments;
269 }
270  
271 0 ▶sub search_notes {
Subroutine search_notes: not called CC=10 SCAR=47.0
Pod documented
272 0 my $self = shift;
273 0 my ($search_string,$limit) = @_;
274  
275 0 $search_string =~ tr/*?//d;
276  
277 0 my @results;
278 0 my @words = map {quotemeta($_)} $search_string =~ /(\w+)/g;
279 0 my $search = join '|',@words;
280  
281 0 for my $feature (@{$self->{data}}) {
282 0 ▶ next unless defined $feature->{gclass} && defined $feature->{gname}; # ignore NULL objects
Branch: 1 branch
BranchTrueFalseTotal
unless defined $feature->{"gclass"} and defined $feature->{"gname"} 0 0 0
Condition0%0/3
defined $feature->{"gclass"} and defined $feature->{"gname"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $feature->{"gclass"} and defined $feature->{"gname"}
defined $feature->{"gclass"} defined $feature->{"gname"}
Truth table0%0/3
A and B
A= defined $feature->{"gclass"}B= defined $feature->{"gname"}
ABresult
0X0
100
111
283 0 ▶ next unless $feature->{attributes};
Branch: 1 branch
BranchTrueFalseTotal
unless $feature->{"attributes"} 0 0 0
284 0 my @attributes = @{$feature->{attributes}};
285 0 my @values = map {$_->[1]} @attributes;
286 0 my $value = "@values";
287 0 my $matches = 0;
288 0 for my $w (@words) {
289 0 my @hits = $value =~ /($w)/ig;
290 0 $matches += @hits;
291 }
292 0 ▶ next unless $matches;
Branch: 1 branch
BranchTrueFalseTotal
unless $matches 0 0 0
293  
294 0 my $relevance = 10 * $matches;
295 0 my $featname = Bio::DB::GFF::Featname->new($feature->{gclass}=>$feature->{gname});
296 0 my $note;
297 0 $note = join ' ',map {$_->[1]} grep {$_->[0] eq 'Note'} @{$feature->{attributes}};
298 0 $note .= join ' ',grep /$search/,map {$_->[1]} grep {$_->[0] ne 'Note'} @{$feature->{attributes}};
299 0 my $type = Bio::DB::GFF::Typename->new($feature->{method},$feature->{source});
300 0 push @results,[$featname,$note,$relevance,$type];
301 0 ▶ last if defined $limit && @results >= $limit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $limit and @results >= $limit 0 0 0
Condition0%0/3
defined $limit and @results >= $limit
!ll&&!rl&&r
000
MC/DC0%0/2
defined $limit and @results >= $limit
defined $limit @results >= $limit
Truth table0%0/3
A and B
A= defined $limitB= @results >= $limit
ABresult
0X0
100
111
302 }
303  
304 #added result filtering so that this method returns the expected results
305 #this section of code used to be in GBrowse's do_keyword_search method
306  
307 0 my $match_sub = 'sub {';
308 0 foreach (split /\s+/,$search_string) {
309 0 $match_sub .= "return unless \$_[0] =~ /\Q$_\E/i; ";
310 }
311 0 $match_sub .= "};";
312 0 my $match = eval $match_sub;
313  
314 0 my @matches = grep { $match->($_->[1]) } @results;
315  
316 0 return @matches;
317 }
318  
319 20 ▶sub _delete_features {
Subroutine _delete_features: called CC=4 SCAR=14.2
320 20 my $self = shift;
321 20 my @feature_ids = sort {$b<=>$a} @_;
322 20 my $removed = 0;
323 20 foreach (@feature_ids) {
324 75 ▶ next unless $_ >= 0 && $_ < @{$self->{data}};
Branch: 1 branch
BranchTrueFalseTotal
unless $_ >= 0 and $_ < @{$self->{"data"};} 0 75 75
Condition33%1/3
$_ >= 0 and $_ < @{$self->{"data"};}
!ll&&!rl&&r
0075
MC/DC0%0/2
$_ >= 0 and $_ < @{$self->{"data"};}
$_ >= 0 $_ < @{$self->{"data"};}
Truth table33%1/3
A and B
A= $_ >= 0B= $_ < @{$self->{"data"};}
ABresult
0X0
100
111
325 75 $removed += defined splice(@{$self->{data}},$_,1);
326 }
327 20 $removed;
328 }
329  
330 21 ▶sub _delete {
Subroutine _delete: called CC=7 SCAR=19.5
331 21 my $self = shift;
332 21 my $delete_spec = shift;
333 21 ▶ my $ranges = $delete_spec->{segments} || [];
Condition50%1/2
$delete_spec->{'segments'} || []
l!l
210
MC/DC0%0/1
$delete_spec->{'segments'} || []
$delete_spec->{'segments'}
Truth table50%1/2
A
A= $delete_spec->{'segments'}
Aresult
11
00
334 21 ▶ my $types = $delete_spec->{types} || [];
Condition50%1/2
$delete_spec->{'types'} || []
l!l
210
MC/DC0%0/1
$delete_spec->{'types'} || []
$delete_spec->{'types'}
Truth table50%1/2
A
A= $delete_spec->{'types'}
Aresult
11
00
335 21 my $force = $delete_spec->{force};
336 21 my $range_type = $delete_spec->{range_type};
337  
338 21 my $deleted = 0;
339 21 ▶ if (@$ranges) {
Branch: 2 branches
BranchTrueFalseTotal
if (@$ranges) { } 10 11 21
elsif (@$types) { } 5 6 11
340 10 ▶ my @args = @$types ? (-type=>$types) : ();
Branch: 1 branch
BranchTrueFalseTotal
@$types ? : 5 5 10
341 10 push @args,(-range_type => $range_type);
342 10 my %ids_to_remove = map {$_->id => 1} map {$_->features(@args)} @$ranges;
343 10 $deleted = $self->delete_features(keys %ids_to_remove);
344 } elsif (@$types) {
345 5 my %ids_to_remove = map {$_->id => 1} $self->features(-type=>$types);
346 5 $deleted = $self->delete_features(keys %ids_to_remove);
347 } else {
348 6 ▶ $self->throw("This operation would delete all feature data and -force not specified")
Branch: 1 branch
BranchTrueFalseTotal
unless $force 3 3 6
349 unless $force;
350 3 $deleted = @{$self->{data}};
351 3 @{$self->{data}} = ();
352 }
353 18 $deleted;
354 }
355  
356 # attributes -
357  
358 # Some GFF version 2 files use the groups column to store a series of
359 # attribute/value pairs. In this interpretation of GFF, the first such
360 # pair is treated as the primary group for the feature; subsequent pairs
361 # are treated as attributes. Two attributes have special meaning:
362 # "Note" is for backward compatibility and is used for unstructured text
363 # remarks. "Alias" is considered as a synonym for the feature name.
364 # If no name is provided, then attributes() returns a flattened hash, of
365 # attribute=>value pairs.
366  
367 20 ▶sub do_attributes{
Subroutine do_attributes: called CC=5 SCAR=16.1
Pod documented
368 20 my $self = shift;
369 20 my ($feature_id,$tag) = @_;
370 20 my $attr ;
371  
372 #my $feature = ${$self->{data}}[$feature_id];
373 20 my $feature = $self->_basic_features_by_id($feature_id);
374  
375 20 my @result;
376 20 for my $attr (@{$feature->{attributes}}) {
377 50 my ($attr_name,$attr_value) = @$attr ;
378 50 ▶ if (defined($tag) && lc($attr_name) eq lc($tag)){push @result,$attr_value;}
Branch: 2 branches
BranchTrueFalseTotal
if (defined $tag and lc $attr_name eq lc $tag) { } 20 30 50
elsif (not defined $tag) { } 15 15 30
Condition100%3/3
defined $tag and lc $attr_name eq lc $tag
!ll&&!rl&&r
151520
MC/DC100%2/2
defined $tag and lc $attr_name eq lc $tag
defined $tag lc $attr_name eq lc $tag
Truth table100%3/3
A and B
A= defined $tagB= lc $attr_name eq lc $tag
ABresult
0X0
100
111
379 15 elsif (!defined($tag)) {push @result,($attr_name,$attr_value);}
380 }
381 20 return @result;
382 }
383  
384  
385 #sub get_feature_by_attribute{
386 5 ▶sub _feature_by_attribute{
Subroutine _feature_by_attribute: called CC=7 SCAR=19.5
387 5 my $self = shift;
388 5 my ($attributes,$callback) = @_;
389 5 ▶ $callback || $self->throw('must provide a callback argument');
Branch: 1 branch
BranchTrueFalseTotal
$callback or $self->throw("must provide a callback argument") 5 0 5
390 5 my $count = 0;
391 5 my $feature_id = -1;
392 5 my $feature_group_id = undef;
393  
394 5 for my $feature (@{$self->{data}}) {
395  
396 175 $feature_id++;
397 175 for my $attr (@{$feature->{attributes}}) {
398 65 my ($attr_name,$attr_value) = @$attr ;
399 #there could be more than one set of attributes......
400 65 foreach (keys %$attributes) {
401 65 ▶ if (lc($_) eq lc($attr_name) && lc($attributes->{$_}) eq lc($attr_value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $_ eq lc $attr_name and lc $attributes->{$_} eq lc $attr_value) 10 55 65
Condition100%3/3
lc $_ eq lc $attr_name and lc $attributes->{$_} eq lc $attr_value
!ll&&!rl&&r
411410
MC/DC100%2/2
lc $_ eq lc $attr_name and lc $attributes->{$_} eq lc $attr_value
lc $_ eq lc $attr_name lc $attributes->{$_} eq lc $attr_value
Truth table100%3/3
A and B
A= lc $_ eq lc $attr_nameB= lc $attributes->{$_} eq lc $attr_value
ABresult
0X0
100
111
402 10 $callback->($self->_hash_to_array($feature));
403 10 $count++;
404 }
405 }
406 }
407 }
408  
409 }
410  
411  
412 # This is the low-level method that is called to retrieve GFF lines from
413 # the database. It is responsible for retrieving features that satisfy
414 # range and feature type criteria, and passing the GFF fields to a
415 # callback subroutine.
416  
417 85 ▶sub get_features{
Subroutine get_features: called CC=3 SCAR=11.4
Pod documented
418 85 my $self = shift;
419 85 my $count = 0;
420 85 my ($search,$options,$callback) = @_;
421  
422 85 my $found_features;
423  
424 85 $found_features = $self->_get_features_by_search_options($search,$options);
425  
426 # only true if the sort by group option was specified
427 0 @{$found_features} = sort {lc("$a->{gclass}:$a->{gname}") cmp lc("$b->{gclass}:$b->{gname}")}
428 0 ▶ @{$found_features} if $options->{sort_by_group} ;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"sort_by_group"} 0 85 85
429  
430 85 for my $feature (@{$found_features}) { # only true if the sort by group option was specified
431 470 $count++;
432 470 $callback->(
433 $self->_hash_to_array($feature)
434 );
435 }
436  
437 85 return $count;
438 }
439  
440  
441 # Low level implementation of fetching a named feature.
442 # GFF annotations are named using the group class and name fields.
443 # May return zero, one, or several Bio::DB::GFF::Feature objects.
444  
445 =head2 _feature_by_name
446  
447 Title : _feature_by_name
448 Usage : $db->get_features_by_name($name,$class,$callback)
449 Function: get a list of features by name and class
450 Returns : count of number of features retrieved
451 Args : name of feature, class of feature, and a callback
452 Status : protected
453  
454 This method is used internally. The callback arguments are those used
455 by make_feature().
456  
457 =cut
458  
459 16 ▶sub _feature_by_name {
Subroutine _feature_by_name: called CC=16 SCAR=40.5
460 16 my $self = shift;
461 16 my ($class,$name,$location,$callback) = @_;
462 16 ▶ $callback || $self->throw('must provide a callback argument');
Branch: 1 branch
BranchTrueFalseTotal
$callback or $self->throw("must provide a callback argument") 16 0 16
463 16 my $count = 0;
464 16 my $regexp;
465  
466 16 ▶ if ($name =~ /[*?]/) { # uh oh regexp time
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /[*?]/) 0 16 16
467 0 $name = quotemeta($name);
468 0 $name =~ s/\\\*/.*/g;
469 0 $name =~ s/\\\?/.?/g;
470 0 $regexp++;
471 }
472  
473 16 for my $feature (@{$self->{data}}) {
474 560 ▶ next unless ($regexp && $feature->{gname} =~ /$name/i) || lc($feature->{gname}) eq lc($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $regexp and $feature->{"gname"} =~ /$name/i or lc $feature->{"gname"} eq lc $name 486 74 560
Condition50%3/6
$regexp and $feature->{"gname"} =~ /$name/i or lc $feature->{"gname"} eq lc $name
l!l&&r!l&&!r
074486
$regexp and $feature->{"gname"} =~ /$name/i
!ll&&!rl&&r
56000
MC/DC33%1/3
$regexp and $feature->{"gname"} =~ /$name/i or lc $feature->{"gname"} eq lc $name
$regexp $feature->{"gname"} =~ /$name/i lc $feature->{"gname"} eq lc $name
Truth table40%2/5
A and B or C
A= $regexpB= $feature->{"gname"} =~ /$name/iC= lc $feature->{"gname"} eq lc $name
ABCresult
11X1
0X11
1011
0X00
1000
475 74 ▶ next if defined($feature->{gclass}) && length($feature->{gclass}) > 0 && $feature->{gclass} ne $class;
Branch: 1 branch
BranchTrueFalseTotal
if defined $feature->{"gclass"} and length $feature->{"gclass"} > 0 and $feature->{"gclass"} ne $class 0 74 74
Condition33%2/6
defined $feature->{"gclass"} and length $feature->{"gclass"} > 0 and $feature->{"gclass"} ne $class
!ll&&!rl&&r
0740
defined $feature->{"gclass"} and length $feature->{"gclass"} > 0
!ll&&!rl&&r
0074
MC/DC0%0/3
defined $feature->{"gclass"} and length $feature->{"gclass"} > 0 and $feature->{"gclass"} ne $class
defined $feature->{"gclass"} length $feature->{"gclass"} > 0 $feature->{"gclass"} ne $class
Truth table25%1/4
A and B and C
A= defined $feature->{"gclass"}B= length $feature->{"gclass"} > 0C= $feature->{"gclass"} ne $class
ABCresult
0XX0
10X0
1100
1111
476  
477 74 ▶ if ($location) {
Branch: 1 branch
BranchTrueFalseTotal
if ($location) 0 74 74
478 0 ▶ next if $location->[0] ne $feature->{ref};
Branch: 1 branch
BranchTrueFalseTotal
if $location->[0] ne $feature->{"ref"} 0 0 0
479 0 ▶ next if $location->[1] && $location->[1] > $feature->{stop};
Branch: 1 branch
BranchTrueFalseTotal
if $location->[1] and $location->[1] > $feature->{"stop"} 0 0 0
Condition0%0/3
$location->[1] and $location->[1] > $feature->{"stop"}
!ll&&!rl&&r
000
MC/DC0%0/2
$location->[1] and $location->[1] > $feature->{"stop"}
$location->[1] $location->[1] > $feature->{"stop"}
Truth table0%0/3
A and B
A= $location->[1]B= $location->[1] > $feature->{"stop"}
ABresult
0X0
100
111
480 0 ▶ next if $location->[2] && $location->[2] < $feature->{start};
Branch: 1 branch
BranchTrueFalseTotal
if $location->[2] and $location->[2] < $feature->{"start"} 0 0 0
Condition0%0/3
$location->[2] and $location->[2] < $feature->{"start"}
!ll&&!rl&&r
000
MC/DC0%0/2
$location->[2] and $location->[2] < $feature->{"start"}
$location->[2] $location->[2] < $feature->{"start"}
Truth table0%0/3
A and B
A= $location->[2]B= $location->[2] < $feature->{"start"}
ABresult
0X0
100
111
481 }
482 74 $count++;
483 74 $callback->($self->_hash_to_array($feature),0);
484 }
485 16 return $count;
486 }
487  
488 # Low level implementation of fetching a feature by it's id.
489 # The id of the feature as implemented in the in-memory db, is the location of the
490 # feature in the features hash array.
491 5 ▶sub _feature_by_id{
Subroutine _feature_by_id: called CC=5 SCAR=16.4
492 5 my $self = shift;
493 5 my ($ids,$type,$callback) = @_;
494 5 ▶ $callback || $self->throw('must provide a callback argument');
Branch: 1 branch
BranchTrueFalseTotal
$callback or $self->throw("must provide a callback argument") 5 0 5
495  
496 5 my $feature_group_id = undef;
497  
498 5 my $count = 0;
499 5 ▶ if ($type eq 'feature'){
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "feature") 5 0 5
500 5 for my $feature_id (@$ids){
501 5 my $feature = $self->_basic_features_by_id($feature_id);
502 5 ▶ $callback->($self->_hash_to_array($feature)) if $callback;
Branch: 1 branch
BranchTrueFalseTotal
if $callback 5 0 5
503 5 $count++;
504 }
505 }
506 }
507  
508 25 ▶sub _basic_features_by_id{
Subroutine _basic_features_by_id: called CC=4 SCAR=14.0
509 25 my $self = shift;
510 25 my ($ids) = @_;
511
512 25 ▶ $ids = [$ids] unless ref $ids =~ /ARRAY/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ids =~ /ARRAY/ 25 0 25
513  
514 25 my @result;
515 25 for my $feature_id (@$ids){
516 25 push @result, ${$self->{data}}[$feature_id];
517 }
518 25 ▶ return wantarray() ? @result : $result[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 25 25
519 }
520  
521 # This method is similar to get_features(), except that it returns an
522 # iterator across the query.
523 # See Bio::DB::GFF::Adaptor::memory::iterator.
524  
525 15 ▶sub get_features_iterator {
Subroutine get_features_iterator: called CC=2 SCAR=7.0
Pod documented
526 15 my $self = shift;
527 15 my ($search,$options,$callback) = @_;
528 15 ▶ $callback || $self->throw('must provide a callback argument');
Branch: 1 branch
BranchTrueFalseTotal
$callback or $self->throw("must provide a callback argument") 15 0 15
529  
530 15 my $results = $self->_get_features_by_search_options($search,$options);
531 15 my $results_array = $self->_convert_feature_hash_to_array($results);
532  
533 15 return Bio::DB::GFF::Adaptor::memory::iterator->new($results_array,$callback);
534 }
535  
536  
537 # This method is responsible for fetching the list of feature type names.
538 # The query may be limited to a particular range, in
539 # which case the range is indicated by a landmark sequence name and
540 # class and its subrange, if any. These arguments may be undef if it is
541 # desired to retrieve all feature types.
542  
543 # If the count flag is false, the method returns a simple list of
544 # Bio::DB::GFF::Typename objects. If $count is true, the method returns
545 # a list of $name=>$count pairs, where $count indicates the number of
546 # times this feature occurs in the range.
547  
548 25 ▶sub get_types {
Subroutine get_types: called CC=17 SCAR=32.8
Pod documented
549 25 my $self = shift;
550 25 my ($srcseq,$class,$start,$stop,$want_count,$typelist) = @_;
551  
552 25 my(%result,%obj);
553  
554 25 for my $feature (@{$self->{data}}) {
555 875 my $feature_start = $feature->{start};
556 875 my $feature_stop = $feature->{stop};
557 875 my $feature_ref = $feature->{ref};
558 875 my $feature_class = $feature->{class};
559 875 my $feature_method = $feature->{method};
560 875 my $feature_source = $feature->{source};
561  
562 875 ▶ if (defined $srcseq){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $srcseq) 525 350 875
563 525 ▶ next unless lc($feature_ref) eq lc($srcseq);
Branch: 1 branch
BranchTrueFalseTotal
unless lc $feature_ref eq lc $srcseq 270 255 525
564 }
565  
566 605 ▶ if (defined $class){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $class) 0 605 605
567 0 ▶ next unless defined $feature_class && $feature_class eq $class ;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $feature_class and $feature_class eq $class 0 0 0
Condition0%0/3
defined $feature_class and $feature_class eq $class
!ll&&!rl&&r
000
MC/DC0%0/2
defined $feature_class and $feature_class eq $class
defined $feature_class $feature_class eq $class
Truth table0%0/3
A and B
A= defined $feature_classB= $feature_class eq $class
ABresult
0X0
100
111
568 }
569  
570 # the requested range should OVERLAP the retrieved features
571 605 ▶ if (defined $start or defined $stop) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start or defined $stop) 255 350 605
Condition66%2/3
defined $start or defined $stop
l!l&&r!l&&!r
2550350
MC/DC50%1/2
defined $start or defined $stop
defined $start defined $stop
Truth table66%2/3
A or B
A= defined $startB= defined $stop
ABresult
1X1
011
000
572 255 ▶ $start = 1 unless defined $start;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start 0 255 255
573 255 ▶ $stop = MAX_SEGMENT unless defined $stop;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stop 0 255 255
574 255 ▶ next unless $feature_stop >= $start && $feature_start <= $stop;
Branch: 1 branch
BranchTrueFalseTotal
unless $feature_stop >= $start and $feature_start <= $stop 0 255 255
Condition33%1/3
$feature_stop >= $start and $feature_start <= $stop
!ll&&!rl&&r
00255
MC/DC0%0/2
$feature_stop >= $start and $feature_start <= $stop
$feature_stop >= $start $feature_start <= $stop
Truth table33%1/3
A and B
A= $feature_stop >= $startB= $feature_start <= $stop
ABresult
0X0
100
111
575 }
576  
577 605 ▶ if (defined $typelist && @$typelist){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $typelist and @$typelist) 0 605 605
Condition33%1/3
defined $typelist and @$typelist
!ll&&!rl&&r
60500
MC/DC0%0/2
defined $typelist and @$typelist
defined $typelist @$typelist
Truth table33%1/3
A and B
A= defined $typelistB= @$typelist
ABresult
0X0
100
111
578 0 ▶ next unless $self->_matching_typelist($feature_method,$feature_source,$typelist);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_matching_typelist($feature_method, $feature_source, $typelist) 0 0 0
579 }
580  
581 605 my $type = Bio::DB::GFF::Typename->new($feature_method,$feature_source);
582 605 $result{$type}++;
583 605 $obj{$type} = $type;
584  
585 } #end features loop
586  
587 25 ▶ return $want_count ? %result : values %obj;
Branch: 1 branch
BranchTrueFalseTotal
$want_count ? : 15 10 25
588 }
589  
590 0 ▶sub classes {
Subroutine classes: not called CC=2 SCAR=17.9
Pod documented
591 0 my $self = shift;
592 0 my %classes;
593 0 for my $feature (@{$self->{data}}) {
594 0 $classes{$feature->{gclass}}++;
595 }
596 0 my @classes = sort keys %classes;
597 0 return @classes;
598 }
599  
600 # Internal method that performs a search on the features array,
601 # sequentialy retrieves the features, and performs a check on each feature
602 # according to the search options.
603 100 ▶sub _get_features_by_search_options{
Subroutine _get_features_by_search_options: called CC=24 SCAR=34.3
604 100 my $count = 0;
605 100 my ($self, $search,$options) = @_;
606 my ($rangetype,$refseq,$class,$start,$stop,$types,$sparse,$order_by_group,$attributes) =
607 100 (@{$search}{qw(rangetype refseq refclass start stop types)},
608 100 @{$options}{qw(sparse sort_by_group ATTRIBUTES)}) ;
609  
610 100 my @found_features;
611 100 my $data = $self->{data};
612  
613 100 my $feature_id = -1 ;
614 100 my $feature_group_id = undef;
615  
616 100 for my $feature (@{$data}) {
617  
618 3270 $feature_id++;
619  
620 3270 my $feature_start = $feature->{start};
621 3270 my $feature_stop = $feature->{stop};
622 3270 my $feature_ref = $feature->{ref};
623  
624 3270 ▶ if (defined $refseq){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $refseq) 2905 365 3270
625 2905 ▶ next unless lc($feature_ref) eq lc($refseq);
Branch: 1 branch
BranchTrueFalseTotal
unless lc $feature_ref eq lc $refseq 1940 965 2905
626 }
627  
628 1330 ▶ if (defined $start or defined $stop) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start or defined $stop) 455 875 1330
Condition66%2/3
defined $start or defined $stop
l!l&&r!l&&!r
4550875
MC/DC50%1/2
defined $start or defined $stop
defined $start defined $stop
Truth table66%2/3
A or B
A= defined $startB= defined $stop
ABresult
1X1
011
000
629 455 ▶ $start = 0 unless defined($start);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start 0 455 455
630 455 ▶ $stop = MAX_SEGMENT unless defined($stop);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stop 0 455 455
631  
632 455 ▶ if ($rangetype eq 'overlaps') {
Branch: 3 branches
BranchTrueFalseTotal
if ($rangetype eq 'overlaps') { } 385 70 455
elsif ($rangetype eq 'contains') { } 70 0 70
elsif ($rangetype eq 'contained_in') { } 0 0 0
633 385 ▶ next unless $feature_stop >= $start && $feature_start <= $stop;
Branch: 1 branch
BranchTrueFalseTotal
unless $feature_stop >= $start and $feature_start <= $stop 100 285 385
Condition100%3/3
$feature_stop >= $start and $feature_start <= $stop
!ll&&!rl&&r
3070285
MC/DC100%2/2
$feature_stop >= $start and $feature_start <= $stop
$feature_stop >= $start $feature_start <= $stop
Truth table100%3/3
A and B
A= $feature_stop >= $startB= $feature_start <= $stop
ABresult
0X0
100
111
634 } elsif ($rangetype eq 'contains') {
635 70 ▶ next unless $feature_start >= $start && $feature_stop <= $stop;
Branch: 1 branch
BranchTrueFalseTotal
unless $feature_start >= $start and $feature_stop <= $stop 20 50 70
Condition66%2/3
$feature_start >= $start and $feature_stop <= $stop
!ll&&!rl&&r
20050
MC/DC50%1/2
$feature_start >= $start and $feature_stop <= $stop
$feature_start >= $start $feature_stop <= $stop
Truth table66%2/3
A and B
A= $feature_start >= $startB= $feature_stop <= $stop
ABresult
0X0
100
111
636 } elsif ($rangetype eq 'contained_in') {
637 0 ▶ next unless $feature_start <= $start && $feature_stop >= $stop;
Branch: 1 branch
BranchTrueFalseTotal
unless $feature_start <= $start and $feature_stop >= $stop 0 0 0
Condition0%0/3
$feature_start <= $start and $feature_stop >= $stop
!ll&&!rl&&r
000
MC/DC0%0/2
$feature_start <= $start and $feature_stop >= $stop
$feature_start <= $start $feature_stop >= $stop
Truth table0%0/3
A and B
A= $feature_start <= $startB= $feature_stop >= $stop
ABresult
0X0
100
111
638 } else {
639 0 ▶ next unless $feature_start == $start && $feature_stop == $stop;
Branch: 1 branch
BranchTrueFalseTotal
unless $feature_start == $start and $feature_stop == $stop 0 0 0
Condition0%0/3
$feature_start == $start and $feature_stop == $stop
!ll&&!rl&&r
000
MC/DC0%0/2
$feature_start == $start and $feature_stop == $stop
$feature_start == $start $feature_stop == $stop
Truth table0%0/3
A and B
A= $feature_start == $startB= $feature_stop == $stop
ABresult
0X0
100
111
640 }
641  
642 }
643  
644 1210 my $feature_source = $feature->{source};
645 1210 my $feature_method = $feature->{method};
646  
647 1210 ▶ if (defined $types && @$types){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $types and @$types) 375 835 1210
Condition66%2/3
defined $types and @$types
!ll&&!rl&&r
0835375
MC/DC50%1/2
defined $types and @$types
defined $types @$types
Truth table66%2/3
A and B
A= defined $typesB= @$types
ABresult
0X0
100
111
648 375 ▶ next unless $self->_matching_typelist($feature_method,$feature_source,$types);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_matching_typelist($feature_method, $feature_source, $types) 240 135 375
649 }
650  
651 970 my $feature_attributes = $feature->{attributes};
652 970 ▶ if (defined $attributes){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attributes) 255 715 970
653 255 ▶ next unless $self->_matching_attributes($feature_attributes,$attributes);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_matching_attributes($feature_attributes, $attributes) 230 25 255
654 }
655  
656 # if we get here, then we have a feature that meets the criteria.
657 # Then we just push onto an array
658 # of found features and continue.
659  
660 740 my $found_feature = $feature ;
661 740 $found_feature->{feature_id} = $feature_id;
662 740 $found_feature->{group_id} = $feature_group_id;
663 740 push @found_features,$found_feature;
664 }
665  
666 100 return \@found_features;
667 }
668  
669  
670 829 ▶sub _hash_to_array {
Subroutine _hash_to_array: called CC=2 SCAR=6.9
671 829 my ($self,$feature_hash) = @_;
672 829 my @array = @{$feature_hash}{@hash2array_map};
673 829 ▶ return wantarray ? @array : \@array;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 559 270 829
674 }
675  
676 # this subroutine is needed for convertion of the feature from hash to array in order to
677 # pass it to the callback subroutine
678 15 ▶sub _convert_feature_hash_to_array{
Subroutine _convert_feature_hash_to_array: called CC=1 SCAR=0.0
679 15 my ($self, $feature_hash_array) = @_;
680 15 my @features_array_array = map {scalar $self->_hash_to_array($_)} @$feature_hash_array;
681 15 return \@features_array_array;
682 }
683  
684 375 ▶sub _matching_typelist{
Subroutine _matching_typelist: called CC=5 SCAR=16.2
685 375 my ($self, $feature_method,$feature_source,$typelist) = @_;
686 375 foreach (@$typelist) {
687 1090 my ($search_method,$search_source) = @$_;
688 1090 ▶ next if lc($search_method) ne lc($feature_method);
Branch: 1 branch
BranchTrueFalseTotal
if lc $search_method ne lc $feature_method 955 135 1090
689 135 ▶ next if defined($search_source) && lc($search_source) ne lc($feature_source);
Branch: 1 branch
BranchTrueFalseTotal
if defined $search_source and lc $search_source ne lc $feature_source 0 135 135
Condition66%2/3
defined $search_source and lc $search_source ne lc $feature_source
!ll&&!rl&&r
115200
MC/DC0%0/2
defined $search_source and lc $search_source ne lc $feature_source
defined $search_source lc $search_source ne lc $feature_source
Truth table66%2/3
A and B
A= defined $search_sourceB= lc $search_source ne lc $feature_source
ABresult
0X0
100
111
690 135 return 1;
691 }
692 240 return 0;
693 }
694  
695 6425 ▶sub _matching_attributes {
Subroutine _matching_attributes: called CC=3 SCAR=11.0
696 6425 my ($self, $feature_attributes,$attributes) = @_ ;
697 6425 foreach (keys %$attributes) {
698 6440 ▶ return 0 if !_match_all_attr_in_feature($_,$attributes->{$_},$feature_attributes)
Branch: 1 branch
BranchTrueFalseTotal
unless _match_all_attr_in_feature($_, $attributes->{$_}, $feature_attributes) 6395 45 6440
699 }
700 30 return 1;
701 }
702  
703 6440 ▶sub _match_all_attr_in_feature{
Subroutine _match_all_attr_in_feature: called CC=4 SCAR=13.9
704 6440 my ($attr_name,$attr_value,$feature_attributes) = @_;
705 6440 for my $attr (@$feature_attributes) {
706 2405 my ($feature_attr_name,$feature_attr_value) = @$attr ;
707 2405 ▶ next if ($attr_name ne $feature_attr_name || $attr_value ne $feature_attr_value);
Branch: 1 branch
BranchTrueFalseTotal
if $attr_name ne $feature_attr_name or $attr_value ne $feature_attr_value 2360 45 2405
Condition100%3/3
$attr_name ne $feature_attr_name or $attr_value ne $feature_attr_value
l!l&&r!l&&!r
217518545
MC/DC100%2/2
$attr_name ne $feature_attr_name or $attr_value ne $feature_attr_value
$attr_name ne $feature_attr_name $attr_value ne $feature_attr_value
Truth table100%3/3
A or B
A= $attr_name ne $feature_attr_nameB= $attr_value ne $feature_attr_value
ABresult
1X1
011
000
708 45 return 1;
709 }
710 6395 return 0;
711 }
712  
713  
714 5 ▶sub do_initialize { 1; }
Subroutine do_initialize: called CC=1 SCAR=0.0
Pod documented
715 0 ▶sub get_feature_by_group_id{ 1; }
Subroutine get_feature_by_group_id: not called CC=1 SCAR=6.9
Pod undocumented
716  
717 4 1;
718  
« GFF/Adaptor/dbi/mysql.pm ↑ Summary GFF/Adaptor/dbi/iterator.pm »