Tools/EUtilities/Link/LinkSet.pm

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