/usr/share/perl5/Circos/SVG.pm is in circos 0.64-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | package Circos::SVG;
=pod
=head1 NAME
Circos::SVG - utility routines for SVG in Circos
=head1 SYNOPSIS
This module is not meant to be used directly.
=head1 DESCRIPTION
Circos is an application for the generation of publication-quality,
circularly composited renditions of genomic data and related
annotations.
Circos is particularly suited for visualizing alignments, conservation
and intra and inter-chromosomal relationships. However, Circos can be
used to plot any kind of 2D data in a circular layout - its use is not
limited to genomics. Circos' use of lines to relate position pairs
(ribbons add a thickness parameter to each end) is effective to
display relationships between objects or positions on one or more
scales.
All documentation is in the form of tutorials at L<http://www.circos.ca>.
=cut
# -------------------------------------------------------------------
use strict;
use warnings;
use base 'Exporter';
our @EXPORT = qw(
style_string
style
);
use Carp qw( carp confess croak );
use FindBin;
use GD::Image;
use Params::Validate qw(:all);
use lib "$FindBin::RealBin";
use lib "$FindBin::RealBin/../lib";
use lib "$FindBin::RealBin/lib";
use Circos::Configuration;
use Circos::Colors;
use Circos::Constants;
use Circos::Debug;
use Circos::Error;
use Circos::Utils;
use Circos::Font;
use Circos::Geometry;
use Circos::Text;
use Circos::Unit;
use Circos::Image qw(!draw_line);
use Memoize;
our $default_color = "black";
our $default_font_name = "Arial";
our $default_font = "default";
our $default_font_color = "black";
for my $f ( qw ( ) ) {
memoize($f);
}
sub draw_polygon {
my %params;
if ( fetch_conf("debug_validate") ) {
%params = validate(@_,{
polygon => 1,
thickness => 0,
color => 0,
fill_color => 0,
linecap => 0,
});
} else {
%params = @_;
$params{"stroke-linecap"} ||= "round";
}
my $pts = join( $SPACE, map { join( $COMMA, @$_ ) } $params{polygon}->vertices );
my $style = style(thickness => $params{thickness},
color => $params{color},
linecap => $params{linecap},
fill_color=> $params{fill_color});
my $svg = sprintf(q{<polygon points="%s" style="%s"/>},$pts,$style);
Circos::printsvg($svg);
}
# Edited on the island of Capri :)
sub draw_circle {
my %params;
if ( fetch_conf("debug_validate") ) {
%params = validate(@_,{
point => 1,
radius => 1,
color => 0,
stroke_color => 0,
stroke_thickness => 0,
});
} else {
%params = @_;
}
my $style = style(thickness => $params{stroke_thickness},
color => $params{stroke_color},
fill_color=> $params{color});
my $fmt = "'%.1f'";
my $svg = sprintf(qq{<circle cx=$fmt cy=$fmt r=$fmt style="%s"/>},
@{$params{point}},$params{radius},$style);
Circos::printsvg($svg);
}
################################################################
# Draw a line
sub draw_line {
my %params;
if ( fetch_conf("debug_validate") ) {
%params = validate(@_,{
points => { type => ARRAYREF },
color => { default => fetch_conf("default_color") || $default_color },
thickness => { default => 1 },
"stroke-linecap" => { default => "round" },
});
} else {
%params = @_;
$params{color} ||= fetch_conf("default_color") || $default_color;
$params{"stroke-linecap"} ||= "round";
$params{thickness} ||= 1;
}
if (@{$params{points}} != 4) {
fatal_error("argument","list_size",current_function(),current_package(),4,int(@{$params{points}}));
}
my $fmt = "'%.1f'";
my $style = style(thickness => $params{thickness},
color => $params{color},
fill_color => undef,
linecap => $params{"stroke-linecap"});
my $svg = sprintf(qq{<line x1=$fmt y1=$fmt x2=$fmt y2=$fmt style="%s"/>},@{$params{points}},$style);
printdebug_group("svg","line",@{$params{points}},$params{color},$params{thickness},$style);
Circos::printsvg($svg);
}
sub draw_text {
my %params;
my @args = remove_undef_keys(@_);
if (fetch_conf("debug_validate")) {
%params = validate( @args,
{
text => 1,
font => { default => fetch_conf("default_font") || $default_font },
size => 1,
color => { default => fetch_conf("default_font_color") || $default_font_color },
angle => 1,
radius => 1,
angle_offset => { default => 0 },
is_parallel => { default => 0 },
is_rotated => { default => 1 },
rotation => { default => 0 },
x_offset => { default => 0 },
y_offset => { default => 0 },
guides => { default => 0 },
mapoptions => 0,
});
} else {
%params = @args;
$params{color} ||= fetch_conf("default_font_color") || $default_font_color;
$params{is_parallel} ||= 0;
$params{x_offset} ||= 0;
$params{y_offset} ||= 0;
}
my ( $w, $h ) = get_label_size( text=>$params{text},
size=>$params{size},
font_file=>get_font_file_from_key($params{font}));
my $font_name = get_font_name_from_key($params{font});
my $angle_quadrant = angle_quadrant($params{angle});
my $text_angle = text_angle_2( angle => $params{angle},
is_rotated => $params{is_rotated},
is_parallel => $params{is_parallel} );
my $radius_offset = 0;
# adjust radius
if ($params{is_parallel} ) {
$params{angle_offset} = 0;
if ($params{is_rotated}) {
if ($angle_quadrant == 1 || $angle_quadrant == 2) {
$radius_offset = $h;
}
}
}
# adjust anchor
my $anchor;
if ($params{is_parallel}) {
$anchor = "middle";
} else {
if ($params{is_rotated}) {
if ($angle_quadrant <= 1) {
$anchor = "start";
} else {
$anchor = "end";
}
} else {
$anchor = "start";
}
}
my ($x,$y) = getxypos( $params{angle} + $params{angle_offset},
$params{radius} + $radius_offset );
my $svg_text = $params{text};
$svg_text =~ s/&/&/g;
my $style = style(thickness => $params{thickness},
fill_color => $params{color},
textanchor => $anchor);
my $svg = sprintf( qq{<text x="%.1f" y="%.1f" font-size="%.1fpx" font-family="%s" style="%s" transform="rotate(%.1f,%.1f,%.1f)">%s</text>},
$x,$y,
$CONF{svg_font_scale} * $params{size},
$font_name,
$style,
360 - $text_angle,
$x,$y,
defined $svg_text ? $svg_text : $EMPTY_STR,
);
Circos::printsvg($svg);
}
sub draw_slice {
$CONF{debug_validate} && validate(@_, {
image => { isa => 'GD::Image' },
start => 1,
start_offset => 0,
end_offset => 0,
end => 1,
chr => 1,
radius_from => 1,
radius_to => 0,
radius_to_y0 => 0,
radius_to_y1 => 0,
edgecolor => 1,
edgestroke => 1,
fillcolor => 0,
ideogram => 0,
mapoptions => { type => HASHREF, optional => 1 },
guides => 0,
start_a => 1,
end_a => 1,
angle_orientation => 1,
});
my %params = @_;
my ($start_a,$end_a,$angle_orientation) = @params{qw(start_a end_a angle_orientation)};
my $style = style(thickness => $params{edgestroke},
color => $params{edgecolor},
linecap => $params{linecap} || "round",
fill_color => $params{fillcolor});
my $svg;
if (defined $params{radius_to} &&
$params{radius_from} == $params{radius_to} ) {
my $end_a_mod = $end_a;
if ( abs( $end_a - $start_a ) > 359.99 || $start_a == $end_a ) {
$end_a_mod -= 0.01;
}
#
# when the start/end radius is the same, there can be no
# fill because the slice is 0-width
#
$svg = sprintf(
qq{<path d="M %.2f,%.2f A%.2f,%.2f %.2f %d,%d %.2f,%.2f" style="%s"/>},
getxypos( $start_a, $params{radius_from} ),
$params{radius_from},
$params{radius_from},
0,
abs( $start_a - $end_a_mod ) > 180,
1,
getxypos( $end_a_mod, $params{radius_from} ),
$style,
);
} elsif ( $end_a == $start_a ) {
$svg = sprintf(
qq{<path d="M %.2f,%.2f L %.2f,%.2f " style="%s"/>},
getxypos( $start_a, $params{radius_from} ),
getxypos( $end_a, $params{radius_to} ),
$style,
);
} else {
my $large_arc = abs( $start_a - $end_a ) > 180;
my $sweep = $end_a > $start_a ? 1 : 0;
my $end_a_mod = $end_a;
if ( abs( $end_a - $start_a ) > 359.99 || $start_a == $end_a ) {
$end_a_mod -= 0.01;
}
if(defined $params{radius_to_y0} && defined $params{radius_to_y1}) {
$svg = sprintf(
qq{<path d="M%.3f,%.3f A%.3f,%.3f %.3f %d,%d %.3f,%.3f L%.3f,%.3f L%.3f,%.3f Z" style="%s"/>},
# move to (M)
getxypos( $start_a, $params{radius_from} ),
# elliptical arc (A)
$params{radius_from}, $params{radius_from}, # rx ry
40, # x axis rotation
$large_arc, $sweep, # large arc flag, sweep flag
getxypos( $end_a_mod, $params{radius_from} ), # end x,y
getxypos( $end_a_mod, $params{radius_to_y1} ),
getxypos( $start_a, $params{radius_to_y0} ),
#getxypos( $start_a, $params{radius_to} ),
$style,
);
} else {
$svg = sprintf(
qq{<path d="M%.3f,%.3f A%.3f,%.3f %.3f %d,%d %.3f,%.3f L%.3f,%.3f A%.3f,%.3f %.3f %d,%d %.3f,%.3f Z" style="%s"/>},
# move to (M)
getxypos( $start_a, $params{radius_from} ),
# elliptical arc (A)
$params{radius_from}, $params{radius_from}, # rx ry
40, # x axis rotation
$large_arc, $sweep, # large arc flag, sweep flag
getxypos( $end_a_mod, $params{radius_from} ), # end x,y
getxypos( $end_a_mod, $params{radius_to} ),
$params{radius_to}, $params{radius_to},
0,
$large_arc, !$sweep,
getxypos( $start_a, $params{radius_to} ),
$style,
);
}
}
Circos::printsvg($svg);
}
################################################################
# Given a hash, generate a style string
#
# key1=value1; key2=value2; key3=value3; ...
sub style_string {
my %hash = @_;
my $style = join(";",map { sprintf("%s:%s", $_, $hash{$_}) } grep(defined $hash{$_}, keys %hash));
return $style;
}
################################################################
# Generate style for
#
# thickness, color, linecap, fill_color, text-anchor
sub style {
my %params = @_;
my @style;
if (my $an = $params{textanchor}) {
push @style, sprintf("text-anchor:%s",$an);
}
if (my $st = $params{thickness}) {
push @style, sprintf("stroke-width:%.1f", $st);
my $sc = $params{color} || fetch_conf("default_color");
push @style, sprintf("stroke:rgb(%d,%d,%d)", rgb_color($sc));
if ( (my $op = rgb_color_opacity( $params{color} )) < 1 ) {
push @style, sprintf("stroke-opacity:%.2f",$op);
}
}
if (my $lc = $params{linecap}) {
push @style, sprintf("stroke-linecap:%s",$lc);
}
if (my $fc = $params{fill_color}) {
push @style, sprintf("fill:rgb(%d,%d,%d)", rgb_color($fc));
if ( (my $op = rgb_color_opacity( $params{fill_color} )) < 1 ) {
push @style, sprintf("fill-opacity:%.2f",$op);
}
} else {
push @style, "fill:none";
}
return join($SEMICOLON,@style) . $SEMICOLON;
}
sub tag {
my $tag = shift;
my $tag_data = {
xml=> q|<?xml version="1.0" encoding="utf-8" standalone="no"?>|,
doctype=> q|<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">|,
};
if(! $tag_data->{$tag}) {
fatal_error("svg","no_such_tag",$tag);
} else {
return $tag_data->{$tag};
}
}
1;
|