10 use vars qw( $USAGE %VALIDFORMATS);
12 %VALIDFORMATS = ( 'png' => 1,
19 $USAGE = "usage:\tchaos_plot -i/--input=INPUTFILE -f/--format=SEQFORMAT \n".
20 "\t-o/--output=OUTPUTFILE -g/--graphics=GRAPHIC TYPE\n".
21 "\t-w/--width=600 -h/--height=400\n";
23 $USAGE .= "\tValid graphics formats: (" . join(",", ( keys %VALIDFORMATS )) .")\n";
24 $USAGE .= "\tImage size defaults to 600x400, SEQFORMAT to fasta\n";
25 $USAGE .= "\tINPUTFILE can also be read from STDIN\n";
27 my ($format,$graph,$width,$height,$seqfile,$output) = ('fasta', 'png', 600, 400);
28 GetOptions( "i|input:s" => \$seqfile,
29 "f|format:s" => \$format,
30 "o|output:s" => \$output,
31 "g|graph|graphics:s" => \$graph,
33 "height:i" => \$height
36 if( ! $output || ! $VALIDFORMATS{$graph} ) {
40 $seqfile = shift unless $seqfile;
41 if( defined $seqfile ) {
42 print "Could not open file [$seqfile]\n$USAGE" and exit unless -e $seqfile;
43 $seqin = new Bio::SeqIO(-format => $format,
46 $seqin = new Bio::SeqIO(-format => $format,
50 my $img = new GD::Image($width,$height);
51 my $white = $img->colorAllocate(255,255,255);
52 my $black = $img->colorAllocate(0,0,0);
54 my $seq = $seqin->next_seq;
55 die("Sequence type must be DNA not " . $seq->alphabet())
56 unless $seq->alphabet ne 'dna' or $seq->alphabet ne 'rna';
58 my $len = $seq->length();
61 my ($x,$y) = ( 0.5, 0.5);
62 $img->string(gdGiantFont, 1,1, 'A', $black);
63 $img->string(gdGiantFont, 0,$height - 15, 'C', $black);
64 $img->string(gdGiantFont, $width - 15,1, 'T', $black);
65 $img->string(gdGiantFont, $width - 15,$height -20, 'G', $black);
67 for( my $i = 1; $i <= $len; $i++ ) {
69 my $base = lc $seq->subseq($i,$i);
73 } elsif ( $base eq 'g' ) {
74 $x = ( $x + 1.0 ) * 0.5;
75 $y = ( $y + 1.0 ) * 0.5;
76 } elsif ( $base eq 'c' ) {
78 $y = ( $y + 1.0 ) * 0.5;
79 } elsif ( $base eq 't' or $base eq 'u' ) {
80 $x = ( $x + 1.0 ) * 0.5;
84 $img->setPixel($x * $width,$y * $height, $black);
86 open(OUT, ">$output");
88 $graph =~ s/jpg/jpeg/;
90 print OUT $img->$graph();
97 bp_chaos_plot - a chaos plot from DNA and RNA sequences
101 bp_chaos_plot.pl -i/--input=INPUTFILE -f/--format=SEQFORMAT
102 -o/--output=OUTPUTFILE -g/--graphics=GRAPHIC FORMAT
103 -w/--width=WIGHT -h/--height=HEIGHT
107 This scripts generates image files using GD image library to visualize
108 nucleotide sequences using chaos plot.
112 Valid graphics formats are currently gd, gd2, png, wbmp, jpeg and gif.
114 The default size of the image file is 600x400.
116 The sequence input can be provided using any of the three methods:
120 =item unnamed argument
122 bp_chaos_plot filename
126 bp_chaos_plot -i filename
130 bp_chaos_plot < filename
138 User feedback is an integral part of the evolution of this and other
139 Bioperl modules. Send your comments and suggestions preferably to
140 the Bioperl mailing list. Your participation is much appreciated.
142 bioperl-l@bioperl.org - General discussion
143 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
145 =head2 Reporting Bugs
147 Report bugs to the Bioperl bug tracking system to help us keep track
148 of the bugs and their resolution. Bug reports can be submitted via the
151 https://redmine.open-bio.org/projects/bioperl/
153 =head1 AUTHOR - Jason Stajich
155 Email jason@bioperl.org
159 This code is based on EMBOSS C code for chaos.c by Ian Longden.
160 Included are documentation from EMBOSS code:
162 Chaos produces a chaos plot. The original application is part of the
163 ACEDB genome database package, written by ** Richard Durbin (MRC LMB,
164 UK) rd@mrc-lmba.cam.ac.uk, and Jean Thierry-Mieg (CRBM du CNRS,
165 France) mieg@crbm1.cnusc.fr