Bio-Graphics

 view release on metacpan or  search on metacpan

lib/Bio/Graphics/Glyph/wiggle_xyplot.pm  view on Meta::CPAN

package Bio::Graphics::Glyph::wiggle_xyplot;

use strict;
use base qw(Bio::Graphics::Glyph::wiggle_data
            Bio::Graphics::Glyph::xyplot 
            Bio::Graphics::Glyph::smoothing);
use IO::File;
use File::Spec;

sub my_description {
    return <<END;
This glyph draws quantitative data as an xyplot. It is designed to be
used in conjunction with features in "wiggle" format as generated by
Bio::Graphics::Wiggle, base pair coverage data generated by the
Bio::DB::Sam module, or interval statistical_summaries generated by 
the Bio::DB::BigWig module.

For this glyph to work, the feature must define one of the following tags
or methods:

  wigfile -- a path to a Bio::Graphics::Wiggle file

  wigdata -- Wiggle data in the Bio::Graphics::Wiggle "wif" format, as created
             by \$wig->export_to_wif().

  coverage-- a simple comma-delimited string containing the quantitative values,
             assumed to be one value per pixel.

  statistical_summary() -- a method for generating statistical information 
             including validCount, maxVal, minVal, sumData, and sumSquares.
END
}

sub my_options {
    {
	basedir => [
	    'string',
	    undef,
	    'If a relative path is used for "wigfile", then this option provides',
	    'the base directory on which to resolve the path.'
	    ],
	variance_band => [
	    'boolean',
	    0,
	    'If true, draw a semi-transparent band across the image that indicates',
	    'the mean and standard deviation of the data set. Only of use when a wig',
	    'file is provided.'
        ],
	z_score_bounds => [
	    'integer',
            4,
	    'When using z_score autoscaling, this option controls how many standard deviations',
	    'above and below the mean to show.'
	],
	autoscale => [
	    ['local','chromosome','global','z_score','clipped_global'],
            'clipped_global',
	    'If set to "global" , then the minimum and maximum values of the XY plot',
	    'will be taken from the wiggle file as a whole. If set to "chromosome", then',
            'scaling will be to minimum and maximum on the current chromosome.',
	    '"clipped_global" is similar to "global", but clips the top and bottom values',
	    'to the multiples of standard deviations indicated by "z_score_bounds"',
	    'If set to "z_score", then the whole plot will be rescaled to z-scores in which',
	    'the "0" value corresponds to the mean across the genome, and the units correspond',
	    'to standard deviations above and below the mean. The number of SDs to show are',
	    'controlled by the "z_score_bound" option.',
	    'Otherwise, the plot will be',
	    'scaled to the minimum and maximum values of the region currently on display.',
	    'min_score and max_score override autoscaling if one or both are defined'
        ],
    interval_method => [
    	['mean', 'sum', 'min', 'max'],
    	'mean',
    	'When working with features that offer a statistical_summary() method,',
    	'such as those from Bio::DB::BigWig, define the method for reporting',
    	'scores within each interval.',
    ],
    };
}

# Added pad_top subroutine (pad_top of Glyph.pm, which is called when executing $self->pad_top
# returns 0, so we need to override it here)
sub pad_top { shift->Bio::Graphics::Glyph::xyplot::pad_top(@_) }

sub pad_left {
    my $self = shift;
    my $pad  = $self->SUPER::pad_left(@_);
    return $pad unless $self->option('variance_band');
    $pad    += length('+1sd')/2 * $self->font('gdTinyFont')->width+3;
    return $pad;
}

sub clip_color {
    my $self = shift;
    return $self->translate_color('orange');
}

# we override the draw method so that it dynamically creates the parts needed
# from the wig file rather than trying to fetch them from the database

# sub draw() { } is now mostly in wiggle_data.pm 
sub draw {
  my $self = shift;
  my ($gd,$dx,$dy) = @_;
  my $result = $self->Bio::Graphics::Glyph::wiggle_data::draw(@_);



( run in 1.074 second using v1.01-cache-2.11-cpan-39bf76dae61 )