1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 70,
11 -requires_modules => [qw(Class::AutoClass Clone)]);
13 use_ok('Bio::Graph::IO');
16 ################1st of all let's test the io.....
17 ############### test dip tab delimited format ###################
22 ok my $io = Bio::Graph::IO->new(
24 -file => test_input_file('tab1part.mif'),
27 ok $gr = $io->next_network();
29 ok my $node = $gr->nodes_by_id('A64696');
30 is $node->accession_number, 'A64696';
32 ##test write. to filehandle...
33 my $out_file = test_output_file();
34 ok my $out = Bio::Graph::IO->new(
36 -file =>">$out_file");
37 ok $out->write_network($gr);
39 ## get articulation_points.
40 my @nodes = $gr->articulation_points();
42 ##now remove 2 nodes: this removes 4 edges and 3087 should be a new artic point
43 is $gr->edge_count, 72;
44 $gr->remove_nodes($gr->nodes_by_id('3082N'), $gr->nodes_by_id('3083N'));
45 is $gr->edge_count, 68;
46 my $nodes = $gr->articulation_points();
47 ok grep {$_->object_id eq 'H64521'} @$nodes;
48 is scalar @$nodes, 13;
49 @nodes = @{$gr->articulation_points()};
51 # these were failing, I don't understand the module enough to know if
52 # this is a bug. Richard needs to look at it
54 local $TODO = 'Possible bug!';
55 ok grep {$_->object_id eq 'B64701'} @nodes;
59 ok grep {$_->object_id eq 'B64528'} @nodes;
63 ok $node = $gr->nodes_by_id('A64696');
64 is $node->accession_number, 'A64696';
67 ## can we round trip, is out format same as original format?
68 ok my $io2 = Bio::Graph::IO->new(
71 ok my $g2 = $io2->next_network();
72 ok $node = $g2->nodes_by_id('A64696');
73 is $node->accession_number, 'A64696';
75 ##### now lets test some graph properties.....##
76 ## basic properties from SImpleGraph.
78 is sprintf("%.3f",$g2->density), "0.027";
79 is $g2->is_connected, '';
80 is $g2->is_forest, undef;
85 ## get connected subgraphs
86 my @components = $g2->components();
87 is scalar @components, 5;
89 ## get nodes connected to parameter
90 my $t = $g2->traversal($g2->nodes_by_id('3079N'));
91 my @dfnodes = $t->get_all;
94 ##before deleting 3048N, 3047N has 2 neighbours
95 my @n1 = $g2->neighbors($g2->nodes_by_id('3047N'));
98 ok $g2->remove_nodes($g2->nodes_by_id('3048N'));
100 ## after deleting there is only 1 interactor
101 @n1 = $g2->neighbors($g2->nodes_by_id('3047N'));
104 ##check no undefs left after node removal ##
106 ok map {$_->object_id}$g2->edges;
108 ## get an edge by its id
110 ok my $edge = $g2->edge_by_id('4368E');
111 is $edge->object_id, '4368E';
115 is $g2->edge_count, 71;
117 my @n = $g2->neighbors($g2->nodes_by_id('3075N'));
120 ok $g2->remove_nodes($g2->nodes_by_id('3075N'));
122 ## should be 13 less interactions in graph.
123 is scalar $g2->edge_count, 58;
125 ## many more subgraphs now
126 @components = $g2->components();
127 #there were 5 subgraphs, now there are 10 unconnected nodes, total 15
128 is scalar @components, 15;
130 ## how many unconnected nodes?
131 my @ucnodes = $g2->unconnected_nodes;
132 is scalar @ucnodes, 10;
134 ##get CC using protein object..
135 is sprintf("%.3f", $g2->clustering_coefficient($g2->nodes_by_id('B64525'))), 0.022;
137 #.. and using id string (same as previous, for convenience )
138 is sprintf("%.3f", $g2->clustering_coefficient('B64525')), 0.022;
140 ## test has_node() method
141 is $g2->has_node('B64525'), 1;
142 is $g2->has_node('B64'), 0;
144 ## remove a single duplicate edge
145 ok $g2->remove_dup_edges($g2->nodes_by_id('3103N'));
147 ## remove all duplicate edges
148 ok $g2->remove_dup_edges();
150 ## should now be no duplicates
151 my @dupids = map{$_->object_id()} $g2->dup_edges();
152 is $dupids[0], undef;
154 ########### now we test the 'union()' method to see it conforms to
155 ## the rules described in its documentation:
157 $io = Bio::Graph::IO->new(
159 -file => test_input_file('tab1part.mif'));
160 $gr = $io->next_network();
161 $io2 = Bio::Graph::IO->new(
163 -file => test_input_file('tab1part.mif'));
165 $g2 = $io2->next_network();
167 # First of all we put the same graph into both variables. After a union
168 # graph 1 should be unaffected. Because all edge ids are the same,
169 # all duplicates will be redundant.
170 # therea re 3 duplicates in dataset.
171 my @dups = $gr->dup_edges();
174 @dups = $gr->dup_edges();
176 my @redundant = $gr->redundant_edge();
177 is scalar @redundant, 72;
179 ## now lets do a union with a graph that has some new edges,
180 ## using existing nodes
185 $io = Bio::Graph::IO->new(
187 -file => test_input_file('tab1part.mif'));
188 $gr = $io->next_network();
189 $io2 = Bio::Graph::IO->new(
191 -file => test_input_file('tab2part.mif'));
192 $g2 = $io2->next_network();
193 is $gr->edge_count, 72;
194 is $gr->node_count, 74;
196 #there should be 1 more edge in the graph $gr now, with no new nodes.
198 is $gr->edge_count, 73;
199 is $gr->node_count, 74;
201 ## now lets test a union that has new nodes in $g2
204 $io = Bio::Graph::IO->new
206 -file => test_input_file('tab1part.mif'));
207 $gr = $io->next_network();
208 $io2 = Bio::Graph::IO->new
210 -file => test_input_file('tab3part.mif'));
212 $g2 = $io2->next_network();
213 is $gr->edge_count, 72;
214 is $gr->node_count, 74;
216 # there should be 2 more edge in the graph $gr now and 2 more nodes.
218 is $gr->edge_count, 74;
219 is $gr->node_count, 76;
221 # test IO/psi_xml if the required modules are present
223 test_skip(-tests => 12, -requires_module => 'XML::Twig');
225 ok $io = Bio::Graph::IO->new
226 (-format => 'psi_xml',
227 -file => test_input_file('psi_xml.dat'));
228 ok my $g = $io->next_network();
229 is $g->edge_count, 3;
230 is $g->node_count, 4;
231 #my @rts =$g->articulation_points();
232 my $n = $g->nodes_by_id(207153);
233 is $n->species->node_name,"Helicobacter pylori 26695";
234 is $n->primary_seq->desc,"bogus-binding membrane protein (lepA) HP0355";
236 # PSI XML from IntAct
237 ok my $io2 = Bio::Graph::IO->new
238 (-format => 'psi_xml',
239 -file => test_input_file('sv40_small.xml'));
240 ok my $g3 = $io2->next_network();
241 is $g3->edge_count, 3;
242 is $g3->node_count, 5;
244 my @rts =$g->articulation_points();
245 $n = $g->nodes_by_id(207153);
247 local $TODO = 'Possible bug in binomial output';
248 is $n->species->binomial(),"Helicobacter pylori 26695";
250 is $n->primary_seq->desc,"bogus-binding membrane protein (lepA) HP0355";