/usr/share/perl5/Circos/PNG.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 | package Circos::PNG;
=pod
=head1 NAME
Circos::PNG - PNG routines for PNG 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();
use Carp qw( carp confess croak );
use FindBin;
use GD;
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::Image qw(!draw_line);
use Circos::Utils;
use Memoize;
our $default_color = "black";
for my $f ( qw ( ) ) {
memoize($f);
}
################################################################
# Draw a line
sub draw_arc {
my %params;
if( fetch_conf("debug_validate") ) {
%params = validate(@_,{
point => { type => ARRAYREF },
width => 1,
height => 0,
angle_start => { default => 0 },
angle_end => { default => 360 },
stroke_color => 0,
stroke_thickness => 0,
color => 0,
});
} else {
%params = @_;
$params{angle_start} ||= 0;
$params{angle_end} ||= 360;
}
$params{height} ||= $params{width};
if(@{$params{point}} != 2) {
fatal_error("argument","list_size",current_function(),current_package(),2,int(@{$params{point}}));
}
printdebug_group("png","arc",@{$params{point}},@params{qw(width height angle_start angle_end)});
# first fill the arc
if(my $color = $params{color}) {
my $color_obj = aa_color($color,$IM,$COLORS);
$IM->filledArc(@{$params{point}},@params{qw(width height angle_start angle_end)},$color_obj);
}
# stroke the arc
stroke($params{stroke_thickness},$params{stroke_color},"arc",@{$params{point}},@params{qw(width height angle_start angle_end)});
}
sub draw_polygon {
my %params;
if( fetch_conf("debug_validate") ) {
%params = validate(@_,{
polygon => 1,
color => fetch_conf("default_color") || $default_color,
thickness => 0,
pattern => 0,
fill_color => 0,
});
} else {
%params = @_;
$params{color} ||= fetch_conf("default_color") || $default_color;
}
printdebug_group("png","polygon",map {@$_} $params{polygon}->vertices);
if($params{pattern}) {
my ($color_idx,$tile);
if ($params{fill_color} ) {
$tile = Circos::fetch_colored_fill_pattern($params{pattern},$params{fill_color});
} elsif ($params{pattern}) {
$tile = Circos::fetch_fill_pattern($params{pattern});
}
if (defined $tile) {
$IM->setTile($tile);
$IM->filledPolygon($params{polygon},gdTiled);
}
} elsif ($params{fill_color} && ref $params{polygon} eq "GD::Polygon") {
my $color_obj = aa_color( $params{fill_color}, $IM, $COLORS );
$IM->filledPolygon($params{polygon},$color_obj);
}
stroke($params{thickness},$params{color},"polydraw",$params{polygon});
}
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 },
});
} else {
%params = @_;
$params{color} ||= fetch_conf("default_color") || $default_color;
$params{thickness} ||= 1;
}
if(@{$params{points}} != 4) {
fatal_error("argument","list_size",current_function(),current_package(),4,int(@{$params{points}}));
}
printdebug_group("png","line",@{$params{points}},$params{color},$params{thickness});
stroke($params{thickness},$params{color},"line",@{$params{points}});
}
# -------------------------------------------------------------------
sub draw_bezier {
my %params;
if( fetch_conf("debug_validate") ) {
%params = validate(@_,{
points => { type => ARRAYREF },
color => { default => fetch_conf("default_color") || $default_color },
thickness => { default => 1 },
});
} else {
%params = @_;
$params{color} ||= fetch_conf("default_color") || $default_color;
$params{thickness} ||= 1;
}
if ( $params{thickness} > 100 ) {
fatal_error("links","too_thick",$params{thickness});
} elsif ( $params{thickness} < 1 ) {
fatal_error("links","too_thin",$params{thickness});
}
# In the current implementation of gd (2.0.35) antialiasing is
# incompatible with thick lines and transparency. Thus, antialiased lines
# are available only when thickness=1 and the color has no alpha channel.
printdebug_group("link","thickness",$params{thickness},"color",$params{color});
my $bezier_poly_line = GD::Polyline->new();
for my $point ( @{$params{points}} ) {
$bezier_poly_line->addPt(@$point);
}
stroke($params{thickness},$params{color},"polydraw",$bezier_poly_line);
}
# applies a stroke to a GD object drawn by function $fn
# added on island of Capri :)
sub stroke {
my ($st,$sc,$fn,@args) = @_;
return unless $st;
my $color_obj;
$sc ||= fetch_conf("default_color") || $default_color;
my ($b,$bc,$buse);
if(fetch_conf("anti_aliasing") && $st == 1 && rgb_color_opacity($sc) == 1) {
$IM->setAntiAliased(fetch_color($sc));
$color_obj = gdAntiAliased;
} else {
# When the element is thicker than round_brush_min_thickness, use a round brush instead
# of the default square one. This fixes jaggies on thick links.
$buse = fetch_conf("round_brush_use") && $st >= fetch_conf("round_brush_min_thickness");
if($buse) {
($b,$bc) = Circos::fetch_brush($st,$st,$sc);
$IM->setBrush($b);
} else {
$IM->setThickness($st) if $st > 1;
}
$color_obj = fetch_color($sc);
}
if($buse) {
$IM->$fn(@args,gdBrushed);
} else {
$IM->$fn(@args,$color_obj);
$IM->setThickness(1) if $st > 1;
}
}
1;
|