| 1 | package Bio::Graphics::Glyph::heterogeneous_segments; | ||
| 2 | |||
| 3 | # this glyph acts like graded_segments but the bgcolor of each segment is | ||
| 4 | # controlled by the source field of the feature. Use the source field name | ||
| 5 | # to set the background color: | ||
| 6 | # -waba_strong_color => 'blue' | ||
| 7 | # -waba_weak_color => 'red' | ||
| 8 | # -waba_coding_color => 'green' | ||
| 9 | |||
| 10 | use strict; | ||
| 11 | use base qw(Bio::Graphics::Glyph::graded_segments); | ||
| 12 | |||
| 13 | sub my_description { | ||
| 14 | return <<END; | ||
| 15 | This glyph acts like graded_segments but the bgcolor of each segment (sub-feature) | ||
| 16 | can be individually set using the source field of the feature. | ||
| 17 | |||
| 18 | Each segment type color is specified using the following nomenclature: | ||
| 19 | |||
| 20 | -{source}_color => \$color | ||
| 21 | |||
| 22 | For example, if the feature consists of a gene containing both | ||
| 23 | confirmed and unconfirmed exons, you can make the confirmed exons | ||
| 24 | green and the unconfirmed ones red this way: | ||
| 25 | |||
| 26 | -confirmed_color => 'green', | ||
| 27 | -unconfirmed_color => 'red' | ||
| 28 | END | ||
| 29 | } | ||
| 30 | |||
| 31 | # override draw method to calculate the min and max values for the components | ||
| 32 | sub draw { | ||
| 33 | my $self = shift; | ||
| 34 | |||
| 35 | # bail out if this isn't the right kind of feature | ||
| 36 | # handle both das-style and Bio::SeqFeatureI style, | ||
| 37 | # which use different names for subparts. | ||
| 38 | my @parts = $self->parts; | ||
| 39 | @parts = $self if !@parts && $self->level == 0; | ||
| 40 | return $self->SUPER::draw(@_) unless @parts; | ||
| 41 | |||
| 42 | @parts = $self->merge_parts(@parts) if $self->option('merge_parts'); | ||
| 43 | |||
| 44 | # figure out the colors | ||
| 45 | $self->{source2color} ||= {}; | ||
| 46 | my $fill = $self->bgcolor; | ||
| 47 | for my $part (@parts) { | ||
| 48 | my $s = eval { $part->feature->source_tag } or next; | ||
| 49 | $self->{source2color}{$s} ||= $self->color(lc($s)."_color") || $fill; | ||
| 50 | $part->{partcolor} = $self->{source2color}{$s}; | ||
| 51 | } | ||
| 52 | |||
| 53 | $self->Bio::Graphics::Glyph::segments::draw(@_); | ||
| 54 | } | ||
| 55 | |||
| 56 | |||
| 57 | # synthesize a key glyph | ||
| 58 | sub keyglyph { | ||
| 59 | my $self = shift; | ||
| 60 | |||
| 61 | my $scale = 1/$self->scale; # base pairs/pixel | ||
| 62 | |||
| 63 | # two segments, at pixels 0->50, 60->80 | ||
| 64 | my $offset = $self->panel->offset; | ||
| 65 | |||
| 66 | my $feature = | ||
| 67 | Bio::Graphics::Feature->new( | ||
| 68 | -segments=>[ [ 0*$scale +$offset,25*$scale+$offset], | ||
| 69 | [ 25*$scale +$offset,50*$scale+$offset], | ||
| 70 | [ 50*$scale+$offset, 75*$scale+$offset] | ||
| 71 | ], | ||
| 72 | -name => $self->option('key'), | ||
| 73 | -strand => '+1'); | ||
| 74 | my @sources = grep {/_color$/} $self->factory->options; | ||
| 75 | foreach (@sources) {s/_color$//} | ||
| 76 | ($feature->segments)[0]->source_tag($sources[1]); | ||
| 77 | ($feature->segments)[1]->source_tag($sources[0]); | ||
| 78 | ($feature->segments)[2]->source_tag($sources[2]); | ||
| 79 | my $factory = $self->factory->clone; | ||
| 80 | $factory->set_option(label => 1); | ||
| 81 | $factory->set_option(bump => 0); | ||
| 82 | $factory->set_option(connector => 'solid'); | ||
| 83 | my $glyph = $factory->make_glyph(0,$feature); | ||
| 84 | return $glyph; | ||
| 85 | } | ||
| 86 | |||
| 87 | 1; | ||
| 88 | |||
| 89 | =head1 NAME | ||
| 90 | |||
| 91 | Bio::Graphics::Glyph::heterogeneous_segments - The "heterogeneous_segments" glyph | ||
| 92 | |||
| 93 | =head1 SYNOPSIS | ||
| 94 | |||
| 95 | See L<Bio::Graphics::Panel> and L<Bio::Graphics::Glyph>. | ||
| 96 | |||
| 97 | =head1 DESCRIPTION | ||
| 98 | |||
| 99 | This glyph acts like graded_segments but the bgcolor of each segment (sub-feature) | ||
| 100 | can be individually set using the source field of the feature. | ||
| 101 | |||
| 102 | Each segment type color is specified using the following nomenclature: | ||
| 103 | |||
| 104 | -{source}_color => $color | ||
| 105 | |||
| 106 | For example, if the feature consists of a gene containing both | ||
| 107 | confirmed and unconfirmed exons, you can make the confirmed exons | ||
| 108 | green and the unconfirmed ones red this way: | ||
| 109 | |||
| 110 | -confirmed_color => 'green', | ||
| 111 | -unconfirmed_color => 'red' | ||
| 112 | |||
| 113 | =head2 OPTIONS | ||
| 114 | |||
| 115 | The following options are standard among all Glyphs. See | ||
| 116 | L<Bio::Graphics::Glyph> for a full explanation. | ||
| 117 | |||
| 118 | Option Description Default | ||
| 119 | ------ ----------- ------- | ||
| 120 | |||
| 121 | -fgcolor Foreground color black | ||
| 122 | |||
| 123 | -outlinecolor Synonym for -fgcolor | ||
| 124 | |||
| 125 | -bgcolor Background color turquoise | ||
| 126 | |||
| 127 | -fillcolor Synonym for -bgcolor | ||
| 128 | |||
| 129 | -linewidth Line width 1 | ||
| 130 | |||
| 131 | -height Height of glyph 10 | ||
| 132 | |||
| 133 | -font Glyph font gdSmallFont | ||
| 134 | |||
| 135 | -connector Connector type 0 (false) | ||
| 136 | |||
| 137 | -connector_color | ||
| 138 | Connector color black | ||
| 139 | |||
| 140 | -label Whether to draw a label 0 (false) | ||
| 141 | |||
| 142 | -description Whether to draw a description 0 (false) | ||
| 143 | |||
| 144 | -hilite Highlight color undef (no color) | ||
| 145 | |||
| 146 | =head1 BUGS | ||
| 147 | |||
| 148 | Please report them. | ||
| 149 | |||
| 150 | =head1 SEE ALSO | ||
| 151 | |||
| 152 | L<Bio::Graphics::Panel>, | ||
| 153 | L<Bio::Graphics::Glyph>, | ||
| 154 | L<Bio::Graphics::Glyph::arrow>, | ||
| 155 | L<Bio::Graphics::Glyph::cds>, | ||
| 156 | L<Bio::Graphics::Glyph::crossbox>, | ||
| 157 | L<Bio::Graphics::Glyph::diamond>, | ||
| 158 | L<Bio::Graphics::Glyph::dna>, | ||
| 159 | L<Bio::Graphics::Glyph::dot>, | ||
| 160 | L<Bio::Graphics::Glyph::ellipse>, | ||
| 161 | L<Bio::Graphics::Glyph::extending_arrow>, | ||
| 162 | L<Bio::Graphics::Glyph::generic>, | ||
| 163 | L<Bio::Graphics::Glyph::graded_segments>, | ||
| 164 | L<Bio::Graphics::Glyph::heterogeneous_segments>, | ||
| 165 | L<Bio::Graphics::Glyph::line>, | ||
| 166 | L<Bio::Graphics::Glyph::pinsertion>, | ||
| 167 | L<Bio::Graphics::Glyph::primers>, | ||
| 168 | L<Bio::Graphics::Glyph::rndrect>, | ||
| 169 | L<Bio::Graphics::Glyph::segments>, | ||
| 170 | L<Bio::Graphics::Glyph::ruler_arrow>, | ||
| 171 | L<Bio::Graphics::Glyph::toomany>, | ||
| 172 | L<Bio::Graphics::Glyph::transcript>, | ||
| 173 | L<Bio::Graphics::Glyph::transcript2>, | ||
| 174 | L<Bio::Graphics::Glyph::translation>, | ||
| 175 | L<Bio::Graphics::Glyph::triangle>, | ||
| 176 | L<Bio::DB::GFF>, | ||
| 177 | L<Bio::SeqI>, | ||
| 178 | L<Bio::SeqFeatureI>, | ||
| 179 | L<Bio::Das>, | ||
| 180 | L<GD> | ||
| 181 | |||
| 182 | =head1 AUTHOR | ||
| 183 | |||
| 184 | Lincoln Stein E<lt>lstein@cshl.orgE<gt> | ||
| 185 | |||
| 186 | Copyright (c) 2001 Cold Spring Harbor Laboratory | ||
| 187 | |||
| 188 | This library is free software; you can redistribute it and/or modify | ||
| 189 | it under the same terms as Perl itself. See DISCLAIMER.txt for | ||
| 190 | disclaimers of warranty. | ||
| 191 | |||
| 192 | =cut |