~ubuntu-branches/ubuntu/utopic/circos/utopic-proposed

« back to all changes in this revision

Viewing changes to lib/Circos/URL.pm

  • Committer: Package Import Robot
  • Author(s): Olivier Sallou, Olivier Sallou, Charles Plessy, Andreas Tille
  • Date: 2012-06-14 12:56:33 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120614125633-0wh7ovv69s5k1uiq
Tags: 0.61-1
[ Olivier Sallou ]
* New upstream release

[ Charles Plessy ]
* renamed debian/upstream-metadata.yaml to debian/upstream

[ Andreas Tille ]
* debian/upstream: enhanced citation information 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Circos::URL;
 
2
 
 
3
=pod
 
4
 
 
5
=head1 NAME
 
6
 
 
7
Circos::URL - URL routines for PNG in Circos
 
8
 
 
9
=head1 SYNOPSIS
 
10
 
 
11
This module is not meant to be used directly.
 
12
 
 
13
=head1 DESCRIPTION
 
14
 
 
15
Circos is an application for the generation of publication-quality,
 
16
circularly composited renditions of genomic data and related
 
17
annotations.
 
18
 
 
19
Circos is particularly suited for visualizing alignments, conservation
 
20
and intra and inter-chromosomal relationships. However, Circos can be
 
21
used to plot any kind of 2D data in a circular layout - its use is not
 
22
limited to genomics. Circos' use of lines to relate position pairs
 
23
(ribbons add a thickness parameter to each end) is effective to
 
24
display relationships between objects or positions on one or more
 
25
scales.
 
26
 
 
27
All documentation is in the form of tutorials at L<http://www.circos.ca>.
 
28
 
 
29
=cut
 
30
 
 
31
# -------------------------------------------------------------------
 
32
 
 
33
use strict;
 
34
use warnings;
 
35
 
 
36
use base 'Exporter';
 
37
our @EXPORT = qw(
 
38
format_url
 
39
);
 
40
 
 
41
use Carp qw( carp confess croak );
 
42
use FindBin;
 
43
use GD;
 
44
use Params::Validate qw(:all);
 
45
 
 
46
use lib "$FindBin::RealBin";
 
47
use lib "$FindBin::RealBin/../lib";
 
48
use lib "$FindBin::RealBin/lib";
 
49
 
 
50
use Circos::Configuration;
 
51
#use Circos::Colors;
 
52
use Circos::Constants;
 
53
use Circos::Debug;
 
54
use Circos::Error;
 
55
#use Circos::Image qw(!draw_line);
 
56
use Circos::Utils;
 
57
 
 
58
use Memoize;
 
59
 
 
60
for my $f ( qw ( ) ) {
 
61
  memoize($f);
 
62
}
 
63
 
 
64
sub format_url {
 
65
  # given a url (although the function can be applied to any string)
 
66
  # replace all instances of [PARAM] with the value of the parameter
 
67
  # named PARAM extracted from the elements passed in the param_path
 
68
  #
 
69
  # e.g. format_url(url=>"www.domain.com/param=[ID]",param_path=>[$datum,$data]);
 
70
  my %args        = @_;
 
71
  my $delim_left  = "\Q[\E";
 
72
  my $delim_right = "\Q]\E";
 
73
  my $url         = $args{url};
 
74
  return unless defined $url;
 
75
  my $ignore_param;
 
76
  while ($url =~ /$delim_left([^$delim_right$delim_left]+)$delim_right/g) {
 
77
    my $param = $1;
 
78
    my $value;
 
79
                if(exists $args{param_path}[0]{data}[0] && 
 
80
                                         defined $args{param_path}[0]{data}[0]{$param}) {
 
81
                        $value = $args{param_path}[0]{data}[0]{$param};
 
82
                } else {
 
83
                        $value = seek_parameter($param,@{$args{param_path}});
 
84
                }
 
85
    printdebug_group("url","format_url",$url,$1,$value);
 
86
    if (! defined $value) {
 
87
      if ($CONF{image}{image_map_missing_parameter} eq "exit") {
 
88
                                fatal_error("map","url_param_not_set",$url,$param);
 
89
      } elsif ($CONF{image}{image_map_missing_parameter} =~ /removeurl/) {
 
90
                                # there is no value for this parameter, so return an empty url
 
91
                                return undef;
 
92
      } elsif ($CONF{image}{image_map_missing_parameter} =~ /ignoreparam/) {
 
93
                                $ignore_param->{$param}++;
 
94
      } elsif ($CONF{image}{image_map_missing_parameter} =~ /removeparam/ || 1) {
 
95
                                printdumper($args{param_path});exit;
 
96
                                # not defined - removeparam by default
 
97
                                error("warning","general","You have tried to use the URL $url for an image map, but the parameter in the url [$param] has no value defined for this data point or data set. This parameter is being removed from the URL of this element. Use the image_map_missing_parameter setting in the <image> block to adjust this behaviour.");
 
98
                                $url =~ s/$delim_left$param$delim_right//g;
 
99
      }
 
100
    } else {
 
101
                        $url =~ s/$delim_left$param$delim_right/$value/g;
 
102
    }
 
103
  }
 
104
  printdebug_group("url","format_url_done",$url);
 
105
  return $url;
 
106
}
 
107
 
 
108
1;