File: DotLib.pm

package info (click to toggle)
sspace 2.1.1%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 6,792 kB
  • sloc: perl: 2,382; python: 374; makefile: 27; sh: 17
file content (238 lines) | stat: -rwxr-xr-x 4,696 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# $Id: DotLib.pm,v 1.3 2003/02/24 17:33:00 mpop Exp $
#
# DotLib.pm - set of procedures for generating .dot files
#

#  Copyright @ 2002, 2003, The Institute for Genomic Research (TIGR).  All
#  rights reserved.


=head1 Name

DotLib - library of routines for generating .dot files

=head1 Synopsis

    use DotLib;

=head1 Description

    A set of procedures used to create various .dot objects such as
file headers, file tails, components, nodes, edges, etc.

=cut

package DotLib;

use strict;


BEGIN {
    use Exporter ();
    use vars qw(@EXPORT @EXPORT_OK @ISA %EXPORT_TAGS);

    @ISA         = qw(Exporter);
    @EXPORT      = qw(&printHeader
                      &printFooter
		      &printNode
		      &printEdge
		      &startCluster
		      &endCluster
		      );
    %EXPORT_TAGS = ();
    @EXPORT_OK   = ();
}

our $VERSION = '1.0'; 
our $REVISION = '$Revision: 1.3 $ ';
our $VERSION_STRING = "$VERSION ($REVISION)";

use vars @EXPORT;
use vars @EXPORT_OK;

=over 4

=item B<my $ret = printHeader($file, $type);>

Prints a .dot header for the type of output specified in the $type variable.
Allowable types are "printer", "plotter".  If $type is undefined or not
passed, it generates a default header.  Returns 1 upon successful 
completion and 'undef' otherwise.

Example:

    my $err = printHeader(\*STDOUT, "plotter");

=cut

sub printHeader
{
    my $file = shift;
    my $type = shift;

    print $file "digraph ROOT {\n";
    print $file "  rankdir = LR\n";
    print $file "  orientation = landscape\n";
    print $file "  ranksep = 0.3\n";
    print $file "  nodesep = 0.3\n";
    print $file "  fontsize = 8\n";
    print $file "  margin = \".2,.2\"\n";
	
    if ($type eq "printer"){
	print $file "  ratio = auto\n";
	print $file "  page = \"8.5,11\"\n";
    } elsif ($type eq "plotter"){
	print $file "  ratio = auto\n";
	print $file "  page = \"36,48\"\n";
    }
    
    print $file "\n";

    return 1;
} # printHeader


=item B<my $ret = printFooter($file);>

Prints a .dot footer (currently just a closed brace).  Returns 1 upon
successful completion and 'undef' otherwise.

Example:

    my $err = printFooter(\*STDOUT);

=cut

sub printFooter
{
    my $file = shift;

    print $file "}\n";
    
    return 1;
} # printFooter


=item B<my $ret = printNode($file, $id, $label, $ori);>

Prints a "contig" node with the specified id, label, and orientation.
If orientation is 1 then the node is a forward facing arrow, otherwise
it is a backward facing arror. Returns 1 upon successful completion
and 'undef' otherwise.

Example:

    my $err = printNode(\*STDOUT, $node_id, "$node_id ($node_len)", 1);

=cut   

sub printNode
{
    my $file = shift;
    my $id = shift;
    my $label = shift;
    my $ori = shift;
    my $angle;
    
    $id =~ s/(\W)/_/g;

    if ($ori == 1){
	$angle = -90;
    } else {
	$angle = 90;
    }

    print $file "    $id [ label = \"$label\" height = 0.2, fontsize = 8, shape = \"house\", orientation = $angle ]\n";

    return 1;

} # printNode


=item B<my $ret = printEdge($file, $nodeA, $nodeB, $label, $style);>

Prints an edge between two nodes with the specified label.  The style can
be any of the GraphViz acceptable styles ("dotted", "solid", "dashed", 
"invis") or undefined in which case the default is used. Returns 1 upon
successful completion and 'undef' otherwise.

Example:

    my $err = printEdge(\*STDOUT, $nodeA, $nodeB, "A to B", "invis");

=cut   

sub printEdge
{
    my $file = shift;
    my $nodeA = shift;
    my $nodeB = shift;
    my $label = shift;
    my $instyle = shift;
    my $style;

    $nodeA =~ s/(\W)/_/g;
    $nodeB =~ s/(\W)/_/g;

    if (defined $instyle){
	$style = "style = \"" . $instyle . "\"";
	if ($instyle eq "invis"){
	    $style .= " color = \"white\" ";
	}
    }

    print $file "    $nodeA -> $nodeB [ label =\"$label\" fontsize = 8 $style ]\n";

    return 1;
} # printEdge

=item B<my $err = startCluster($file, $id, $label);>

Starts a cluster in the .dot output file with the given label and id.
Returns 1 upon successful completion and 'undef' otherwise.

Example:
    
    my $err = startCluster(\*STDOUT, $clust_id, "first cluster");

=cut

sub startCluster
{
    my $file = shift;
    my $id = shift;
    my $label = shift;

    $id =~ s/(\W)/_/g;

    print $file "  subgraph cluster_$id {\n";
    print $file "    label = \"$label\"\n";

    return 1;
} # startCluster

=item B<my $err = endCluster($file);>

Ends a cluster in the .dot output.  Returns 1 upon successful
completion and 'undef' otherwise.

Example: 

    my $err = endCluster(\*STDOUT);

=cut

sub endCluster
{
    my $file = shift;

    print $file "  }\n";
   
    return 1;
} # endCluster


1;