| 1 | # | ||||||||||||||||||||||||||||
| 2 | # BioPerl module for Bio::Network::ProteinNet | ||||||||||||||||||||||||||||
| 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::ProteinNet - a representation of a protein interaction graph. | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # Read in from file | ||||||||||||||||||||||||||||
| 14 | my $graphio = Bio::Network::IO->new(-file => 'human.xml', | ||||||||||||||||||||||||||||
| 15 | -format => 'psi25'); | ||||||||||||||||||||||||||||
| 16 | my $graph = $graphio->next_network(); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | my @edges = $gr->edges; | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | for my $edge (@edges) { | ||||||||||||||||||||||||||||
| 21 | for my $node ($edge->[0],$edge->[1]) { | ||||||||||||||||||||||||||||
| 22 | my @proteins = $node->proteins; | ||||||||||||||||||||||||||||
| 23 | for my $protein (@proteins) { | ||||||||||||||||||||||||||||
| 24 | print $protein->display_id," "; | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 Perl Graph module | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | The bioperl-network package uses the Perl Graph module, use version .86 or greater. | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head2 Working with Nodes | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | A Node object represents either a protein or a protein complex. Nodes can | ||||||||||||||||||||||||||||
| 36 | be retrieved through their identifiers: | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # Get a node (represented by a sequence object) from the graph. | ||||||||||||||||||||||||||||
| 39 | my $node = $graph->get_nodes_by_id('UniProt:P12345'); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # A node that's a protein can be treated just like a Sequence object | ||||||||||||||||||||||||||||
| 42 | print $node->seq; | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # Remove a node by specifying its identifier | ||||||||||||||||||||||||||||
| 45 | $graph->remove_nodes($graph->get_nodes_by_id('UniProt:P12345')); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # How many nodes are there? | ||||||||||||||||||||||||||||
| 48 | my $ncount = $graph->nodes(); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # Get interactors of your favourite protein | ||||||||||||||||||||||||||||
| 51 | my $node = $graph->get_nodes_by_id('RefSeq:NP_023232'); | ||||||||||||||||||||||||||||
| 52 | my @neighbors = $graph->neighbors($node); | ||||||||||||||||||||||||||||
| 53 | print " NP_023232 interacts with "; | ||||||||||||||||||||||||||||
| 54 | print join " ,", map{$_->primary_id()} @neighbors; | ||||||||||||||||||||||||||||
| 55 | print "\n"; | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Annotate your sequences with interaction info | ||||||||||||||||||||||||||||
| 58 | my @seq_objects = ($seq1, $seq2, $seq3); | ||||||||||||||||||||||||||||
| 59 | for my $seq (@seq_objects) { | ||||||||||||||||||||||||||||
| 60 | if ( $graph->get_nodes_by_id($seq->accession_number) ) { | ||||||||||||||||||||||||||||
| 61 | my $node = $graph->get_nodes_by_id( $seq->accession_number); | ||||||||||||||||||||||||||||
| 62 | my @neighbors = $graph->neighbors($node); | ||||||||||||||||||||||||||||
| 63 | for my $n (@neighbors) { | ||||||||||||||||||||||||||||
| 64 | my $ft = Bio::SeqFeature::Generic->new( | ||||||||||||||||||||||||||||
| 65 | -primary_tag => 'Interactor', | ||||||||||||||||||||||||||||
| 66 | -tag => { id => $n->accession_number } | ||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||
| 68 | $seq->add_SeqFeature($ft); | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Get proteins with > 10 interactors | ||||||||||||||||||||||||||||
| 74 | my @nodes = $graph->nodes(); | ||||||||||||||||||||||||||||
| 75 | my @hubs; | ||||||||||||||||||||||||||||
| 76 | for my $node (@nodes) { | ||||||||||||||||||||||||||||
| 77 | if ($graph->neighbors($node) > 10) { | ||||||||||||||||||||||||||||
| 78 | push @hubs, $node; | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | print "the following proteins have > 10 interactors:\n"; | ||||||||||||||||||||||||||||
| 82 | print join "\n", map {$_->primary_id()} @hubs; | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # Get clustering coefficient of a given node. | ||||||||||||||||||||||||||||
| 85 | my $id = "RefSeq:NP_023232"; | ||||||||||||||||||||||||||||
| 86 | my $cc = $graph->clustering_coefficient($graph->get_nodes_by_id($id)); | ||||||||||||||||||||||||||||
| 87 | if ($cc != -1) { ## result is -1 if cannot be calculated | ||||||||||||||||||||||||||||
| 88 | print "CC for $id is $cc"; | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head2 Working with Edges | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | # How many edges are there? | ||||||||||||||||||||||||||||
| 94 | my $ecount = $graph->edges; | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | # Get all the paired nodes, or edges, in the graph as an array | ||||||||||||||||||||||||||||
| 97 | my @edges = $graph->edges | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =head2 Working with Interactions | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | # How many interactions are there? | ||||||||||||||||||||||||||||
| 102 | my $icount = $graph->interactions; | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # Retrieve all interactions | ||||||||||||||||||||||||||||
| 105 | my @interx = $graph->interactions; | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # Get interactions above a threshold confidence score | ||||||||||||||||||||||||||||
| 108 | for my $interx (@interx) { | ||||||||||||||||||||||||||||
| 109 | if ($interx->weight > 0.6) { | ||||||||||||||||||||||||||||
| 110 | print $interx->primary_id, "\t", $interx->weight, "\n"; | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =head2 Working with Graphs | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | # Get graph density | ||||||||||||||||||||||||||||
| 117 | my $density = $graph->density(); | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | # Get connected sub-graphs | ||||||||||||||||||||||||||||
| 120 | my @graphs = $graph->connected_components(); | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # Copy interactions from one graph to another | ||||||||||||||||||||||||||||
| 123 | $graph1->add_interactions_from($graph2); | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =head2 Creating networks from your own data | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | If you have interaction data in your own format, e.g. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | <interaction id> <protein id 1> <protein id 2> <score> | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | A simple approach would look something like this: | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | my $io = Bio::Root::IO->new(-file => 'mydata'); | ||||||||||||||||||||||||||||
| 135 | my $graph = Bio::Network::ProteinNet->new(refvertexed => 1); | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | while (my $l = $io->_readline() ) { | ||||||||||||||||||||||||||||
| 138 | my ($id, $nid1, $nid2, $sc) = split /\s+/, $l; | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | my $prot1 = Bio::Seq->new(-accession_number => $nid1); | ||||||||||||||||||||||||||||
| 141 | my $prot2 = Bio::Seq->new(-accession_number => $nid2); | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | # create new Interaction object based on an id and weight | ||||||||||||||||||||||||||||
| 144 | my $interaction = Bio::Network::Interaction->new(-id => $id, | ||||||||||||||||||||||||||||
| 145 | -weight => $sc ); | ||||||||||||||||||||||||||||
| 146 | $graph->add_interaction(-nodes => [($prot1,$prot2)]), | ||||||||||||||||||||||||||||
| 147 | -interaction => $interaction ); | ||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | A ProteinNet is a representation of a protein interaction network. | ||||||||||||||||||||||||||||
| 154 | Its functionality comes from the L<Graph> module of Perl and from BioPerl, | ||||||||||||||||||||||||||||
| 155 | the nodes or vertices in the network are Sequence objects. | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =head2 Nodes | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | A node is one or more BioPerl sequence objects, a L<Bio::Seq> or | ||||||||||||||||||||||||||||
| 160 | L<Bio::Seq::RichSeq> object. Essentially the graph can use any objects | ||||||||||||||||||||||||||||
| 161 | that implement L<Bio::AnnotatableI> and L<Bio::IdentifiableI> interfaces | ||||||||||||||||||||||||||||
| 162 | since these objects hold useful identifiers. This is relevant since the | ||||||||||||||||||||||||||||
| 163 | identity of nodes is determined by their identifiers. | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =head2 Interactions and Edges | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | Since bioperl-network is built on top of the L<Graph> and L<Graph::Undirected> | ||||||||||||||||||||||||||||
| 168 | modules of Perl it uses its formal model as well. An Edge corresponds to a | ||||||||||||||||||||||||||||
| 169 | pair of nodes, and there is only one Edge per pair. An Interaction is an | ||||||||||||||||||||||||||||
| 170 | attribute of an Edge, and there can be 1 or more Interactions per Edge. So | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | $ecount = $network->edges | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | Tells you how many paired nodes there are and | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | $icount = $network->interactions | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | Tells you how many node-node interactions there are. An Interaction is | ||||||||||||||||||||||||||||
| 179 | equivalent to one experiment or one experimental observation. | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =head1 FOR DEVELOPERS | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | In this module, the nodes or vertexes are represented by L<Bio::Seq> | ||||||||||||||||||||||||||||
| 184 | objects containing database identifiers but usually | ||||||||||||||||||||||||||||
| 185 | without sequence, since the data is parsed from protein-protein | ||||||||||||||||||||||||||||
| 186 | interaction data. | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | Interactions should be L<Bio::Network::Interaction> objects, which are | ||||||||||||||||||||||||||||
| 189 | L<Bio::IdentifiableI> implementing objects. At present Interactions only | ||||||||||||||||||||||||||||
| 190 | have an identifier and a weight() method, to hold confidence data. | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | A ProteinNet object has the following internal data, aside from the data | ||||||||||||||||||||||||||||
| 193 | structures of Graph itself: | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =over 2 | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | =item _id_map | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | Look-up hash ('_id_map') for finding a node using any of its ids. The keys | ||||||||||||||||||||||||||||
| 200 | are standard identifiers (e.g. "GenBank:A12345") and the values are | ||||||||||||||||||||||||||||
| 201 | memory addresses used by Graph (e.g. "Bio::Network::Node=HASH(0x1bc53e4)"). | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =item _interx_id_map | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | Look-up hash for Interactions ('_interx_id_map'),used for retrieving an | ||||||||||||||||||||||||||||
| 206 | Interaction object using an identifier. The keys are primary ids of the | ||||||||||||||||||||||||||||
| 207 | Interaction (e.g. "DIP:2341E") and the values are addresses of | ||||||||||||||||||||||||||||
| 208 | Interactions (e.g. "Bio::Network::Interaction=HASH(0x1bc46f2)"). | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =back | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | The function of these hashes is either to facilitate fast lookups or | ||||||||||||||||||||||||||||
| 213 | to cache data. | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | =head1 API CHANGES | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | These modules were first released as part of the core BioPerl package | ||||||||||||||||||||||||||||
| 218 | and were called Bio::Graph. Bio::Graph was copied to a separate package, | ||||||||||||||||||||||||||||
| 219 | bioperl-network, and renamed Bio::Network. All of the modules were | ||||||||||||||||||||||||||||
| 220 | revised and a new module, Interaction.pm, was added. The | ||||||||||||||||||||||||||||
| 221 | functionality of the PSI MI parser, IO/psi.pm, was significantly | ||||||||||||||||||||||||||||
| 222 | enhanced. | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | Graph manipulation in Bio::Graph was based on the Bio::Graph::SimpleGraph | ||||||||||||||||||||||||||||
| 225 | module by Nat Goodman. The first release as a separate package, | ||||||||||||||||||||||||||||
| 226 | bioperl-network, replaced SimpleGraph with the Perl Graph package. Other | ||||||||||||||||||||||||||||
| 227 | API changes were also made, partly to keep nomenclature consistent with | ||||||||||||||||||||||||||||
| 228 | BioPerl, partly to use the terms used by the interaction databases, and | ||||||||||||||||||||||||||||
| 229 | partly to accomodate the differences between Graph and | ||||||||||||||||||||||||||||
| 230 | Bio::Graph::SimpleGraph. | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | The advantages to using Graph are that Bioperl developers are not | ||||||||||||||||||||||||||||
| 233 | responsible for maintaining the code that actually handles graph | ||||||||||||||||||||||||||||
| 234 | manipulation and there is more functionality in Graph than in SimpleGraph. | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =over 13 | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | =item Bio::Graph::Edge | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | Bio::Graph::Edge has been replaced by Bio::Network::Interaction | ||||||||||||||||||||||||||||
| 241 | and Bio::Network::Edge | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | =item next_graph() | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | This method has been replaced by next_network(). | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | =item union() | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | The union() method has been removed since it was not performing a true | ||||||||||||||||||||||||||||
| 250 | union. It has been replaced by L<add_interaction_from> | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | =item remove_nodes() | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | remove_nodes() is now an alias to Graph::delete_vertices | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | =item _get_ids_by_db() | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | _get_ids_by_db() has been renamed L<get_ids_by_node> | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | =item add_node() | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | add_node() is now an alias to Graph::add_vertex | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | =item components() | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | components() is now an alias to Graph::connected_components | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | =item edge_count() | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | edge_count() is now an alias to Graph::edges | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | =item node_count() | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | node_count() is now an alias to Graph::vertices | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | =item nodes_by_id() | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | nodes_by_id() is now an alias to L<get_nodes_by_id> | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | =item edge_by_id() | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | This method has been removed since edges no longer have identifiers, | ||||||||||||||||||||||||||||
| 283 | Interactions do. Use L<get_interaction_by_id> | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | =item unconnected_nodes() | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | unconnected_nodes() is now an alias to Graph::isolated_vertices | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | =item object_id() | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | object_id() is now an alias to Interaction::primary_id() | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | =back | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | =head1 REQUIREMENTS | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | To use this module you need Graph.pm, version .80 or greater. To | ||||||||||||||||||||||||||||
| 298 | read XML data (e.g. PSI XML) you will need XML::Twig. | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | L<Bio::Network::IO> | ||||||||||||||||||||||||||||
| 303 | L<Bio::Network::Edge> | ||||||||||||||||||||||||||||
| 304 | L<Bio::Network::Node> | ||||||||||||||||||||||||||||
| 305 | L<Bio::Network::Interaction> | ||||||||||||||||||||||||||||
| 306 | L<Bio::Network::IO::dip> | ||||||||||||||||||||||||||||
| 307 | L<Bio::Network::IO::psi> | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | =head1 FEEDBACK | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | =head2 Mailing Lists | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | User feedback is an integral part of the evolution of this and other | ||||||||||||||||||||||||||||
| 314 | Bioperl modules. Send your comments and suggestions preferably to one | ||||||||||||||||||||||||||||
| 315 | of the Bioperl mailing lists. Your participation is much appreciated. | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||||||||
| 318 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | =head2 Support | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||
| 327 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||
| 328 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||
| 329 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||
| 334 | the bugs and their resolution. Bug reports can be submitted via the | ||||||||||||||||||||||||||||
| 335 | web: | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | http://bugzilla.open-bio.org/ | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | Brian Osborne bosborne at alum.mit.edu | ||||||||||||||||||||||||||||
| 342 | Richard Adams richard.adams@ed.ac.uk | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | Maintained by Brian Osborne | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | The first version of this package was based on the Bio::Graph::SimpleGraph | ||||||||||||||||||||||||||||
| 347 | module written by Nat Goodman. | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | =cut | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | package Bio::Network::ProteinNet; | ||||||||||||||||||||||||||||
| 352 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 353 | 3 | ▶ | use Graph 0.86; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 354 | 3 | ▶ | use Bio::Network::Interaction; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 355 | 3 | ▶ | use Bio::Root::Root; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 356 | 3 | ▶ | use vars qw($GRAPH_ARRAY_INDEX @ISA); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 357 | 3 | @ISA = qw( Graph::Undirected Bio::Root::Root ); | |||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | # A Graph object is an array reference, therefore we need | ||||||||||||||||||||||||||||
| 360 | # to add all our additional data at a specific, arbitrary index | ||||||||||||||||||||||||||||
| 361 | 3 | $GRAPH_ARRAY_INDEX = 5; | |||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | =head2 get_interaction_by_id | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | Name : get_interaction_by_id | ||||||||||||||||||||||||||||
| 367 | Purpose : Get an interaction using an id | ||||||||||||||||||||||||||||
| 368 | Usage : $interx = $g->get_interaction_by_id($id) | ||||||||||||||||||||||||||||
| 369 | Returns : One or more Interactions | ||||||||||||||||||||||||||||
| 370 | Arguments : One or more Interaction identifiers, the primary id | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | =cut | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 0 | ▶ | sub get_interaction_by_id { | ||||||||||||||||||||||||||
|
Subroutine
get_interaction_by_id: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 375 | 0 | my ($self,@ids) = @_; | |||||||||||||||||||||||||||
| 376 | 0 | ▶ | $self->throw("I need an identifier!") unless (@ids); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 377 | 0 | my @interx; | |||||||||||||||||||||||||||
| 378 | 0 | for my $id (@ids) { | |||||||||||||||||||||||||||
| 379 | 0 | my @temp; | |||||||||||||||||||||||||||
| 380 | 0 | push @temp, $self->[$GRAPH_ARRAY_INDEX]->{'_interx_id_map'}->{$id}; | |||||||||||||||||||||||||||
| 381 | 0 | ▶ | $self->warn("More than 1 Interaction retrieved using id $id") if ($#temp > 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 382 | 0 | push @interx,@temp; | |||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | 0 | ▶ | scalar @interx == 1 ? return $interx[0] : return @interx; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | =head2 get_nodes_by_id | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | Name : get_nodes_by_id | ||||||||||||||||||||||||||||
| 390 | Purpose : Get node using an id | ||||||||||||||||||||||||||||
| 391 | Usage : $node = $g->get_nodes_by_id($id) | ||||||||||||||||||||||||||||
| 392 | Returns : One node | ||||||||||||||||||||||||||||
| 393 | Arguments : One or more protein identifiers | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | =cut | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | 1 | ▶ | sub get_nodes_by_id { | ||||||||||||||||||||||||||
|
Subroutine
get_nodes_by_id: called CC=3 SCAR=20.3
Pod
documented
| |||||||||||||||||||||||||||||
| 398 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 399 | 1 | my @ids = @_; | |||||||||||||||||||||||||||
| 400 | 1 | my @nodes = $self->_ids(@ids); | |||||||||||||||||||||||||||
| 401 | 0 | ▶ | unless (@nodes) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 402 | 0 | my $str = join " ",@ids; | |||||||||||||||||||||||||||
| 403 | 0 | $self->warn("No nodes retrieved using these ids: $str"); | |||||||||||||||||||||||||||
| 404 | 0 | return 0; | |||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | 0 | ▶ | if ($#nodes > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 407 | 0 | my $str = join " ",@ids; | |||||||||||||||||||||||||||
| 408 | #$self->warn("Returning >1 node retrieved using these ids: $str"); | ||||||||||||||||||||||||||||
| 409 | 0 | return @nodes; | |||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||
| 411 | 0 | $nodes[0]; | |||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | =head2 get_interactions | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | Name : get_interactions | ||||||||||||||||||||||||||||
| 417 | Purpose : Get 1 or more Interaction objects given a pair of nodes | ||||||||||||||||||||||||||||
| 418 | Usage : @interx = $g->get_interactions($n1,$n2) | ||||||||||||||||||||||||||||
| 419 | Returns : A hash of Interaction objects where the key is the primary | ||||||||||||||||||||||||||||
| 420 | id of the Interaction and the value is the Interaction | ||||||||||||||||||||||||||||
| 421 | Arguments : 2 nodes | ||||||||||||||||||||||||||||
| 422 | Notes : | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | =cut | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 0 | ▶ | sub get_interactions { | ||||||||||||||||||||||||||
|
Subroutine
get_interactions: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 427 | 0 | my ($self,@nodes) = @_; | |||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | 0 | ▶ | $self->throw("The get_interactions method needs 2 nodes, not ". | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 430 | scalar @nodes . " nodes") if ($#nodes != 1); | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | 0 | for my $node (@nodes) { | |||||||||||||||||||||||||||
| 433 | 0 | ▶ | $self->throw("Node must be a Bio::Network::Node object, not a [". ref($node) . "].") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 434 | unless ($node->isa("Bio::Network::Node")); | ||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | 0 | my $interactions = $self->get_edge_attributes(@nodes); | |||||||||||||||||||||||||||
| 438 | 0 | %$interactions; | |||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | =head2 add_id_to_interaction | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | Name : add_id_to_interaction | ||||||||||||||||||||||||||||
| 444 | Purpose : Store identifiers in an internal hash that is used to look | ||||||||||||||||||||||||||||
| 445 | up interactions by id - this does not add ids to Interaction | ||||||||||||||||||||||||||||
| 446 | objects. | ||||||||||||||||||||||||||||
| 447 | Usage : $g->add_id_to_interaction($id,$interaction) | ||||||||||||||||||||||||||||
| 448 | Arguments : Identifier and Interaction object. | ||||||||||||||||||||||||||||
| 449 | Returns : | ||||||||||||||||||||||||||||
| 450 | Notes : The identifier should be concatenated | ||||||||||||||||||||||||||||
| 451 | with a database or namespace name in order to make | ||||||||||||||||||||||||||||
| 452 | accurate comparisons when you are merging data from different | ||||||||||||||||||||||||||||
| 453 | formats. Examples: DIP:3455E. | ||||||||||||||||||||||||||||
| 454 | Use _get_standard_name() to find a standardized name. | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | See L<_get_standard_name> | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | =cut | ||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | 0 | ▶ | sub add_id_to_interaction { | ||||||||||||||||||||||||||
|
Subroutine
add_id_to_interaction: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 461 | 0 | my ($g,$id,$interx) = @_; | |||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | 0 | ▶ | $g->throw("Node must be a Bio::Network::Interaction object, not a [" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 464 | . ref($interx) . "]." ) unless ($interx->isa("Bio::Network::Interaction")); | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 0 | ▶ | $g->[$GRAPH_ARRAY_INDEX]->{'_interx_id_map'}->{$id} = $interx if $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | =head2 add_id_to_node | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | Name : add_id_to_node | ||||||||||||||||||||||||||||
| 472 | Purpose : Store identifiers in an internal hash that is used to look | ||||||||||||||||||||||||||||
| 473 | up nodes by id - this does not add ids to Node objects | ||||||||||||||||||||||||||||
| 474 | or their associated Annotation objects. | ||||||||||||||||||||||||||||
| 475 | Usage : $g->add_id_to_node($id,$node) or | ||||||||||||||||||||||||||||
| 476 | $g->add_id_to_node(\@ids,$node) | ||||||||||||||||||||||||||||
| 477 | Arguments : Identifier (or reference to an array of identifiers), node. | ||||||||||||||||||||||||||||
| 478 | Returns : | ||||||||||||||||||||||||||||
| 479 | Notes : The identifier should be concatenated | ||||||||||||||||||||||||||||
| 480 | with a database or namespace name in order to make | ||||||||||||||||||||||||||||
| 481 | accurate comparisons when you are merging data from different | ||||||||||||||||||||||||||||
| 482 | formats. Examples: DIP:3455N, UniProt:Q45772, GenBank:7733911. | ||||||||||||||||||||||||||||
| 483 | Use _get_standard_name() to find a standardized name. | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | See L<_get_standard_name> | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | =cut | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | 0 | ▶ | sub add_id_to_node { | ||||||||||||||||||||||||||
|
Subroutine
add_id_to_node: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 490 | 0 | my ($g,$id,$node) = @_; | |||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | 0 | ▶ | $g->throw("Node must be a Bio::Network::Node object, not a [" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 493 | . ref($node) . "]." ) unless ($node->isa("Bio::Network::Node")); | ||||||||||||||||||||||||||||
| 494 | 0 | ▶ | $g->throw("Node $node does not exist, cannot add edge") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 495 | unless ($g->has_node($node)); | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | 0 | ▶ | if (ref $id eq "ARRAY") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 498 | 0 | my @ids = @$id; | |||||||||||||||||||||||||||
| 499 | 0 | for my $id (@ids) { | |||||||||||||||||||||||||||
| 500 | 0 | ▶ | next unless $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 501 | 0 | $g->[$GRAPH_ARRAY_INDEX]->{'_id_map'}->{$id} = $node; | |||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||
| 503 | } else { | ||||||||||||||||||||||||||||
| 504 | 0 | ▶ | $g->[$GRAPH_ARRAY_INDEX]->{'_id_map'}->{$id} = $node if $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | =head2 add_interactions_from | ||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | Name : add_interactions_from | ||||||||||||||||||||||||||||
| 511 | Purpose : To copy interactions from one graph to another | ||||||||||||||||||||||||||||
| 512 | Usage : $graph1->add_interactions_from($graph2) | ||||||||||||||||||||||||||||
| 513 | Returns : void | ||||||||||||||||||||||||||||
| 514 | Arguments : A Graph object of the same class as the calling object. | ||||||||||||||||||||||||||||
| 515 | Description : This method copies interactions from the graph passed as the | ||||||||||||||||||||||||||||
| 516 | argument to the calling graph. To take account of | ||||||||||||||||||||||||||||
| 517 | differing IDs identifying the same protein, all ids are | ||||||||||||||||||||||||||||
| 518 | compared. The following rules are used: | ||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | 1. If a pair of nodes exist in both graphs then: | ||||||||||||||||||||||||||||
| 521 | a. No Interactions with the same primary id will be copied | ||||||||||||||||||||||||||||
| 522 | from $graph2 to $graph1. | ||||||||||||||||||||||||||||
| 523 | b. All other Interactions from $graph2 will be copied | ||||||||||||||||||||||||||||
| 524 | to $graph1, even if these nodes do not interact in $graph1. | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | 2. Nodes are never copied from $graph2 to $graph1. This is rather | ||||||||||||||||||||||||||||
| 527 | conservative but prevents the problem of having duplicated, | ||||||||||||||||||||||||||||
| 528 | identical nodes in $graph1 due to the same protein being identified | ||||||||||||||||||||||||||||
| 529 | by different ids in the 2 graphs. | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | So, for example | ||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | Interaction N1 N2 Comment | ||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | Graph 1: E1 P1 P2 | ||||||||||||||||||||||||||||
| 536 | E2 P3 P4 | ||||||||||||||||||||||||||||
| 537 | E3 P1 P4 | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | Graph 2: E1 P1 P2 E1 will not be copied to Graph1 | ||||||||||||||||||||||||||||
| 540 | X2 P1 P3 X2 will be copied to Graph 1 | ||||||||||||||||||||||||||||
| 541 | X3 P1 P4 X3 will be copied to Graph 1 | ||||||||||||||||||||||||||||
| 542 | X4 Z4 Z5 Nothing copied to Graph1 | ||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | There are measures one could take to allow copying nodes from $graph2 | ||||||||||||||||||||||||||||
| 545 | to $graph1, currently unimplemented: | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | 1. Use sequence, if available, and some threshold measure of similarity, | ||||||||||||||||||||||||||||
| 548 | or length, to prove that proteins are not identical and can be copied. | ||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | 2. Use species information. For example, if $graph1 is entirely composed | ||||||||||||||||||||||||||||
| 551 | of human proteins then any non-human proteins could be copied to | ||||||||||||||||||||||||||||
| 552 | $graph1 without risk (and cross-species interactions are fairly common | ||||||||||||||||||||||||||||
| 553 | due the nature of interaction experiments). | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | 3. Use namespace or dataspace when assessing identity. For example, assume | ||||||||||||||||||||||||||||
| 556 | that all nodes in $graph1 are identified by Swissprot ids. Assume a | ||||||||||||||||||||||||||||
| 557 | protein in $graph2 is also identified by a Swissprot id, not found in | ||||||||||||||||||||||||||||
| 558 | $graph1. This could be reasonable grounds for allowing the protein in | ||||||||||||||||||||||||||||
| 559 | $graph2 to be copied to $graph1. | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | 4. Some combination of the above. | ||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||
| 563 | =cut | ||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||
| 565 | 0 | ▶ | sub add_interactions_from { | ||||||||||||||||||||||||||
|
Subroutine
add_interactions_from: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||
| 566 | 0 | my ($graph1, $graph2) = @_; | |||||||||||||||||||||||||||
| 567 | 0 | my $class = ref($graph1); | |||||||||||||||||||||||||||
| 568 | 0 | ▶ | $graph1->throw("add_interaction_from() needs a ". $class . " object, not a [". | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 569 | ref($graph2). "] object") unless ($graph2->isa($class)); | ||||||||||||||||||||||||||||
| 570 | 0 | my (%common_ids,%common_nodes); | |||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||
| 572 | # get identifiers found in both graphs | ||||||||||||||||||||||||||||
| 573 | 0 | for my $id ( (keys %{$graph1->[$GRAPH_ARRAY_INDEX]->{'_id_map'}}), | |||||||||||||||||||||||||||
| 574 | 0 | (keys %{$graph2->[$GRAPH_ARRAY_INDEX]->{'_id_map'}}) ) { | |||||||||||||||||||||||||||
| 575 | 0 | $common_ids{$id}++; | |||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||
| 577 | # get nodes corresponding to identifiers found in both graphs | ||||||||||||||||||||||||||||
| 578 | 0 | for my $id (keys %common_ids) { | |||||||||||||||||||||||||||
| 579 | 0 | ▶ | if ($common_ids{$id} == 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 580 | 0 | ▶ | if (defined $graph1->[$GRAPH_ARRAY_INDEX]->{'_id_map'}{$id} && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $graph1->[$Bio::Network::ProteinNet::GRAPH_ARRAY_INDEX]{"_id_map"}{$id} and defined $graph2->[$Bio::Network::ProteinNet::GRAPH_ARRAY_INDEX]{"_id_map"}{$id}
MC/DC0%0/2
defined $graph1->[$Bio::Network::ProteinNet::GRAPH_ARRAY_INDEX]{"_id_map"}{$id} and defined $graph2->[$Bio::Network::ProteinNet::GRAPH_ARRAY_INDEX]{"_id_map"}{$id}
defined $graph1->[$Bio::Network::ProteinNet::GRAPH_ARRAY_INDEX]{"_id_map"}{$id}
defined $graph2->[$Bio::Network::ProteinNet::GRAPH_ARRAY_INDEX]{"_id_map"}{$id}
Truth table0%0/3
A and B
A= defined $graph1->[$Bio::Network::ProteinNet::GRAPH_ARRAY_INDEX]{"_id_map"}{$id}B= defined $graph2->[$Bio::Network::ProteinNet::GRAPH_ARRAY_INDEX]{"_id_map"}{$id}
| |||||||||||||||||||||||||||||
| 581 | defined $graph2->[$GRAPH_ARRAY_INDEX]->{'_id_map'}{$id} ) { | ||||||||||||||||||||||||||||
| 582 | $common_nodes{$graph2->[$GRAPH_ARRAY_INDEX]->{'_id_map'}{$id}} = | ||||||||||||||||||||||||||||
| 583 | 0 | $graph1->[$GRAPH_ARRAY_INDEX]->{'_id_map'}{$id}; | |||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||
| 587 | # get all the edges in $graph2, if both nodes for a given edge are in | ||||||||||||||||||||||||||||
| 588 | # $graph1 then interactions can be copied, unless it's already in $graph1 | ||||||||||||||||||||||||||||
| 589 | 0 | my @edges = $graph2->edges; | |||||||||||||||||||||||||||
| 590 | 0 | for my $edgeref (@edges) { | |||||||||||||||||||||||||||
| 591 | 0 | ▶ | if (defined $common_nodes{$edgeref->[0]} && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $common_nodes{$edgeref->[0]} and defined $common_nodes{$edgeref->[1]}
MC/DC0%0/2
defined $common_nodes{$edgeref->[0]} and defined $common_nodes{$edgeref->[1]}
defined $common_nodes{$edgeref->[0]}
defined $common_nodes{$edgeref->[1]}
Truth table0%0/3
A and B
A= defined $common_nodes{$edgeref->[0]}B= defined $common_nodes{$edgeref->[1]}
| |||||||||||||||||||||||||||||
| 592 | defined $common_nodes{$edgeref->[1]} ) { | ||||||||||||||||||||||||||||
| 593 | 0 | my $attref2 = $graph2->get_edge_attributes($edgeref->[0],$edgeref->[1]); # nothing | |||||||||||||||||||||||||||
| 594 | 0 | ▶ | if ($graph1->has_edge($common_nodes{$edgeref->[0]}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 595 | $common_nodes{$edgeref->[1]}) ) { | ||||||||||||||||||||||||||||
| 596 | # interactions for the given pair are in both graphs... | ||||||||||||||||||||||||||||
| 597 | my $attref1 = $graph1->get_edge_attributes($common_nodes{$edgeref->[0]}, | ||||||||||||||||||||||||||||
| 598 | 0 | $common_nodes{$edgeref->[1]}); | |||||||||||||||||||||||||||
| 599 | 0 | for my $interxid (keys %$attref2) { | |||||||||||||||||||||||||||
| 600 | #...so check to see if their primary id's are the same or not | ||||||||||||||||||||||||||||
| 601 | 0 | ▶ | unless (defined $attref1->{$interxid}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 602 | $graph1->add_interaction(-nodes => [($common_nodes{$edgeref->[0]}, | ||||||||||||||||||||||||||||
| 603 | $common_nodes{$edgeref->[1]})], | ||||||||||||||||||||||||||||
| 604 | 0 | -interaction => $attref2->{$interxid}); | |||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||
| 607 | } else { | ||||||||||||||||||||||||||||
| 608 | # a pair of nodes in $graph2 interact but don't interact in $graph1 | ||||||||||||||||||||||||||||
| 609 | 0 | for my $interxid (keys %$attref2) { | |||||||||||||||||||||||||||
| 610 | $graph1->add_interaction(-nodes => [($common_nodes{$edgeref->[0]}, | ||||||||||||||||||||||||||||
| 611 | $common_nodes{$edgeref->[1]})], | ||||||||||||||||||||||||||||
| 612 | 0 | -interaction => $attref2->{$interxid}); | |||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||
| 619 | =head2 subgraph | ||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||
| 621 | Name : subgraph | ||||||||||||||||||||||||||||
| 622 | Purpose : Construct a subgraph of nodes from another network, including | ||||||||||||||||||||||||||||
| 623 | all Interactions. | ||||||||||||||||||||||||||||
| 624 | Usage : my $subgraph = $graph->subgraph(@nodes). | ||||||||||||||||||||||||||||
| 625 | Returns : A subgraph composed of nodes, edges, and Interactions from the | ||||||||||||||||||||||||||||
| 626 | original graph. | ||||||||||||||||||||||||||||
| 627 | Arguments : A list of nodes. | ||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||
| 629 | =cut | ||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||
| 631 | 0 | ▶ | sub subgraph { | ||||||||||||||||||||||||||
|
Subroutine
subgraph: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 632 | 0 | my ($self,@nodes) = @_; | |||||||||||||||||||||||||||
| 633 | 0 | my $class = ref($self); | |||||||||||||||||||||||||||
| 634 | 0 | my $subgraph = new $class; | |||||||||||||||||||||||||||
| 635 | 0 | my @pairs = (); | |||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||
| 637 | 0 | $subgraph->add_node(@nodes); | |||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||
| 639 | # retrieve and add interacting pairs of nodes and Interactions | ||||||||||||||||||||||||||||
| 640 | 0 | ▶ | @pairs = $self->_all_pairs(@nodes) if ($#nodes > 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 641 | 0 | for my $pair (@pairs) { | |||||||||||||||||||||||||||
| 642 | 0 | ▶ | if ( $self->has_edge(@$pair) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 643 | 0 | my $ref = $self->get_edge_attributes(@$pair); | |||||||||||||||||||||||||||
| 644 | 0 | for my $id (keys %$ref) { | |||||||||||||||||||||||||||
| 645 | $subgraph->add_interaction(-nodes => $pair, | ||||||||||||||||||||||||||||
| 646 | 0 | -interaction => $ref->{$id} ); | |||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||
| 650 | # add isolated nodes that weren't found as interacting pairs, above | ||||||||||||||||||||||||||||
| 651 | 0 | for my $node (@nodes) { | |||||||||||||||||||||||||||
| 652 | 0 | ▶ | $subgraph->add_node($node) unless ($subgraph->has_node($node)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||
| 654 | 0 | $subgraph; | |||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | =head2 get_ids_by_node | ||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||
| 659 | Name : get_ids_by_node | ||||||||||||||||||||||||||||
| 660 | Purpose : Gets all ids for a node | ||||||||||||||||||||||||||||
| 661 | Arguments: A Bio::SeqI object | ||||||||||||||||||||||||||||
| 662 | Returns : A hash: Keys are db ids, values are identifiers | ||||||||||||||||||||||||||||
| 663 | Usage : my %ids = $gr->get_ids_by_node($seqobj); | ||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | =cut | ||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||
| 667 | 0 | ▶ | sub get_ids_by_node { | ||||||||||||||||||||||||||
|
Subroutine
get_ids_by_node: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 668 | 0 | my %ids; | |||||||||||||||||||||||||||
| 669 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 670 | 0 | ▶ | while (my $node = shift @_ ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 671 | 0 | ▶ | $node->throw("I need a Bio::Network::Node object, not a [" .ref($node) ."]") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 672 | unless ( $node->isa('Bio::Network::Node') ); | ||||||||||||||||||||||||||||
| 673 | ## If Bio::Seq get dbxref ids as well. | ||||||||||||||||||||||||||||
| 674 | 0 | my @proteins = $node->proteins; | |||||||||||||||||||||||||||
| 675 | 0 | for my $protein (@proteins) { | |||||||||||||||||||||||||||
| 676 | 0 | my $ac = $protein->annotation(); | |||||||||||||||||||||||||||
| 677 | 0 | for my $an ($ac->get_Annotations('dblink')) { | |||||||||||||||||||||||||||
| 678 | 0 | $ids{$an->database()} = $an->primary_id(); | |||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||
| 682 | 0 | return %ids; | |||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||
| 685 | =head2 add_interaction | ||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||
| 687 | Name : add_interaction | ||||||||||||||||||||||||||||
| 688 | Purpose : Adds an Interaction to a graph. | ||||||||||||||||||||||||||||
| 689 | Usage : $gr->add_interaction(-interaction => $interx | ||||||||||||||||||||||||||||
| 690 | -nodes => \@nodes ); | ||||||||||||||||||||||||||||
| 691 | Arguments : An Interaction object and a reference to an array holding | ||||||||||||||||||||||||||||
| 692 | a pair of nodes | ||||||||||||||||||||||||||||
| 693 | Returns : | ||||||||||||||||||||||||||||
| 694 | Description : This is the method to use to add an interaction to a graph. | ||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||
| 696 | =cut | ||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||
| 698 | 1 | ▶ | sub add_interaction { | ||||||||||||||||||||||||||
|
Subroutine
add_interaction: called CC=5 SCAR=21.6
Pod
documented
| |||||||||||||||||||||||||||||
| 699 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 700 | 1 | my ($interx,$nodesref) = $self->_rearrange([qw(INTERACTION NODES)],@_); | |||||||||||||||||||||||||||
| 701 | 1 | my @nodes = @$nodesref; | |||||||||||||||||||||||||||
| 702 | #my $interxid = $interx->primary_id; | ||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||
| 704 | 1 | ▶ | $self->throw("The add_edge method needs 2 nodes, not ". scalar @nodes . | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 705 | " nodes") if ($#nodes != 1); | ||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||
| 707 | 1 | for my $node (@nodes) { | |||||||||||||||||||||||||||
| 708 | 2 | ▶ | unless ( $node->isa("Bio::Network::Node") ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 709 | 0 | ▶ | if ( $node->isa("Bio::Seq") ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 710 | # $self->warn("Node must be a Bio::Node object, not a [Bio::Seq]. " . | ||||||||||||||||||||||||||||
| 711 | # "Will make a Node object from it."); | ||||||||||||||||||||||||||||
| 712 | 0 | $node = Bio::Network::Node->new(-protein => [($node)]); | |||||||||||||||||||||||||||
| 713 | } else { | ||||||||||||||||||||||||||||
| 714 | 0 | $self->throw("Cannot make an interaction using a [". ref($node) . | |||||||||||||||||||||||||||
| 715 | "].") | ||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||
| 720 | 1 | $self->add_edge($nodes[0], $nodes[1]); | |||||||||||||||||||||||||||
| 721 | 0 | $self->set_edge_attribute($nodes[0], $nodes[1], $interx->primary_id, $interx); | |||||||||||||||||||||||||||
| 722 | 0 | $self->add_id_to_interaction($interx->primary_id, $interx); | |||||||||||||||||||||||||||
| 723 | # Store the node names in the Interaction object | ||||||||||||||||||||||||||||
| 724 | 0 | $interx->{_nodes} = $nodesref; | |||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||
| 728 | =head2 add_edge | ||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||
| 730 | Name : add_edge | ||||||||||||||||||||||||||||
| 731 | Purpose : | ||||||||||||||||||||||||||||
| 732 | Usage : $gr->add_edge(@nodes) | ||||||||||||||||||||||||||||
| 733 | Arguments : A pair of nodes | ||||||||||||||||||||||||||||
| 734 | Returns : | ||||||||||||||||||||||||||||
| 735 | Description : | ||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||
| 737 | =cut | ||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||
| 739 | 1 | ▶ | sub add_edge { | ||||||||||||||||||||||||||
|
Subroutine
add_edge: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||
| 740 | 1 | my ($self,@nodes) = @_; | |||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||
| 742 | 1 | ▶ | $self->throw("The add_edge method needs 2 nodes, not ". scalar @nodes . | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 743 | " nodes") if ($#nodes != 1); | ||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||
| 745 | 1 | for my $node (@nodes) { | |||||||||||||||||||||||||||
| 746 | 2 | ▶ | $self->throw("Node must be a Bio::Network::Node object, not a [". ref($node) . "].") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 747 | unless ($node->isa("Bio::Network::Node")); | ||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||
| 749 | 1 | $self->SUPER::add_edge(@nodes); | |||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||
| 752 | =head2 add_vertex | ||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||
| 754 | Name : add_vertex | ||||||||||||||||||||||||||||
| 755 | Purpose : Adds a node to a graph. | ||||||||||||||||||||||||||||
| 756 | Usage : $gr->add_vertex($n) | ||||||||||||||||||||||||||||
| 757 | Arguments : A Bio::Network::Node object | ||||||||||||||||||||||||||||
| 758 | Returns : | ||||||||||||||||||||||||||||
| 759 | Description : | ||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||
| 761 | =cut | ||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||
| 763 | 0 | ▶ | sub add_vertex { | ||||||||||||||||||||||||||
|
Subroutine
add_vertex: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 764 | 0 | my ($self,$node) = @_; | |||||||||||||||||||||||||||
| 765 | 0 | ▶ | $self->throw("Node must be a Node object, not a [" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 766 | . ref($node) . "]") unless ($node->isa("Bio::Network::Node")); | ||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||
| 768 | 0 | ▶ | if ($self->has_node($node)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 769 | # $self->warn("Graph already has node with id " . $node->display_id | ||||||||||||||||||||||||||||
| 770 | # . ", will not add it."); | ||||||||||||||||||||||||||||
| 771 | 0 | return; | |||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||
| 773 | 0 | $self->SUPER::add_vertex($node); | |||||||||||||||||||||||||||
| 774 | } | ||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||
| 776 | =head2 add_node | ||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||
| 778 | Name : add_node | ||||||||||||||||||||||||||||
| 779 | Purpose : Alias to add_vertex | ||||||||||||||||||||||||||||
| 780 | Usage : $gr->add_node($node) | ||||||||||||||||||||||||||||
| 781 | Arguments : A Bio::Network::Node object | ||||||||||||||||||||||||||||
| 782 | Returns : | ||||||||||||||||||||||||||||
| 783 | Description : | ||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||
| 785 | =cut | ||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||
| 787 | 0 | ▶ | sub add_node { | ||||||||||||||||||||||||||
|
Subroutine
add_node: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 788 | 0 | my ($self,$node) = @_; | |||||||||||||||||||||||||||
| 789 | 0 | $self->add_vertex($node); | |||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||
| 792 | =head2 clustering_coefficient | ||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||
| 794 | Name : clustering_coefficient | ||||||||||||||||||||||||||||
| 795 | Purpose : Determines the clustering coefficient of a node, a number | ||||||||||||||||||||||||||||
| 796 | in range 0-1 indicating the extent to which the neighbors of | ||||||||||||||||||||||||||||
| 797 | a node are interconnnected. | ||||||||||||||||||||||||||||
| 798 | Arguments : A Node or a text identifier | ||||||||||||||||||||||||||||
| 799 | Returns : The clustering coefficient. 0 is a valid result. | ||||||||||||||||||||||||||||
| 800 | If the CC is not calculable ( if the node has <2 neighbors), | ||||||||||||||||||||||||||||
| 801 | returns -1. | ||||||||||||||||||||||||||||
| 802 | Usage : my $node = $gr->get_nodes_by_id('P12345'); | ||||||||||||||||||||||||||||
| 803 | my $cc = $gr->clustering_coefficient($node); | ||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||
| 805 | =cut | ||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||
| 807 | 0 | ▶ | sub clustering_coefficient { | ||||||||||||||||||||||||||
|
Subroutine
clustering_coefficient: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 808 | 0 | my ($self,$node) = @_; | |||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||
| 810 | 0 | ▶ | $self->throw("[$node] is an incorrect parameter, not present in the graph") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 811 | unless defined($node); | ||||||||||||||||||||||||||||
| 812 | 0 | ▶ | $self->throw("[$node] is an incorrect parameter, not present in the graph") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 813 | unless ($node->isa("Bio::Network::Node")); | ||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||
| 815 | 0 | my @n = $self->neighbors($node); | |||||||||||||||||||||||||||
| 816 | 0 | my $n_count = scalar @n; | |||||||||||||||||||||||||||
| 817 | 0 | my $c = 0; | |||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||
| 819 | ## calculate cc if we can | ||||||||||||||||||||||||||||
| 820 | 0 | ▶ | if ($n_count >= 2){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 821 | 0 | ▶ | for (my $i = 0; $i <= $#n; $i++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 822 | 0 | ▶ | for (my $j = $i+1; $j <= $#n; $j++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 823 | 0 | ▶ | if ($self->has_edge($n[$i], $n[$j])){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 824 | 0 | $c++; | |||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||
| 828 | 0 | $c = 2 * $c / ($n_count *($n_count - 1)); | |||||||||||||||||||||||||||
| 829 | 0 | return $c; # can be 0 if unconnected. | |||||||||||||||||||||||||||
| 830 | }else{ | ||||||||||||||||||||||||||||
| 831 | 0 | return -1; # if value is not calculable | |||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||
| 835 | =head2 remove_nodes | ||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||
| 837 | Name : remove_nodes | ||||||||||||||||||||||||||||
| 838 | Purpose : Alias to Graph::delete_vertices | ||||||||||||||||||||||||||||
| 839 | Usage : $graph2 = $graph1->remove_nodes($node); | ||||||||||||||||||||||||||||
| 840 | Arguments : A single Node object or a list of Node objects | ||||||||||||||||||||||||||||
| 841 | Returns : A Graph with the given nodes deleted | ||||||||||||||||||||||||||||
| 842 | Notes : | ||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||
| 844 | =cut | ||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||
| 846 | 0 | ▶ | sub remove_nodes { | ||||||||||||||||||||||||||
|
Subroutine
remove_nodes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 847 | 0 | my ($self,@nodes) = @_; | |||||||||||||||||||||||||||
| 848 | 0 | my $g = $self->SUPER::delete_vertices(@nodes); | |||||||||||||||||||||||||||
| 849 | 0 | $g; | |||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||
| 852 | =head2 get_random_edge | ||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||
| 854 | Name : get_random_edge | ||||||||||||||||||||||||||||
| 855 | Purpose : Alias to Graph::random_edge | ||||||||||||||||||||||||||||
| 856 | Usage : $edge = $graph1->get_random_edge; | ||||||||||||||||||||||||||||
| 857 | Arguments : | ||||||||||||||||||||||||||||
| 858 | Returns : An Edge object | ||||||||||||||||||||||||||||
| 859 | Notes : | ||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||
| 861 | =cut | ||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||
| 863 | 0 | ▶ | sub get_random_edge { | ||||||||||||||||||||||||||
|
Subroutine
get_random_edge: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 864 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 865 | 0 | my $e = $self->random_edge; | |||||||||||||||||||||||||||
| 866 | 0 | $e; | |||||||||||||||||||||||||||
| 867 | } | ||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||
| 869 | =head2 get_random_node | ||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||
| 871 | Name : get_random_node | ||||||||||||||||||||||||||||
| 872 | Purpose : Alias to Graph::random_vertex | ||||||||||||||||||||||||||||
| 873 | Usage : $node = $graph1->get_random_node; | ||||||||||||||||||||||||||||
| 874 | Arguments : | ||||||||||||||||||||||||||||
| 875 | Returns : A Node object | ||||||||||||||||||||||||||||
| 876 | Notes : | ||||||||||||||||||||||||||||
| 877 | |||||||||||||||||||||||||||||
| 878 | =cut | ||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||
| 880 | 0 | ▶ | sub get_random_node { | ||||||||||||||||||||||||||
|
Subroutine
get_random_node: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 881 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 882 | 0 | my $n = $self->random_vertex; | |||||||||||||||||||||||||||
| 883 | 0 | $n; | |||||||||||||||||||||||||||
| 884 | } | ||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||
| 886 | =head2 is_forest | ||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||
| 888 | Name : is_forest | ||||||||||||||||||||||||||||
| 889 | Purpose : Determine if a graph is a forest (2 or more trees) | ||||||||||||||||||||||||||||
| 890 | Usage : if ($gr->is_forest){ ..... } | ||||||||||||||||||||||||||||
| 891 | Arguments : none | ||||||||||||||||||||||||||||
| 892 | Returns : 1 or "" | ||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||
| 894 | =cut | ||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||
| 896 | 0 | ▶ | sub is_forest { | ||||||||||||||||||||||||||
|
Subroutine
is_forest: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 897 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 898 | 0 | ▶ | return 1 if (!$self->is_connected && !$self->is_cyclic); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->is_connected or $self->is_cyclic
MC/DC0%0/2
$self->is_connected or $self->is_cyclic
$self->is_connected
$self->is_cyclic
Truth table0%0/3
A or B
A= $self->is_connectedB= $self->is_cyclic
| |||||||||||||||||||||||||||||
| 899 | 0 | return ""; | |||||||||||||||||||||||||||
| 900 | } | ||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||
| 902 | =head2 is_tree | ||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||
| 904 | Name : is_tree | ||||||||||||||||||||||||||||
| 905 | Purpose : Determine if the graph is a tree | ||||||||||||||||||||||||||||
| 906 | Usage : if ($gr->is_tree){ ..... } | ||||||||||||||||||||||||||||
| 907 | Arguments : None | ||||||||||||||||||||||||||||
| 908 | Returns : 1 or "" | ||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||
| 910 | =cut | ||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||
| 912 | 0 | ▶ | sub is_tree { | ||||||||||||||||||||||||||
|
Subroutine
is_tree: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 913 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 914 | 0 | ▶ | return 1 if ($self->is_connected && !$self->is_cyclic); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->is_connected and not $self->is_cyclic
MC/DC0%0/2
$self->is_connected and not $self->is_cyclic
$self->is_connected
not $self->is_cyclic
Truth table0%0/3
A and not(B)
A= $self->is_connectedB= not $self->is_cyclic
| |||||||||||||||||||||||||||||
| 915 | 0 | return ""; | |||||||||||||||||||||||||||
| 916 | } | ||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||
| 918 | =head2 is_empty | ||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||
| 920 | Name : is_empty | ||||||||||||||||||||||||||||
| 921 | Purpose : Determine if graph has no nodes | ||||||||||||||||||||||||||||
| 922 | Usage : if ($gr->is_empty){ ..... } | ||||||||||||||||||||||||||||
| 923 | Arguments : None | ||||||||||||||||||||||||||||
| 924 | Returns : 1 or "" | ||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||
| 926 | =cut | ||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||
| 928 | 0 | ▶ | sub is_empty { | ||||||||||||||||||||||||||
|
Subroutine
is_empty: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 929 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 930 | 0 | my @nodes = $self->vertices; | |||||||||||||||||||||||||||
| 931 | 0 | ▶ | return 1 if (scalar @nodes == 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 932 | 0 | return ""; | |||||||||||||||||||||||||||
| 933 | } | ||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||
| 935 | 0 | ▶ | sub unconnected_nodes { | ||||||||||||||||||||||||||
|
Subroutine
unconnected_nodes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 936 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 937 | 0 | return $self->SUPER::isolated_vertices; | |||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||
| 940 | =head2 articulation_points | ||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||
| 942 | Name : articulation_points | ||||||||||||||||||||||||||||
| 943 | Purpose : Find nodes in a graph that if removed will fragment | ||||||||||||||||||||||||||||
| 944 | the graph into sub-graphs. | ||||||||||||||||||||||||||||
| 945 | Usage : my @nodes = $gr->articulation_points | ||||||||||||||||||||||||||||
| 946 | or | ||||||||||||||||||||||||||||
| 947 | my $count = $gr->articulation_points | ||||||||||||||||||||||||||||
| 948 | Arguments : None | ||||||||||||||||||||||||||||
| 949 | Returns : An array or a count of the array of nodes that will fragment | ||||||||||||||||||||||||||||
| 950 | the graph if deleted. | ||||||||||||||||||||||||||||
| 951 | Notes : This method is currently broken due to bugs in Graph v. .69 | ||||||||||||||||||||||||||||
| 952 | and later | ||||||||||||||||||||||||||||
| 953 | |||||||||||||||||||||||||||||
| 954 | =cut | ||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||
| 956 | 0 | ▶ | sub articulation_points { | ||||||||||||||||||||||||||
|
Subroutine
articulation_points: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 957 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 958 | 0 | my @nodes = $self->SUPER::articulation_points; | |||||||||||||||||||||||||||
| 959 | 0 | ▶ | wantarray ? @nodes : scalar @nodes; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 960 | } | ||||||||||||||||||||||||||||
| 961 | |||||||||||||||||||||||||||||
| 962 | =head2 is_articulation_point | ||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||
| 964 | Name : is_articulation_point | ||||||||||||||||||||||||||||
| 965 | Purpose : Determine if a given node is an articulation point or not. | ||||||||||||||||||||||||||||
| 966 | Usage : if ($gr->is_articulation_point($node)) {....} | ||||||||||||||||||||||||||||
| 967 | Arguments : A node (Sequence object) | ||||||||||||||||||||||||||||
| 968 | Returns : 1 if node is an articulation point, 0 if it is not | ||||||||||||||||||||||||||||
| 969 | Notes : This method is currently broken due to bugs in Graph v. .69 | ||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||
| 971 | =cut | ||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||
| 973 | 0 | ▶ | sub is_articulation_point { | ||||||||||||||||||||||||||
|
Subroutine
is_articulation_point: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 974 | 0 | my ($self,$node) = @_; | |||||||||||||||||||||||||||
| 975 | |||||||||||||||||||||||||||||
| 976 | 0 | ▶ | $self->throw("$node is an incorrect parameter, not present in the graph") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 977 | unless ( $node->isa("Bio::Network::Node") ); | ||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||
| 979 | 0 | my @artic_points = $self->articulation_points(); | |||||||||||||||||||||||||||
| 980 | 0 | ▶ | grep /$node/,@artic_points ? return 1 : return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 981 | } | ||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||
| 983 | =head2 nodes | ||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||
| 985 | Name : nodes | ||||||||||||||||||||||||||||
| 986 | Purpose : Alias to Graph::vertices() | ||||||||||||||||||||||||||||
| 987 | Arguments: | ||||||||||||||||||||||||||||
| 988 | Returns : An integer | ||||||||||||||||||||||||||||
| 989 | Usage : my $count = $graph->nodes; | ||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||
| 991 | =cut | ||||||||||||||||||||||||||||
| 992 | |||||||||||||||||||||||||||||
| 993 | 0 | ▶ | sub nodes { | ||||||||||||||||||||||||||
|
Subroutine
nodes: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 994 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 995 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 996 | 0 | my @ns = $self->vertices; | |||||||||||||||||||||||||||
| 997 | 0 | return @ns; | |||||||||||||||||||||||||||
| 998 | } else { | ||||||||||||||||||||||||||||
| 999 | 0 | return scalar $self->vertices; | |||||||||||||||||||||||||||
| 1000 | } | ||||||||||||||||||||||||||||
| 1001 | } | ||||||||||||||||||||||||||||
| 1002 | |||||||||||||||||||||||||||||
| 1003 | =head2 has_node | ||||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||
| 1005 | Name : has_node | ||||||||||||||||||||||||||||
| 1006 | Purpose : Alias to Graph::has_vertex | ||||||||||||||||||||||||||||
| 1007 | Arguments: | ||||||||||||||||||||||||||||
| 1008 | Returns : True if the node exists | ||||||||||||||||||||||||||||
| 1009 | Usage : if ( $graph->has_node($node) ){ ... } | ||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||
| 1011 | =cut | ||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||
| 1013 | 0 | ▶ | sub has_node { | ||||||||||||||||||||||||||
|
Subroutine
has_node: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1014 | 0 | my ($self,$node) = @_; | |||||||||||||||||||||||||||
| 1015 | 0 | return $self->has_vertex($node); | |||||||||||||||||||||||||||
| 1016 | } | ||||||||||||||||||||||||||||
| 1017 | |||||||||||||||||||||||||||||
| 1018 | |||||||||||||||||||||||||||||
| 1019 | =head2 interactions | ||||||||||||||||||||||||||||
| 1020 | |||||||||||||||||||||||||||||
| 1021 | Name : interactions | ||||||||||||||||||||||||||||
| 1022 | Purpose : Count the total number of Interactions in the network (an Edge can | ||||||||||||||||||||||||||||
| 1023 | have one or more Interactions) or retrieve all the Interactions in | ||||||||||||||||||||||||||||
| 1024 | the network as an array | ||||||||||||||||||||||||||||
| 1025 | Usage : my $count = $gr->interactions or | ||||||||||||||||||||||||||||
| 1026 | my @interx = $gr->interactions | ||||||||||||||||||||||||||||
| 1027 | Arguments: | ||||||||||||||||||||||||||||
| 1028 | Returns : A number or an array of Interactions | ||||||||||||||||||||||||||||
| 1029 | Notes : | ||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||
| 1031 | =cut | ||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||
| 1033 | 0 | ▶ | sub interactions { | ||||||||||||||||||||||||||
|
Subroutine
interactions: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 1034 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 1035 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1036 | 0 | my @interx; | |||||||||||||||||||||||||||
| 1037 | 0 | for my $id (keys %{$self->[$GRAPH_ARRAY_INDEX]->{'_interx_id_map'}}) { | |||||||||||||||||||||||||||
| 1038 | 0 | push @interx, $self->[$GRAPH_ARRAY_INDEX]->{'_interx_id_map'}->{$id}; | |||||||||||||||||||||||||||
| 1039 | } | ||||||||||||||||||||||||||||
| 1040 | 0 | return @interx; | |||||||||||||||||||||||||||
| 1041 | } else { | ||||||||||||||||||||||||||||
| 1042 | 0 | return scalar keys %{$self->[$GRAPH_ARRAY_INDEX]->{'_interx_id_map'}}; | |||||||||||||||||||||||||||
| 1043 | } | ||||||||||||||||||||||||||||
| 1044 | } | ||||||||||||||||||||||||||||
| 1045 | |||||||||||||||||||||||||||||
| 1046 | =head2 nodes_by_id | ||||||||||||||||||||||||||||
| 1047 | |||||||||||||||||||||||||||||
| 1048 | Name : nodes_by_id | ||||||||||||||||||||||||||||
| 1049 | Purpose : Alias to get_nodes_by_id | ||||||||||||||||||||||||||||
| 1050 | Notes : Deprecated | ||||||||||||||||||||||||||||
| 1051 | |||||||||||||||||||||||||||||
| 1052 | =cut | ||||||||||||||||||||||||||||
| 1053 | |||||||||||||||||||||||||||||
| 1054 | 0 | ▶ | sub nodes_by_id { | ||||||||||||||||||||||||||
|
Subroutine
nodes_by_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1055 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 1056 | 0 | my @ids = @_; | |||||||||||||||||||||||||||
| 1057 | 0 | return $self->get_nodes_by_id(@ids); | |||||||||||||||||||||||||||
| 1058 | } | ||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||
| 1060 | =head2 edge_count | ||||||||||||||||||||||||||||
| 1061 | |||||||||||||||||||||||||||||
| 1062 | Name : edge_count | ||||||||||||||||||||||||||||
| 1063 | Purpose : Alias to edges() | ||||||||||||||||||||||||||||
| 1064 | Notes : Deprecated, use edges() | ||||||||||||||||||||||||||||
| 1065 | |||||||||||||||||||||||||||||
| 1066 | =cut | ||||||||||||||||||||||||||||
| 1067 | |||||||||||||||||||||||||||||
| 1068 | 0 | ▶ | sub edge_count { | ||||||||||||||||||||||||||
|
Subroutine
edge_count: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1069 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 1070 | 0 | return scalar $self->edges; | |||||||||||||||||||||||||||
| 1071 | } | ||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||
| 1073 | =head2 neighbor_count | ||||||||||||||||||||||||||||
| 1074 | |||||||||||||||||||||||||||||
| 1075 | Name : neighbor_count | ||||||||||||||||||||||||||||
| 1076 | Purpose : Alias to Graph::neighbors | ||||||||||||||||||||||||||||
| 1077 | Usage : my $count = $gr->neighbor_count($node) | ||||||||||||||||||||||||||||
| 1078 | Arguments : A node | ||||||||||||||||||||||||||||
| 1079 | Returns : An integer | ||||||||||||||||||||||||||||
| 1080 | Notes : Deprecated | ||||||||||||||||||||||||||||
| 1081 | |||||||||||||||||||||||||||||
| 1082 | =cut | ||||||||||||||||||||||||||||
| 1083 | |||||||||||||||||||||||||||||
| 1084 | 0 | ▶ | sub neighbor_count{ | ||||||||||||||||||||||||||
|
Subroutine
neighbor_count: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1085 | 0 | my ($self,$node) = @_; | |||||||||||||||||||||||||||
| 1086 | 0 | return scalar $self->SUPER::neighbors($node); | |||||||||||||||||||||||||||
| 1087 | } | ||||||||||||||||||||||||||||
| 1088 | |||||||||||||||||||||||||||||
| 1089 | =head2 node_count | ||||||||||||||||||||||||||||
| 1090 | |||||||||||||||||||||||||||||
| 1091 | Name : node_count | ||||||||||||||||||||||||||||
| 1092 | Purpose : Alias to Graph::vertices() | ||||||||||||||||||||||||||||
| 1093 | Notes : Deprecated, use nodes() | ||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||
| 1095 | =cut | ||||||||||||||||||||||||||||
| 1096 | |||||||||||||||||||||||||||||
| 1097 | 0 | ▶ | sub node_count { | ||||||||||||||||||||||||||
|
Subroutine
node_count: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1098 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 1099 | 0 | return scalar $self->vertices; | |||||||||||||||||||||||||||
| 1100 | } | ||||||||||||||||||||||||||||
| 1101 | |||||||||||||||||||||||||||||
| 1102 | =head2 components | ||||||||||||||||||||||||||||
| 1103 | |||||||||||||||||||||||||||||
| 1104 | Name : components | ||||||||||||||||||||||||||||
| 1105 | Purpose : Alias to Graph::connected_components | ||||||||||||||||||||||||||||
| 1106 | Usage : my @components = $gr->components | ||||||||||||||||||||||||||||
| 1107 | Arguments : | ||||||||||||||||||||||||||||
| 1108 | Returns : | ||||||||||||||||||||||||||||
| 1109 | Notes : Deprecated | ||||||||||||||||||||||||||||
| 1110 | |||||||||||||||||||||||||||||
| 1111 | =cut | ||||||||||||||||||||||||||||
| 1112 | |||||||||||||||||||||||||||||
| 1113 | 0 | ▶ | sub components { | ||||||||||||||||||||||||||
|
Subroutine
components: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1114 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 1115 | 0 | return $self->connected_components; | |||||||||||||||||||||||||||
| 1116 | } | ||||||||||||||||||||||||||||
| 1117 | |||||||||||||||||||||||||||||
| 1118 | =head2 unconnected_nodes | ||||||||||||||||||||||||||||
| 1119 | |||||||||||||||||||||||||||||
| 1120 | Name : unconnected_nodes | ||||||||||||||||||||||||||||
| 1121 | Purpose : Alias to Graph::isolated_vertices | ||||||||||||||||||||||||||||
| 1122 | Arguments : None | ||||||||||||||||||||||||||||
| 1123 | Returns : An array of unconnected nodes | ||||||||||||||||||||||||||||
| 1124 | Notes : Deprecated | ||||||||||||||||||||||||||||
| 1125 | |||||||||||||||||||||||||||||
| 1126 | =cut | ||||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||
| 1128 | =head2 _all_pairs | ||||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||
| 1130 | Name : _all_pairs | ||||||||||||||||||||||||||||
| 1131 | Purpose : Find unique set of all pairwise combinations | ||||||||||||||||||||||||||||
| 1132 | Usage : my @pairs = $self->_all_pairs(@arr) | ||||||||||||||||||||||||||||
| 1133 | Arguments : An array | ||||||||||||||||||||||||||||
| 1134 | Returns : An array of array references, each array in the 2nd dimension | ||||||||||||||||||||||||||||
| 1135 | is a 2-element array | ||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||
| 1137 | =cut | ||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||
| 1139 | 0 | ▶ | sub _all_pairs { | ||||||||||||||||||||||||||
|
Subroutine
_all_pairs: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 1140 | 0 | my ($self,@arr) = @_; | |||||||||||||||||||||||||||
| 1141 | 0 | my @pairs = (); | |||||||||||||||||||||||||||
| 1142 | 0 | ▶ | $self->throw("Must pass an array with at least 2 elements to _all_pairs()") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1143 | unless ($#arr > 0); | ||||||||||||||||||||||||||||
| 1144 | 0 | ▶ | for (my $x = 0 ; $x < $#arr ; $x++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1145 | 0 | ▶ | for (my $y = $x ; $y < $#arr ; $y++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1146 | 0 | push @pairs, [($arr[$x],$arr[($y + 1)])]; | |||||||||||||||||||||||||||
| 1147 | } | ||||||||||||||||||||||||||||
| 1148 | } | ||||||||||||||||||||||||||||
| 1149 | 0 | @pairs; | |||||||||||||||||||||||||||
| 1150 | } | ||||||||||||||||||||||||||||
| 1151 | |||||||||||||||||||||||||||||
| 1152 | =head2 _ids | ||||||||||||||||||||||||||||
| 1153 | |||||||||||||||||||||||||||||
| 1154 | Name : _ids | ||||||||||||||||||||||||||||
| 1155 | Purpose : | ||||||||||||||||||||||||||||
| 1156 | Usage : | ||||||||||||||||||||||||||||
| 1157 | Arguments : | ||||||||||||||||||||||||||||
| 1158 | Returns : | ||||||||||||||||||||||||||||
| 1159 | |||||||||||||||||||||||||||||
| 1160 | =cut | ||||||||||||||||||||||||||||
| 1161 | |||||||||||||||||||||||||||||
| 1162 | 1 | ▶ | sub _ids { | ||||||||||||||||||||||||||
|
Subroutine
_ids: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||
| 1163 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 1164 | 1 | my @refs; | |||||||||||||||||||||||||||
| 1165 | 1 | ▶ | while (my $id = shift) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1166 | 1 | push @refs, $self->[$GRAPH_ARRAY_INDEX]->{'_id_map'}->{$id}; | |||||||||||||||||||||||||||
| 1167 | } | ||||||||||||||||||||||||||||
| 1168 | 0 | return @refs; | |||||||||||||||||||||||||||
| 1169 | } | ||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||
| 1171 | 3 | 1; | |||||||||||||||||||||||||||
| 1172 | |||||||||||||||||||||||||||||
| 1173 | __END__ | ||||||||||||||||||||||||||||