File Coverage

blib/lib/Graph/Writer/Cytoscape.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Graph::Writer::Cytoscape;
2              
3 1     1   43227 use warnings;
  1         3  
  1         37  
4 1     1   6 use strict;
  1         2  
  1         37  
5              
6 1     1   1005 use parent 'Graph::Writer';
  1         413  
  1         6  
7              
8             =head1 NAME
9              
10             Graph::Writer::Cytoscape - Write a directed graph out as Cytoscape competible input file
11              
12             =head1 VERSION
13              
14             Version 1.00
15              
16             =cut
17              
18             our $VERSION = '1.00';
19              
20              
21             =head1 SYNOPSIS
22              
23             Quick summary of what the module does.
24              
25             Perhaps a little code snippet.
26              
27             use Graph;
28             use Graph::Writer::Cytoscape;
29            
30             $graph = Graph->new();
31             # add edges and nodes to the graph
32            
33             $writer = Graph::Writer::Cytoscape->new();
34             $writer->write_graph($graph, 'mygraph');
35              
36             =head1 SUBROUTINES/METHODS
37              
38             =head2 _write_graph
39              
40             =cut
41              
42             sub _write_graph
43             {
44             my $self = shift;
45             my $graph = shift;
46             my $FILE = shift;
47            
48             my $v;
49             my $from;
50             my $to;
51             my $aref;
52             my $time = time;
53             my %titles;
54            
55            
56             #-------------------------------------------------------------------
57             # dump out vertices of the graph, including any attributes
58             #-------------------------------------------------------------------
59             foreach $v (sort $graph->vertices)
60             {
61             $aref = $graph->get_vertex_attributes($v);
62              
63             if (keys(%{ $aref }) > 0)
64             {
65              
66             foreach my $attr (keys %{ $aref })
67             {
68             open(OUT_NODE, ">>",$time."_NODE_".$attr.".txt") or die("No output!\n");
69            
70             if (!$titles{$attr})
71             {
72             print OUT_NODE $attr,"Attribute\n";
73             $titles{$attr} = 1;
74             }
75            
76             print OUT_NODE $v," = ",$aref->{$attr},"\n";
77             close(OUT_NODE);
78             }
79             }
80             else
81             {
82             #Do nothing if it is empty
83             }
84             }
85            
86             %titles = (); #clean the hash
87            
88             #-------------------------------------------------------------------
89             # dump out edges of the graph, including any attributes
90             #-------------------------------------------------------------------
91             foreach my $edge (sort _by_vertex $graph->edges)
92             {
93             ($from, $to) = @$edge;
94             $aref = $graph->get_edge_attributes($from, $to);
95             if (keys(%{ $aref }) > 0)
96             {
97            
98             foreach my $attr (keys %{ $aref })
99             {
100             open(OUT_EDGE, ">>",$time."_EDGE_".$attr.".txt") or die("No output!\n");
101             if (!$titles{$attr})
102             {
103             print OUT_EDGE $attr,"\n";
104             $titles{$attr} = 1;
105             }
106             print OUT_EDGE $from," (pp) ",$to," = ", $aref->{$attr},"\n";
107            
108             open(OUT_NETWORK, ">>",$time."_NETWORK.sif") or die("No output!\n");
109             print OUT_NETWORK $from," pp ",$to,"\n";
110             close(OUT_NETWORK);
111            
112             close(OUT_EDGE);
113             }
114             }
115             else
116             {
117             #Do nothing if it is empty
118             }
119             }
120            
121             return 1;
122             }
123              
124             sub _by_vertex
125             {
126             return $a->[0].$a->[1] cmp $b->[0].$b->[1];
127             }
128              
129             =head1 AUTHOR
130              
131             Haktan Suren, C<< >>
132              
133             =head1 BUGS
134              
135             Please report any bugs or feature requests to C, or through
136             the web interface at L. I will be notified, and then you'll
137             automatically be notified of progress on your bug as I make changes.
138              
139             =head1 DESCRIPTION
140              
141             B is a class for writing out a directed graph
142             as Cytoscape competible input file.
143              
144             The graph must be an instance of the Graph class, which is
145             actually a set of classes developed by Jarkko Hietaniemi.
146              
147             The Cytoscape format is designed to support Cytoscape program, It simply
148             generates the necessary files for Cytoscape. So, it allows you to use Graphviz
149             file in Cytoscape.
150              
151             The graph, nodes, and edges can all have attributes specified,
152             where an attribute is a (name,value) pair, with the value being scalar.
153              
154             =head1 SUPPORT
155              
156             You can find documentation for this module with the perldoc command.
157              
158             perldoc Graph::Writer::Cytoscape
159              
160              
161             You can also look for information at:
162              
163             =over 4
164              
165             =item * RT: CPAN's request tracker
166              
167             L
168              
169             =item * AnnoCPAN: Annotated CPAN documentation
170              
171             L
172              
173             =item * CPAN Ratings
174              
175             L
176              
177             =item * Search CPAN
178              
179             L
180              
181             =back
182              
183              
184             =head1 ACKNOWLEDGEMENTS
185              
186             All credits go to Neil Bowers for developing B class.
187              
188             =head1 LICENSE AND COPYRIGHT
189              
190             Copyright 2012 Haktan Suren.
191              
192             This program is free software; you can redistribute it and/or modify it
193             under the terms of either: the GNU General Public License as published
194             by the Free Software Foundation; or the Artistic License.
195              
196             See http://dev.perl.org/licenses/ for more information.
197              
198              
199             =cut
200              
201             1; # End of Graph::Writer::Cytoscape