~ubuntu-branches/ubuntu/trusty/bioperl/trusty

« back to all changes in this revision

Viewing changes to scripts/seqstats/chaos_plot.PLS

  • Committer: Package Import Robot
  • Author(s): Charles Plessy
  • Date: 2013-09-22 13:39:48 UTC
  • mfrom: (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20130922133948-c6z62zegjyp7ztou
Tags: 1.6.922-1
* New upstream release.
* Replaces and Breaks grinder (<< 0.5.3-3~) because of overlaping contents.
  Closes: #722910
* Stop Replacing and Breaking bioperl ( << 1.6.9 ): not needed anymore. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!perl -w
2
 
 
3
 
use strict;
4
 
 
5
 
use Bio::SeqIO;
6
 
use Getopt::Long;
7
 
use GD;
8
 
 
9
 
use vars qw( $USAGE %VALIDFORMATS);
10
 
 
11
 
%VALIDFORMATS = ( 'png'  => 1,
12
 
                  'jpeg' => 1,
13
 
                  'gd2'  => 1,
14
 
                  'gd'   => 1,
15
 
                  'gif'  => 1,
16
 
                  'wbmp' => 1 );
17
 
 
18
 
$USAGE = "usage:\tchaos_plot -i/--input=INPUTFILE -f/--format=SEQFORMAT \n".
19
 
    "\t-o/--output=OUTPUTFILE -g/--graphics=GRAPHIC TYPE\n".
20
 
    "\t-w/--width=600 -h/--height=400\n";
21
 
 
22
 
$USAGE .= "\tValid graphics formats: (" . join(",", ( keys %VALIDFORMATS )) .")\n";
23
 
$USAGE .= "\tImage size defaults to 600x400, SEQFORMAT to fasta\n";
24
 
$USAGE .= "\tINPUTFILE can also be read from STDIN\n";
25
 
 
26
 
my ($format,$graph,$width,$height,$seqfile,$output) = ('fasta', 'png', 600, 400);
27
 
GetOptions( "i|input:s"           => \$seqfile,
28
 
            "f|format:s"          => \$format,
29
 
            "o|output:s"          => \$output,
30
 
            "g|graph|graphics:s"  => \$graph,
31
 
            "width:i"             => \$width,
32
 
            "height:i"            => \$height
33
 
            );
34
 
 
35
 
if( ! $output || ! $VALIDFORMATS{$graph} ) {
36
 
    die $USAGE ;
37
 
}
38
 
my $seqin;
39
 
$seqfile = shift unless $seqfile;
40
 
if( defined $seqfile ) {
41
 
    print "Could not open file [$seqfile]\n$USAGE" and exit unless -e $seqfile;
42
 
    $seqin = new Bio::SeqIO(-format => $format,
43
 
                            -file   => $seqfile);
44
 
} else {
45
 
    $seqin = new Bio::SeqIO(-format => $format,
46
 
                            -fh     => \*STDIN);
47
 
}
48
 
 
49
 
my $img = new GD::Image($width,$height);
50
 
my $white = $img->colorAllocate(255,255,255); 
51
 
my $black = $img->colorAllocate(0,0,0); 
52
 
 
53
 
my $seq = $seqin->next_seq;
54
 
die("Sequence type must be DNA not " . $seq->alphabet())
55
 
    unless $seq->alphabet ne 'dna' or $seq->alphabet ne 'rna';
56
 
my %nmerdata;
57
 
my $len = $seq->length();
58
 
my $max = 0;
59
 
 
60
 
my ($x,$y) = ( 0.5, 0.5);
61
 
$img->string(gdGiantFont, 1,1, 'A', $black);
62
 
$img->string(gdGiantFont, 0,$height - 15, 'C', $black);
63
 
$img->string(gdGiantFont, $width - 15,1, 'T', $black);
64
 
$img->string(gdGiantFont, $width - 15,$height -20, 'G', $black);
65
 
 
66
 
for( my $i = 1; $i <= $len; $i++ ) {
67
 
 
68
 
    my $base = lc $seq->subseq($i,$i);
69
 
    if( $base eq 'a' ) {
70
 
        $x *= 0.5;
71
 
        $y  *= 0.5;
72
 
    } elsif ( $base eq 'g' ) {
73
 
        $x = ( $x + 1.0 ) * 0.5;
74
 
        $y  = ( $y + 1.0  ) * 0.5; 
75
 
    } elsif ( $base eq 'c' ) {
76
 
        $x *= 0.5;
77
 
        $y  = ( $y + 1.0  ) * 0.5; 
78
 
    } elsif ( $base eq 't' or $base eq 'u' ) {
79
 
        $x = ( $x + 1.0 ) * 0.5;
80
 
        $y  *= 0.5;
81
 
    }
82
 
 
83
 
    $img->setPixel($x * $width,$y * $height, $black);
84
 
}
85
 
open(OUT, ">$output");
86
 
binmode OUT;
87
 
$graph =~ s/jpg/jpeg/;
88
 
 
89
 
print OUT $img->$graph();
90
 
 
91
 
 
92
 
__END__
93
 
 
94
 
=head1 NAME
95
 
 
96
 
chaos_plot - a chaos plot from DNA and RNA sequences
97
 
 
98
 
=head1 SYNOPSIS
99
 
 
100
 
  chaos_plot.pl -i/--input=INPUTFILE -f/--format=SEQFORMAT
101
 
        -o/--output=OUTPUTFILE -g/--graphics=GRAPHIC FORMAT
102
 
        -w/--width=WIGHT -h/--height=HEIGHT
103
 
 
104
 
=head1 DESCRIPTION
105
 
 
106
 
This scripts generates image files using GD image library to visualize
107
 
nucleotide sequences using chaos plot.
108
 
 
109
 
=head1 OPTIONS
110
 
 
111
 
Valid graphics formats are currently gd, gd2, png, wbmp, jpeg and gif.
112
 
 
113
 
The default size of the image file is 600x400.
114
 
 
115
 
The sequence input can be provided using any of the three methods:
116
 
 
117
 
=over 3
118
 
 
119
 
=item unnamed argument
120
 
 
121
 
  chaos_plot filename
122
 
 
123
 
=item named argument
124
 
 
125
 
  chaos_plot -i filename
126
 
 
127
 
=item standard input
128
 
 
129
 
  chaos_plot < filename
130
 
 
131
 
=back
132
 
 
133
 
=head1 FEEDBACK
134
 
 
135
 
=head2 Mailing Lists
136
 
 
137
 
User feedback is an integral part of the evolution of this and other
138
 
Bioperl modules. Send your comments and suggestions preferably to
139
 
the Bioperl mailing list.  Your participation is much appreciated.
140
 
 
141
 
  bioperl-l@bioperl.org                  - General discussion
142
 
  http://bioperl.org/wiki/Mailing_lists  - About the mailing lists
143
 
 
144
 
=head2 Reporting Bugs
145
 
 
146
 
Report bugs to the Bioperl bug tracking system to help us keep track
147
 
of the bugs and their resolution. Bug reports can be submitted via the
148
 
web:
149
 
 
150
 
  https://redmine.open-bio.org/projects/bioperl/
151
 
 
152
 
=head1 AUTHOR - Jason Stajich
153
 
 
154
 
Email jason@bioperl.org
155
 
 
156
 
=head1 HISTORY
157
 
 
158
 
This code is based on EMBOSS C code for chaos.c by Ian Longden.
159
 
Included are documentation from EMBOSS code:
160
 
 
161
 
Chaos produces a chaos plot.  The original application is part of the
162
 
ACEDB genome database package, written by ** Richard Durbin (MRC LMB,
163
 
UK) rd@mrc-lmba.cam.ac.uk, and Jean Thierry-Mieg (CRBM du CNRS,
164
 
France) mieg@crbm1.cnusc.fr
165
 
 
166
 
=cut
167