/usr/share/perl5/Circos/Division.pm is in circos 0.69.6+dfsg-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 | package Circos::Division;
=pod
=head1 NAME
Circos::Division - axis and tick spacing routines 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 Math::Round;
use List::MoreUtils qw(uniq);
use Params::Validate qw(:all);
use lib "$FindBin::RealBin";
use lib "$FindBin::RealBin/../lib";
use lib "$FindBin::RealBin/lib";
use Circos::Configuration;
use Circos::Constants;
use Circos::Debug;
use Circos::Error;
use Circos::Utils;
use Memoize;
for my $f ( qw ( ) ) {
memoize($f);
}
sub make_ranges {
my ($blocks,$param_path,$min,$max,$set) = @_;
return unless $blocks;
my $divisions;
if(! defined $min && ! defined $max) {
for my $block (make_list($blocks)) {
push @$divisions, {y0=>undef,
y1=>undef,
block=>$block};
}
return $divisions;
} else {
return unless defined $max && defined $min && defined $max;
for my $block (make_list($blocks)) {
my @pp = ($block, @$param_path);
next if hide(@pp);
my $ystart = parse_value(seek_parameter("y0",@pp),$min,$max);
my $yend = parse_value(seek_parameter("y1",@pp),$min,$max);
$ystart = $min if ! defined $ystart || $ystart < $min;
$yend = $max if ! defined $yend || $yend > $max;
push @{$divisions->{$yend-$ystart}{$ystart}}, {y0=>$ystart,
y1=>$yend,
block=>$block};
}
my $divisions_sorted = [];
for my $size (sort {$b <=> $a} keys %$divisions) {
for my $y0 (sort {$a <=> $b} keys %{$divisions->{$size}}) {
push @$divisions_sorted, @{ $divisions->{$size}{$y0} };
}
}
return $divisions_sorted;
}
}
sub make_divisions {
my ($blocks,$param_path,$min,$max,$r0,$r1) = @_;
return unless $blocks;
if(defined $min && defined $max) {
} elsif (defined $r0 && defined $r1) {
$min = $r0;
$max = $r1;
} else {
return;
}
my $divisions;
for my $block (make_list($blocks)) {
my @pp = ($block, @$param_path);
next if hide(@pp);
# positions to skip
my @skip = parse_position( seek_parameter("position_skip",@pp),\@pp,$min,$max);
my %skip = map { $_=>1 } @skip;
# specific positions
my @pos = parse_position( seek_parameter("position",@pp),\@pp,$min,$max);
# positions determined with fixed or relative spacing
my $spacing = parse_value(seek_parameter("spacing",@pp),$max-$min);
# optional y start/end values
my $ystart = parse_value(seek_parameter("y0",@pp),$min,$max);
my $yend = parse_value(seek_parameter("y1",@pp),$min,$max);
$ystart = $min if ! defined $ystart || $ystart < $min;
$yend = $max if ! defined $yend || $yend > $max;
$block->{spacing} = $spacing;
my @posauto = parse_spacing( $spacing , \@pp, $min, $max);
my $TOL = ($spacing||0)/1000; # float roundoff causes problems without TOL
for my $pos (sort {$a <=> $b} uniq (@pos,@posauto)) {
my $skip = $skip{$pos} || $pos < $ystart - $TOL || $pos > $yend + $TOL;
printdebug_group("axis","line", $skip?" ":"+",$spacing,$pos,$block->{color});
next if $skip;
push @{$divisions->{$spacing || 0}{$pos}}, $block;
}
}
my $sorted_divisions = [];
my $seen_division;
for my $spacing (sort {$b <=> $a} keys %$divisions) {
for my $pos (sort {$a <=> $b} keys %{$divisions->{$spacing}}) {
# if this division is generated with non-zero spacing (i.e. automatic)
# only accept the first one (largest spacing).
next if $spacing && $seen_division->{$pos}++;
#printinfo($spacing,$pos,$divisions->{$spacing}{$pos}[0]{color});
push @{$sorted_divisions}, {spacing => $spacing,
pos => $pos,
block => $divisions->{$spacing}{$pos}[0]};
}
}
# division blocks
return $sorted_divisions;
}
sub parse_position {
my ($str,$pp,$min,$max) = @_;
return unless defined $str;
my @pos;
for my $p (split(/\s*$COMMA\s*/,$str)) {
$p = parse_value($p,$min,$max);
push @pos, $p;
}
return @pos;
}
sub parse_spacing {
my ($str,$pp,$min,$max) = @_;
return unless defined $str;
my $spacing = parse_value($str,$max-$min);
if($spacing) {
if(my $num_axes = ($max-$min)/$spacing > 1000) {
fatal_error("track","too_many_axes",$spacing,$num_axes);
}
} else {
return;
}
#fatal_error("track","division",$min,$max,$str) if ! $spacing;
my $ystart = first_defined(seek_parameter("y0",@$pp),$min);
my $yend = first_defined(seek_parameter("y1",@$pp),$max);
$ystart = parse_value($ystart,$max-$min);
$yend = parse_value($yend, $max-$min);
my @ypos;
my $TOL = $spacing/1000; # float roundoff causes problems without TOL
for (my $y = $min; $y <= $max + $TOL; $y += $spacing) {
next if $y < $ystart - $TOL;
last if $y > $yend + $TOL;
push @ypos, $y;
}
return @ypos;
}
################################################################
# Parse a relative value, given a range or min/max
#
# 0.1r from a range of 20
# parse_value($str,$range) -> 2
#
# 0.1r from a range 10-30
# parse_value($str,10,30) -> 12
#
# $min + parse_value($str,$max-$min) = parse_value($str,$min,$max)
#
sub parse_value {
my ($value,@range) = @_;
return if ! defined $value;
if($value =~ /(.+)r$/) {
if(@range == 2) {
my ($min,$max) = @range;
return $min + $1*($max-$min);
} elsif (@range == 1) {
my ($range) = @range;
return $1 * $range;
} else {
die "wrong number of range arguments";
}
} else {
return $value;
}
}
1;
|