A chromosome class for scaffold-based chromosomes.
[cview.git] / lib / CXGN / Cview / IL.pm
blob5f92ea42bb1e47ef4486a506e293584e19434e27
3 =head1 NAME
5 CXGN::Cview::IL - a class for drawing Isogenic Line (IL) diagrams
7 =head1 DESCRIPTION
9 Inherits from L<CXGN::Cview::Chromosome>.
11 =head1 SEE ALSO
13 See also the documentation in L<CXGN::Cview>.
15 =head1 AUTHOR(S)
17 Lukas Mueller (lam87@cornell.edu)
19 =head1 FUNCTIONS
22 =cut
26 use strict;
27 use CXGN::Cview::Chromosome;
29 package CXGN::Cview::IL;
31 use base qw( CXGN::Cview::Chromosome );
33 sub new {
34 my $class = shift;
35 my $self = $class->SUPER::new(@_);
36 $self->{sections}=();
37 $self->{fragments} =();
38 return $self;
41 sub add_section {
42 # sections are the non-overlapping sections of the ILs that have labels of the form 1-A
43 my $self=shift;
44 my $section_name = shift;
45 my $marker1 = shift;
46 my $offset1 = shift;
47 my $marker2 = shift;
48 my $offset2 = shift;
51 my %section = ();
52 $section{marker1}=$marker1;
53 $section{offset1}=$offset1;
54 $section{marker2}=$marker2;
55 $section{offset2}=$offset2;
56 $section{name}=$section_name;
57 $section{label_position} = 0;
58 push @{$self->{sections}}, \%section;
63 sub add_fragment {
64 # fragments are the overlapping sections defining the different IL lines and have lables of the form IL1-1.
65 my $self=shift;
66 my $fragment_name=shift;
67 my $marker1=shift;
68 my $offset1 = shift;
69 my $marker2 = shift;
70 my $offset2 = shift;
72 my %fragment = ();
73 $fragment{marker1}=$marker1;
74 $fragment{offset1}=$offset1;
75 $fragment{marker2}=$marker2;
76 $fragment{offset2}=$offset2;
77 $fragment{name}=$fragment_name;
78 $fragment{label_position} = 0;
79 push @{$self->{fragments}}, \%fragment;
83 sub render {
84 my $self=shift;
85 my $image = shift;
87 $self->_calculate_scaling_factor();
88 $self->_calculate_chromosome_length();
89 $self-> set_color(100,100,100);
91 $self->{font}= GD::Font->Small();
92 my $section_x = $self->get_horizontal_offset() - $self->get_width()/2;
94 my $color = $image -> colorResolve($self->{color}[0], $self->{color}[1], $self->{color}[2]);
95 my $light_color = $image -> colorResolve(200, 200, 200);
97 # render sections
99 my $previous_label_position = 0;
100 my $line = 1;
101 my $spacing = 7;
104 foreach my $s (@{$self->{sections}}) {
105 my $y_start = $self->get_vertical_offset()+$self->mapunits2pixels($$s{offset1});
106 my $y_end = $self->get_vertical_offset()+$self->mapunits2pixels($$s{offset2 });
109 $image -> line($section_x - 10, $y_start, $section_x + @{$self->{fragments}}*$spacing, $y_start, $light_color);
110 $image -> line($section_x - 10, $y_end, $section_x + @{$self->{fragments}}*$spacing, $y_end, $light_color);
111 $image -> line($section_x, $y_start, $section_x, $y_end, $color);
112 $image -> string($self->{font}, $section_x - $self->{font}->width()* length($$s{name})-2, ($y_end + $y_start)/2-$self->{font}->height()/2, $$s{name}, $color);
116 # render fragments
118 if (!defined($self->{fragments})) { warn "IL: no fragments to render.\n"; return; }
119 my $max_fragments = @{$self->{fragments}};
121 foreach my $f (@{$self->{fragments}}) {
122 my $y_start = $self->get_vertical_offset()+$self->mapunits2pixels($$f{offset1});
123 my $y_end = $self->get_vertical_offset()+$self->mapunits2pixels($$f{offset2 });
125 my $label_position = ($y_end+$y_start)/2;
126 if ($label_position < ($previous_label_position+$self->{font}->height())) { $label_position = $previous_label_position + $self->{font}->height(); }
128 $image -> line($section_x+$line*$spacing, $y_start, $section_x+$line*$spacing, $y_end,$color);
129 $image -> line($section_x+$line*$spacing+1, $y_start, $section_x+$line*$spacing+1, $y_end, $color);
130 $image -> string($self->{font}, $section_x +$max_fragments*$spacing+3, $label_position-$self->{font}->height()/2, $$f{name}, $color);
131 $image -> line($section_x+$line*$spacing, ($y_end+$y_start)/2, $section_x+$max_fragments*$spacing+3, $label_position, $color);
132 $line++;
133 $previous_label_position = $label_position;