IO/dip_tab.pm

filter: Statementstmt 50.0% 51 / 102 Branchbran 16.6% 4 / 24 Conditioncond 9.5% 2 / 21 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 85.7% 12 / 14 Podpod 100% 2 / 2 totaltotal 40.5% 71 / 175 CC 26 SCAR 39.0
CC
26
Cov
39%
write_network
90.0
next_network
77.6
_add_db_links
20.0
CRAP 49.2
↑ Summary ProteinNet.pm »
1 #
2 # BioPerl module for Bio::Network::IO::dip_tab
3 #
4 # You may distribute this module under the same terms as perl itself
5 # POD documentation - main docs before the code
6  
7 =head1 NAME
8  
9 Bio::Network::IO::dip_tab - class for parsing interaction data in DIP
10 tab-delimited format
11  
12 =head1 SYNOPSIS
13  
14 Do not use this module directly, use Bio::Network::IO. For example:
15  
16 my $io = Bio::Network::IO->new(-format => 'dip_tab',
17 -file => 'data.dip');
18  
19 my $network = $io->next_network;
20  
21 =head1 DESCRIPTION
22  
23 The Database of Interacting Proteins (DIP) is a protein interaction
24 database (see L<http://dip.doe-mbi.ucla.edu/dip/Main.cgi>).
25 The species-specific subsets of the DIP database are provided in
26 a simple, tab-delimited format. The tab-separated columns are:
27  
28 edge DIP id
29 node A DIP id
30 node A optional id
31 node A SwissProt id
32 node A PIR id
33 node A GenBank GI id
34 node B DIP id
35 node B optional id
36 node B SwissProt id
37 node B PIR id
38 node B GenBank GI id
39  
40 The source or namespace of the optional id in columns 3 and 8 varies
41 from species to species, and optional ids are frequently absent.
42  
43 =head2 Versions
44  
45 The first version of this format prepended the identifier with a
46 database name, e.g.:
47  
48 DIP:4305E DIP:3048N PIR:B64526 SWP:P23487 GI:2313123 ...
49  
50 The version as of 1/2006 has no database identifiers:
51  
52 DIP:4305E DIP:3048N B64526 P23487 2313123 ...
53  
54 This module parses both versions.
55  
56 =head1 METHODS
57  
58 The naming system is analagous to the SeqIO system, although usually
59 next_network() will be called only once per file.
60  
61 =head1 FEEDBACK
62  
63 =head2 Mailing Lists
64  
65 User feedback is an integral part of the evolution of this and other
66 Bioperl modules. Send your comments and suggestions preferably to one
67 of the Bioperl mailing lists. Your participation is much appreciated.
68  
69 bioperl-l@bioperl.org - General discussion
70 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
71  
72 =head2 Support
73  
74 Please direct usage questions or support issues to the mailing list:
75  
76 I<bioperl-l@bioperl.org>
77  
78 rather than to the module maintainer directly. Many experienced and
79 reponsive experts will be able look at the problem and quickly
80 address it. Please include a thorough description of the problem
81 with code and data examples if at all possible.
82  
83 =head2 Reporting Bugs
84  
85 Report bugs to the Bioperl bug tracking system to help us keep track
86 the bugs and their resolution. Bug reports can be submitted via the
87 web:
88  
89 http://bugzilla.open-bio.org/
90  
91 =head1 AUTHORS
92  
93 Brian Osborne bosborne at alum.mit.edu
94 Richard Adams richard.adams@ed.ac.uk
95  
96 =cut
97  
98 package Bio::Network::IO::dip_tab;
99 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 1 ▶use vars qw(@ISA $FAC);
Subroutine BEGIN: called CC=1 SCAR=0.0
101 1 ▶use Bio::Network::IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 1 ▶use Bio::Network::ProteinNet;
Subroutine BEGIN: called CC=1 SCAR=0.0
103 1 ▶use Bio::Network::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
104 1 ▶use Bio::Seq::SeqFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
105 1 ▶use Bio::Annotation::DBLink;
Subroutine BEGIN: called CC=1 SCAR=0.0
106 1 ▶use Bio::Annotation::Collection;
Subroutine BEGIN: called CC=1 SCAR=0.0
107 1 ▶use Bio::Network::Interaction;
Subroutine BEGIN: called CC=1 SCAR=0.0
108  
109 1 @ISA = qw(Bio::Network::IO Bio::Network::ProteinNet);
110  
111 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
112 1 $FAC = Bio::Seq::SeqFactory->new(-type => 'Bio::Seq::RichSeq');
113 }
114  
115 =head2 next_network
116  
117 Name : next_network
118 Purpose : parses a DIP file and returns a Bio::Network::ProteinNet
119 object
120 Usage : my $g = $graph_io->next_network();
121 Arguments : none
122 Returns : a Bio::Network::ProteinNet object
123  
124 =cut
125  
126 1 ▶sub next_network {
Subroutine next_network: called CC=13 SCAR=43.5
Pod documented
127 1 my $self = shift;
128 1 my $graph = Bio::Network::ProteinNet->new(refvertexed => 1);
129  
130 1 ▶ while (my $l = $self->_readline() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $l = $self->_readline) 1 0 1
131 1 chomp $l;
132 ## get line, only gi and node_id always defined
133 1 my ($interx_id, $node_id1, $o1, $s1, $p1, $g1,
134 $node_id2, $o2, $s2, $p2, $g2, $score) = split '\t', $l;
135 1 ▶ last unless ($interx_id && $g2);
Branch: 1 branch
BranchTrueFalseTotal
unless $interx_id and $g2 0 1 1
Condition33%1/3
$interx_id and $g2
!ll&&!rl&&r
001
MC/DC0%0/2
$interx_id and $g2
$interx_id $g2
Truth table33%1/3
A and B
A= $interx_idB= $g2
ABresult
0X0
100
111
136  
137 ## concatenate correct database name with id
138 1 ($g1,$g2) = $self->_fix_id("GI",$g1,$g2);
139 1 ($s1,$s2) = $self->_fix_id("SWP",$s1,$s2);
140 1 ($p1,$p2) = $self->_fix_id("PIR",$p1,$p2);
141 # ($node_id1,$node_id2) = $self->_fix_id("DIP",$node_id1,$node_id2);
142  
143 ## skip if score is below threshold
144 1 ▶ if ($self->threshold && defined($score)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->threshold and defined $score) 0 1 1
Condition33%1/3
$self->threshold and defined $score
!ll&&!rl&&r
100
MC/DC0%0/2
$self->threshold and defined $score
$self->threshold defined $score
Truth table33%1/3
A and B
A= $self->thresholdB= defined $score
ABresult
0X0
100
111
145 0 ▶ next unless $score >= $self->threshold;
Branch: 1 branch
BranchTrueFalseTotal
unless $score >= $self->threshold 0 0 0
146 }
147  
148 ## build node object if it's a new node, use DIP id
149 1 my ($node1, $node2);
150  
151 1 ▶ unless ( $node1 = $graph->get_nodes_by_id($node_id1) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($node1 = $graph->get_nodes_by_id($node_id1)) 0 0 0
152 0 ▶ my $acc = $s1 || $p1 || $g1;
Condition0%0/6
$s1 || $p1 || $g1
l!l&&r!l&&!r
000
$s1 or $p1
l!l&&r!l&&!r
000
MC/DC0%0/3
$s1 || $p1 || $g1
$s1 $p1 $g1
Truth table0%0/4
A or B || C
A= $s1B= $p1C= $g1
ABCresult
1XX1
01X1
0011
0000
153 0 my $ac = $self->_add_db_links($acc, $s1, $p1, $node_id1, $g1);
154 0 my $prot1 = $FAC->create(-accession_number => $acc,
155 -primary_id => $g1,
156 -display_id => $acc,
157 -annotation => $ac,
158 );
159 0 $node1 = Bio::Network::Node->new(-protein => [($prot1)]);
160 0 $graph->add_node($node1);
161 0 my @ids = ($g1, $p1, $s1, $node_id1);
162 0 $graph->add_id_to_node(\@ids,$node1);
163 }
164  
165 0 ▶ unless ( $node2 = $graph->get_nodes_by_id($node_id2) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($node2 = $graph->get_nodes_by_id($node_id2)) 0 0 0
166 0 ▶ my $acc = $s2 || $p2 || $g2;
Condition0%0/6
$s2 || $p2 || $g2
l!l&&r!l&&!r
000
$s2 or $p2
l!l&&r!l&&!r
000
MC/DC0%0/3
$s2 || $p2 || $g2
$s2 $p2 $g2
Truth table0%0/4
A or B || C
A= $s2B= $p2C= $g2
ABCresult
1XX1
01X1
0011
0000
167 0 my $ac = $self->_add_db_links($acc, $s2, $p2, $node_id2, $g2);
168 0 my $prot2 = $FAC->create(-accession_number => $acc,
169 -primary_id => $g2,
170 -display_id => $acc,
171 -annotation => $ac,
172 );
173 0 $node2 = Bio::Network::Node->new(-protein => [($prot2)]);
174 0 $graph->add_node($node2);
175 0 my @ids = ($g2, $p2, $s2, $node_id2);
176 0 $graph->add_id_to_node(\@ids,$node2);
177 }
178  
179 ## create new Interaction object based on DIP id, weight
180 0 my $interx = Bio::Network::Interaction->new(-weight => $score,
181 -id => $interx_id);
182  
183 0 $graph->add_interaction(-interaction => $interx,
184 -nodes => [($node1,$node2)]);
185 0 $graph->add_id_to_interaction($interx_id,$interx);
186 }
187 0 $graph;
188 }
189  
190 =head2 write_network
191  
192 Name : write_network
193 Purpose : write graph out in dip format
194 Arguments: a Bio::Network::ProteinNet object
195 Returns : void
196 Usage : $out->write_network($gr);
197  
198 =cut
199  
200 0 ▶sub write_network {
Subroutine write_network: not called CC=9 SCAR=45.0
Pod documented
201 0 my ($self, $gr) = @_;
202 0 ▶ if ( !$gr || !$gr->isa('Bio::Network::ProteinNet') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gr and $gr->isa("Bio::Network::ProteinNet")) 0 0 0
Condition0%0/3
$gr and $gr->isa("Bio::Network::ProteinNet")
!ll&&!rl&&r
000
MC/DC0%0/2
$gr and $gr->isa("Bio::Network::ProteinNet")
$gr $gr->isa("Bio::Network::ProteinNet")
Truth table0%0/3
A and B
A= $grB= $gr->isa("Bio::Network::ProteinNet")
ABresult
0X0
100
111
203 0 $self->throw("I need a Bio::Network::ProteinNet, not a [".
204 ref($gr) . "]");
205 }
206  
207 # Need to have all ids as annotations with database ids as well,
208 # the idea is to be able to round trip, to write it in same way as
209 # for each edge
210  
211 0 for my $ref ($gr->edges) {
212 0 my ($interx,$str,$weight);
213  
214 0 my $atts = $gr->get_edge_attributes(@$ref);
215 # there should be only one Interaction if the network is from DIP
216 0 for my $interx (keys %$atts) {
217 # add DIP edge id
218 0 $str = $interx . "\t";
219 0 $weight = $atts->{$interx}->weight();
220 }
221  
222 # add node ids to string
223 0 for my $node (@$ref){
224 # print out nodes in dip_tab order
225 0 my %ids = $gr->get_ids_by_node($node); # need to modify this in graph()
226 # add second tab since we won't write out an optional id
227 0 $str .= "DIP:" . $ids{DIP} . "\t\t";
228 0 for my $name ( qw(UniProt PIR GenBank) ) {
229 0 ▶ $str .= $ids{$name} if (defined $ids{$name});
Branch: 1 branch
BranchTrueFalseTotal
if defined $ids{$name} 0 0 0
230 0 $str .= "\t";
231 }
232 }
233  
234 # add weight if defined
235 0 ▶ $str .= $weight . "\t" if $weight;
Branch: 1 branch
BranchTrueFalseTotal
if $weight 0 0 0
236 0 $str =~ s/\t$/\n/;
237 0 $self->_print($str);
238 }
239 0 $self->flush();
240 }
241  
242 =head2 _add_db_links
243  
244 Name : _add_db_links
245 Purpose : create DBLink annotations, add to an Annotation
246 Collection object
247 Arguments: an array of ids
248 Returns : an Annotation::Collection object
249 Usage :
250  
251 =cut
252  
253 0 ▶sub _add_db_links {
Subroutine _add_db_links: not called CC=4 SCAR=30.0
254 0 my $self = shift;
255 0 my @ids = @_;
256 0 my %seen;
257 0 my $ac = Bio::Annotation::Collection->new();
258 0 for my $id (@ids) {
259 0 ▶ next unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
260 0 ▶ next if $seen{$id};
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$id} 0 0 0
261 0 $id =~ /^([^:]+):([^:]+)/;
262 0 my $an = Bio::Annotation::DBLink->new(
263 -database => $1,
264 -primary_id => $2 );
265 0 $ac->add_Annotation('dblink', $an);
266 0 $seen{$id}++;
267 }
268 0 return $ac;
269 }
270  
271 =head2 _fix_id
272  
273 Name : _fix_id
274 Purpose :
275 Arguments:
276 Returns :
277 Usage :
278  
279 =cut
280  
281 3 ▶sub _fix_id {
Subroutine _fix_id: called CC=3 SCAR=11.0
282 3 my $self = shift;
283 3 my $str = shift;
284 3 my @ids = @_;
285 3 my $name = $self->_get_standard_name($str);
286 3 for my $id (@ids) {
287 6 ▶ next unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 6 6
288 6 $id =~ /([^:]+)$/;
289 6 $id = $name . ":" . $1;
290 }
291 3 @ids;
292 }
293  
294 1 1;
295  
296 __END__
↑ Summary ProteinNet.pm »