Tools/EUtilities/Link/LinkSet.pm

filter: Statementstmt 71.9% 128 / 178 Branchbran 59.6% 37 / 62 Conditioncond 50.0% 9 / 18 MC/DCmcdc 45.4% 5 / 11 Subroutinesub 65.7% 23 / 35 Podpod 100% 22 / 22 totaltotal 68.7% 224 / 326 CC 46 SCAR 24.8
CC
46
Cov
67%
to_string
72.0
rewind
30.0
get_score_by_id
12.0
CRAP 12.0
« Tools/EUtilities/EUtilParameters.pm ↑ Summary Tools/EUtilities/Link.pm »
1 package Bio::Tools::EUtilities::Link::LinkSet;
2 9 $Bio::Tools::EUtilities::Link::LinkSet::VERSION = '1.77';
3 9 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use base qw(Bio::Root::Root Bio::Tools::EUtilities::HistoryI);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Bio::Tools::EUtilities::Link::UrlLink;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Bio::Tools::EUtilities::Info::LinkInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: Class for EUtils LinkSets.
11 # AUTHOR: Chris Fields <cjfields@bioperl.org>
12 # OWNER: 2006-2013 Chris Fields
13 # LICENSE: Perl_5
14  
15  
16 50 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
17 50 my ($class,@args) = @_;
18 50 my $self = $class->SUPER::new(@args);
19 50 my ($type) = $self->_rearrange([qw(DATATYPE)],@args);
20 50 ▶ $type ||= 'linkset';
Condition50%1/2
$type ||= "linkset"
l!l
500
MC/DC0%0/1
$type ||= "linkset"
$type
Truth table50%1/2
A
A= $type
Aresult
11
00
21 50 $self->eutil('elink');
22 50 $self->datatype($type);
23 50 return $self;
24 }
25  
26  
27 102 ▶sub get_ids {
Subroutine get_ids: called CC=2 SCAR=6.9
Pod documented
28 102 my $self = shift;
29 102 ▶ unless ($self->{'_sorted_id'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_sorted_id"}) 50 52 102
30 50 @{$self->{'_sorted_id'}} =
31 sort {
32 $self->{'_id'}->{$a}->[0] <=>
33 33 $self->{'_id'}->{$b}->[0]
34 50 } keys %{$self->{'_id'}};
35 }
36 102 return @{$self->{'_sorted_id'}};
37 }
38  
39  
40 0 ▶sub get_database {
Subroutine get_database: not called CC=1 SCAR=6.9
Pod documented
41 0 return ($_[0]->get_databases)[0];
42 }
43  
44  
45 0 ▶sub get_db {
Subroutine get_db: not called CC=1 SCAR=6.9
Pod documented
46 0 return shift->get_database;
47 }
48  
49  
50 0 ▶sub get_dbto {
Subroutine get_dbto: not called CC=1 SCAR=6.9
Pod documented
51 0 return shift->get_database;
52 }
53  
54  
55 167 ▶sub get_databases {
Subroutine get_databases: called CC=3 SCAR=11.0
Pod documented
56 167 my $self = shift;
57 167 my %tmp;
58 328 my @dbs = sort map {$_->get_database}
59 167 grep {!$tmp{$_->get_database}++} ($self->get_LinkInfo);
60 167 ▶ unshift @dbs, $self->{'_dbto'} if $self->{'_dbto'} && !$tmp{$self->{'_dbto'}}++;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_dbto"} and not $tmp{$self->{"_dbto"}}++ 59 108 167
Condition66%2/3
$self->{"_dbto"} and not $tmp{$self->{"_dbto"}}++
!ll&&!rl&&r
108059
MC/DC50%1/2
$self->{"_dbto"} and not $tmp{$self->{"_dbto"}}++
$self->{"_dbto"} not $tmp{$self->{"_dbto"}}++
Truth table66%2/3
A and not(B)
A= $self->{"_dbto"}B= not $tmp{$self->{"_dbto"}}++
ABresult
0X0
100
111
61 167 return @dbs;
62 }
63  
64  
65 0 ▶sub get_dbs {
Subroutine get_dbs: not called CC=1 SCAR=6.9
Pod documented
66 0 return shift->get_databases;
67 }
68  
69  
70 26 ▶sub get_dbfrom { return shift->{'_dbfrom'} }
Subroutine get_dbfrom: called CC=1 SCAR=0.0
Pod documented
71  
72  
73 26 ▶sub get_link_names {
Subroutine get_link_names: called CC=2 SCAR=6.9
Pod documented
74 26 my ($self) = shift;
75 26 my %tmps;
76 my @lns;
77 26 ▶ if ($self->{'_linkname'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_linkname"}) 10 16 26
78 10 push @lns, $self->{'_linkname'};
79 10 $tmps{$self->{'_linkname'}}++;
80 }
81 26 push @lns, map {$_->get_link_name} $self->get_LinkInfo;
82 26 return @lns;
83 }
84  
85  
86 0 ▶sub get_link_name {
Subroutine get_link_name: not called CC=1 SCAR=6.9
Pod documented
87 0 return ($_[0]->get_link_names)[0];
88 }
89  
90  
91 26 ▶sub get_submitted_ids {
Subroutine get_submitted_ids: called CC=4 SCAR=14.0
Pod documented
92 26 my $self = shift;
93 26 my $datatype = $self->datatype;
94 26 ▶ if ($datatype eq 'idcheck' || $datatype eq 'urllink') {
Branch: 2 branches
BranchTrueFalseTotal
if ($datatype eq 'idcheck' or $datatype eq 'urllink') { } 16 10 26
elsif ($self->{'_submitted_ids'}) { } 10 0 10
Condition100%3/3
$datatype eq "idcheck" or $datatype eq "urllink"
l!l&&r!l&&!r
12410
MC/DC100%2/2
$datatype eq "idcheck" or $datatype eq "urllink"
$datatype eq "idcheck" $datatype eq "urllink"
Truth table100%3/3
A or B
A= $datatype eq "idcheck"B= $datatype eq "urllink"
ABresult
1X1
011
000
95 16 return $self->get_ids;
96 } elsif ($self->{'_submitted_ids'}) {
97 10 return @{$self->{'_submitted_ids'}};
98 } else {
99 0 return ();
100 }
101 }
102  
103  
104 28 ▶sub has_scores {
Subroutine has_scores: called CC=2 SCAR=6.9
Pod documented
105 28 my $self = shift;
106 28 ▶ return exists $self->{'_has_scores'} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'_has_scores'} ? : 4 24 28
107 }
108  
109  
110 2 ▶sub get_scores {
Subroutine get_scores: called CC=2 SCAR=7.0
Pod documented
111 2 my $self = shift;
112 # do we want to cache this or generate only when needed? Likely won't be
113 # called more than once...
114 2 ▶ return unless $self->has_scores;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_scores 0 2 2
115 2 my %scores = map {$_ => $self->{'_id'}->{$_}->[1]} keys %{$self->{'_id'}};
116 2 return %scores;
117 }
118  
119  
120 0 ▶sub get_score_by_id {
Subroutine get_score_by_id: not called CC=3 SCAR=24.8
Pod documented
121 0 my ($self, $id) = @_;
122 0 ▶ ($id && exists $self->{'_id'}->{$id}) ? return $self->{'_id'}->{$id}->[1] :
Branch: 1 branch
BranchTrueFalseTotal
$id && exists $self->{'_id'}{$id} ? : 0 0 0
Condition0%0/3
$id and exists $self->{"_id"}{$id}
!ll&&!rl&&r
000
MC/DC0%0/2
$id and exists $self->{"_id"}{$id}
$id exists $self->{"_id"}{$id}
Truth table0%0/3
A and B
A= $idB= exists $self->{"_id"}{$id}
ABresult
0X0
100
111
123 return;
124 }
125  
126  
127 26 ▶sub has_linkout {
Subroutine has_linkout: called CC=4 SCAR=13.9
Pod documented
128 26 my $self = shift;
129 26 ▶ if (exists $self->{'_haslinkout'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'_haslinkout'}) { } 4 22 26
130 4 ▶ return $self->{'_haslinkout'} eq 'Y' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_haslinkout'} eq 'Y' ? : 2 2 4
131 } else {
132 22 ▶ return (grep {$_ eq 'LinkOut'} $self->get_databases) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ eq 'LinkOut';} $self->get_databases) ? : 2 20 22
133 }
134 }
135  
136  
137 26 ▶sub has_neighbor {
Subroutine has_neighbor: called CC=3 SCAR=11.0
Pod documented
138 26 my $self = shift;
139 26 ▶ if (exists $self->{'_hasneighbor'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'_hasneighbor'}) { } 4 22 26
140 4 ▶ return $self->{'_hasneighbor'} eq 'Y' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_hasneighbor'} eq 'Y' ? : 4 0 4
141 } else {
142 22 return 0;
143 }
144 }
145  
146  
147 0 ▶sub next_UrlLink {
Subroutine next_UrlLink: not called CC=2 SCAR=17.9
Pod documented
148 0 my $self = shift;
149 0 ▶ unless ($self->{"_urllinks_it"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_urllinks_it"}) 0 0 0
150 0 my @ul = $self->get_UrlLinks;
151 0 ▶ $self->{"_urllinks_it"} = sub {return shift @ul}
Subroutine __ANON__: not called CC=1 SCAR=6.9
152 0 }
153 0 $self->{'_urllinks_it'}->();
154 }
155  
156  
157 26 ▶sub get_UrlLinks {
Subroutine get_UrlLinks: called CC=2 SCAR=6.9
Pod documented
158 26 my $self = shift;
159 26 ▶ return ref $self->{'_urllinks'} ? @{ $self->{'_urllinks'} } : return;
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_urllinks'} ? : 2 24 26
160 }
161  
162  
163 0 ▶sub next_LinkInfo {
Subroutine next_LinkInfo: not called CC=2 SCAR=17.9
Pod documented
164 0 my $self = shift;
165 0 ▶ unless ($self->{"_linkinfo_it"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_linkinfo_it"}) 0 0 0
166 0 my @li = $self->get_LinkInfo;
167 0 ▶ $self->{"_linkinfo_it"} = sub {return shift @li}
Subroutine __ANON__: not called CC=1 SCAR=6.9
168 0 }
169 0 $self->{'_linkinfo_it'}->();
170 }
171  
172  
173 219 ▶sub get_LinkInfo {
Subroutine get_LinkInfo: called CC=2 SCAR=6.9
Pod documented
174 219 my $self = shift;
175 219 ▶ return ref $self->{'_linkinfo'} ? @{ $self->{'_linkinfo'} } : return ();
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_linkinfo'} ? : 42 177 219
176 }
177  
178  
179 {
180 9 my %VALID_DATA = ('linkinfo' => 'linkinfo',
181 'linkinfos' => 'linkinfo',
182 'urllinks' => 'urllinks');
183  
184 0 ▶ sub rewind {
Subroutine rewind: not called CC=5 SCAR=34.0
Pod documented
185 0 my ($self, $arg) = @_;
186 0 ▶ $arg ||= 'all';
Condition0%0/2
$arg ||= "all"
l!l
00
MC/DC0%0/1
$arg ||= "all"
$arg
Truth table0%0/2
A
A= $arg
Aresult
11
00
187 0 ▶ if (exists $VALID_DATA{$arg}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $VALID_DATA{$arg}) { } 0 0 0
elsif ($arg eq 'all') { } 0 0 0
188 0 delete $self->{'_'.$arg.'_it'};
189 } elsif ($arg eq 'all') {
190 0 delete $self->{'_'.$_.'_it'} for values %VALID_DATA;
191 }
192 }
193 }
194  
195 # private methods and handlers
196  
197 {
198 9 my %DATA_HANDLER = (
199 'IdList' => \&_add_submitted_ids,
200 'Id' => \&_add_retrieved_ids,
201 'LinkInfo' => \&_add_linkinfo,
202 'Link' => \&_add_retrieved_ids,
203 'ObjUrl' => \&_add_objurls,
204 );
205  
206 50 ▶sub _add_data {
Subroutine _add_data: called CC=5 SCAR=16.1
207 50 my ($self, $data) = @_;
208 50 for my $key (qw(IdList Link Id ObjUrl LinkInfo)) {
209 250 ▶ next if !exists $data->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $data->{$key} 192 58 250
210 58 my $handler = $DATA_HANDLER{$key};
211 58 $self->$handler($data);
212 58 delete $data->{$key};
213 }
214 # map the rest
215 50 ▶ if ($self->datatype eq 'idcheck' && exists $data->{content}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->datatype eq "idcheck" and exists $data->{"content"}) 16 34 50
Condition100%3/3
$self->datatype eq "idcheck" and exists $data->{"content"}
!ll&&!rl&&r
26816
MC/DC100%2/2
$self->datatype eq "idcheck" and exists $data->{"content"}
$self->datatype eq "idcheck" exists $data->{"content"}
Truth table100%3/3
A and B
A= $self->datatype eq "idcheck"B= exists $data->{"content"}
ABresult
0X0
100
111
216 16 %{$self->{'_id'} } = ($data->{content} => [1]);
217 delete $data->{content}
218 16 }
219 50 map {$self->{'_'.lc $_} = $data->{$_}} keys %$data;
220 }
221  
222 }
223  
224 9 ▶sub _add_submitted_ids {
Subroutine _add_submitted_ids: called CC=2 SCAR=7.0
225 18 my ($self, $data) = @_;
226 18 ▶ if (exists $data->{IdList}->{Id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{"IdList"}{"Id"}) 18 0 18
227 18 @{$self->{'_submitted_ids'}} = @{$data->{IdList}->{Id}} ;
228 }
229 }
230  
231 26 ▶sub _add_retrieved_ids {
Subroutine _add_retrieved_ids: called CC=5 SCAR=16.1
232 26 my ($self, $data) = @_;
233 # map all IDs to deal with possible scores
234 # ID => {'count' = POSITION, 'score' => SCORE}
235 26 ▶ if (exists $data->{Link}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $data->{'Link'}) { } 10 16 26
elsif (exists $data->{'Id'}) { } 16 0 16
236 10 my $ct = 0;
237 10 for my $link (@{$data->{Link}}) {
238 26 ▶ if (exists $link->{Score}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $link->{'Score'}) { } 12 14 26
239 12 $self->{'_has_scores'}++;
240 12 $self->{'_id'}->{$link->{Id}->[0]} = [ $ct++,$link->{Score}];
241 } else {
242 14 $self->{'_id'}->{$link->{Id}->[0]} = [ $ct++ ];
243 }
244 }
245 }
246 elsif (exists $data->{Id}) { # urls
247 16 %{$self->{'_id'} } = ($data->{Id}->[0] => [1]);
248 }
249 }
250  
251 6 ▶sub _add_objurls {
Subroutine _add_objurls: called CC=3 SCAR=11.0
252 6 my ($self, $data) = @_;
253 6 for my $urldata (@{$data->{ObjUrl}}) {
254 6 ▶ $urldata->{dbfrom} = $data->{DbFrom} if exists $data->{DbFrom};
Branch: 1 branch
BranchTrueFalseTotal
if exists $data->{"DbFrom"} 6 0 6
255 6 my $obj = Bio::Tools::EUtilities::Link::UrlLink->new(-eutil => 'elink',
256 -datatype => 'urldata',
257 -verbose => $self->verbose
258 );
259 6 $obj->_add_data($urldata);
260 6 push @{$self->{'_urllinks'}}, $obj;
261 }
262 }
263  
264 8 ▶sub _add_linkinfo {
Subroutine _add_linkinfo: called CC=3 SCAR=11.0
265 8 my ($self, $data) = @_;
266 8 for my $linkinfo (@{$data->{LinkInfo}}) {
267 116 ▶ $linkinfo->{dbfrom} = $data->{DbFrom} if exists $data->{DbFrom};
Branch: 1 branch
BranchTrueFalseTotal
if exists $data->{"DbFrom"} 116 0 116
268 116 my $obj = Bio::Tools::EUtilities::Info::LinkInfo->new(-eutil => 'elink',
269 -datatype => 'linkinfo',
270 -verbose => $self->verbose
271 );
272 116 $obj->_add_data($linkinfo);
273 116 push @{$self->{'_linkinfo'}}, $obj;
274 }
275 }
276  
277  
278 0 ▶sub to_string {
Subroutine to_string: not called CC=8 SCAR=42.8
Pod documented
279 0 my $self = shift;
280 0 ▶ my $level = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
281 0 my $pad = 20 - $level;
282 # order method name
283 0 my %tags = (1 => ['get_databases' => 'DB'],
284 2 => ['get_ids' => 'ID'],
285 3 => ['get_link_names' => 'Link Names'],
286 5 => ['get_submitted_ids' => 'Submitted IDs'],
287 6 => ['has_scores' => 'Scores?'],
288 7 => ['has_linkout' => 'LinkOut?'],
289 8 => ['has_neighbor' => 'DB Neighbors?'],
290 9 => ['get_webenv' => 'WebEnv'],
291 10 => ['get_query_key' => 'Key'],
292 );
293 0 my $string;
294 0 for my $tag (sort {$a <=> $b} keys %tags) {
295 0 my ($m, $nm) = (@{$tags{$tag}}[0..1]);
296 # using this awkward little construct to deal with both lists and scalars
297 0 my @content = grep {defined $_} $self->$m();
298 0 ▶ next unless @content;
Branch: 1 branch
BranchTrueFalseTotal
unless @content 0 0 0
299 0 $string .= $self->_text_wrap(
300 sprintf("%-*s%-*s:",$level, '',$pad, $nm,),
301 ' ' x ($pad).':',
302 join(', ',@content))."\n";
303 }
304 0 ▶ while (my $li = $self->next_LinkInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $li = $self->next_LinkInfo) 0 0 0
305 0 $string .= $li->to_string(4);
306 }
307 0 ▶ while (my $ui = $self->next_UrlLink) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ui = $self->next_UrlLink) 0 0 0
308 0 $string .= $ui->to_string(4);
309 }
310 0 ▶ if ($self->has_scores) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_scores) 0 0 0
311 0 $string .= "Scores:\n";
312 0 my %scores = $self->get_scores;
313 0 $string .= sprintf("%-*s%-*s%s\n",
314 $level + 4, '',
315 $pad - 4, 'ID', 'Score'
316 );
317 0 for my $id ($self->get_ids) {
318 $string .= sprintf("%-*s%-*s%s\n",
319 $level + 4, '',
320 0 $pad - 4, $id, $scores{$id}
321 );
322 }
323 }
324 0 $string .= "\n";
325 0 return $string;
326 }
327  
328 9 1;
329  
330 __END__
« Tools/EUtilities/EUtilParameters.pm ↑ Summary Tools/EUtilities/Link.pm »