maint: remove Travis stuff which has been replaced with Github actions (#325)
[bioperl-live.git] / examples / quality / svgtrace.pl
blobd3c3fc907f5fe222b4af2432cf39160a0c72fa80
1 #! /usr/bin/perl
3 use warnings;
4 use strict;
5 use Bio::SeqIO;
6 use SVG;
8 my $USAGE = <<END_USAGE;
9 $0 <file>
11 This simple example script reads the ABI data and uses the trace data to
12 generate a SVG-formatted chromatogram. Requires the CPAN SVG module and
13 Bio::SeqIO::staden::read (from bioperl-ext), which itself requires io_lib from
14 the Staden package.
16 END_USAGE
18 my $file = shift || die $USAGE;
20 my $img_width = 6000;
21 my $img_height = 200;
23 my $svg = SVG->new(width => $img_width, height => $img_height, xmlns => "http://www.w3.org/2000/svg");
25 my $seq_io = Bio::SeqIO->new( -file => $file, -format => 'abi', -get_trace_data => 1);
27 my $seq = $seq_io->next_seq;
29 my $points = scalar($seq->get_trace_graph( -trace => 'a' ));
31 my @xdata = map { $_ / $points * $img_width } (0..$points-1);
33 my %colours = ( 'a' => 'green', 'c' => 'blue', 'g' => 'black', 't' => 'red' );
34 foreach my $element ('a', 'c', 'g', 't')
36 my @trace = $seq->get_trace_graph( -trace => $element, -scale => $img_height);
37 @trace = map { $img_height - $_ } @trace;
38 my $points = $svg->get_path(-type => 'polyline', -closed => 0, x => \@xdata, y => \@trace);
39 $svg->polyline(%$points, id=> $element, 'stroke-width' => 0.5, stroke => $colours{$element}, 'fill-opacity' => 0, 'fill' => 'white');
42 my $count = 0;
43 my $text_group = $svg->group( id => 'text_layer');
44 foreach my $base_loc (@{$seq->trace})
46 $text_group->text(x => ($base_loc / $points * $img_width), y => 50, 'text-anchor' => 'middle', fill => 'black', 'font-size' => '5pt')->cdata(substr($seq->seq,$count,1));
47 ++$count;
50 print $svg->xmlify();