blib/script/contig_draw.pl untested

filter: Statementstmt 0.0% 0 / 71 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 97 CC 3 SCAR 12.0
CC
3
Cov
0%
MAX
6.0
MIN
6.0
BEGIN
2.0
CRAP 3.3
1 #!/usr/local/bin/perl -w
2  
3 =head1 NAME
4  
5 search_overview -- Render a SearchIO parser report into a simple overview graphic
6  
7 =head1 SYNOPSIS
8  
9 search_overview -i filename [-f format] [-o outputfilename] [--labels]
10  
11 =head1 DESCRIPTION
12  
13 This script will take any Bio::SearchIO parseable report and turn it
14 into a simple overview graphic of the report. For our purposes we are
15 assuming BLAST and the BLAST scores when assigning colors. Output is
16 a PNG format file.
17  
18 This is not intended to be an overly customized script, rather it
19 should probably just be either a quick and dirty look at a report or a
20 starting point for more complicated implementations.
21  
22 The color is determined by the hit score which is currently pegged to the NCBI
23 scheme which looks like this
24  
25 RED E<gt>= 200
26 PURPLE 80-200
27 GREEN 50-80
28 BLUE 40-50
29 BLACK E<lt>40
30  
31 Options:
32 -i/--input The input filename, otherwise input is assumed from STDIN
33 -o/--output The output filename, this is optional, if you do not
34 provide the output filename the script will create a file
35 using the name of the query sequence and will process
36 all the sequences in the file. If an output filename
37 IS provided the script will only display an image for the
38 first one.
39 -f/--format The SearchIO format parser to use, if not provided
40 SearchIO will guess based on the file extension.
41 -l/--labels Display the hit sequence name as a label in the overview.
42 For lots of sequences this will make the image very long
43 so by default it is turned off.
44  
45 =head1 AUTHOR Jason Stajich
46  
47 Jason Stajich, jason[-at-]open-bio[-dot-]org.
48  
49 =cut
50  
51 use strict;
52  
53 use Bio::Graphics::Panel;
54 use Bio::Graphics::Feature;
55 use Bio::Graphics::FeatureFile;
56 use Bio::Assembly::IO;
57 use Getopt::Long;
58 use Dumpvalue();
59 my $dumper = new Dumpvalue();
60  
61 use constant WIDTH => 600; # default width
62  
63 my ($in,$format,$out);
64  
65 my $showlabels = 0;
66  
67 # This defines the color order
68 # For NCBI it is typically defined like this
69 # Score
70 # RED >= 200
71 # PURPLE 80-200
72 # GREEN 50-80
73 # BLUE 40-50
74 # BLACK <40
75 my @COLORS = qw(red magenta green blue black);
76 my @SCORES = (200,80,50,40,0);
77  
78 GetOptions(
79 'i|in|input:s' => \$in,
80 'f|format:s' => \$format,
81 'o|output:s' => \$out,
82 'l|labels' => \$showlabels
83 );
84  
85 if (!$in) {
86 $in = "../../t/data/acefile.ace.1";
87 # $in = "../../t/data/consed_project/edit_dir/test_project.fasta.screen.ace.1";
88 }
89 if (!$out) {
90 $out = "web/contig.png";
91 }
92 print("Parsing this file: ($in)\n");
93 my $parser = new Bio::Assembly::IO(-file => $in );
94 my $ass = $parser->next_assembly();
95  
96 my @contigs = $ass->all_contigs();
97  
98 # for demo purposes, just work on the first contig
99 my $contig = pop(@contigs);
100  
101 my (@sequences,@features,@configs);
102  
103 # get the consensus sequence
104 my $cs = $contig->get_consensus_sequence();
105 print STDERR "Adding a consensus with start(".$cs->start().") and end(".$cs->end().")\n";
106 $cs->display_name("Consensus sequence(".$cs->start().",".length($cs->seq()).")");
107 my $min = $cs->start();
108 my $max = $cs->end();
109 push @features, $cs;
110 $dumper->dumpValue($cs);
111 # now get the things in this contig
112 foreach my $feat ($contig->each_seq()) {
113 print STDERR "Adding a member with name(".$feat->display_id().") start(".$feat->start().") and end(".$feat->end().")\n";
114 print(ref($feat)."\n");
115 # $dumper->dumpValue($feat) ;
116 # my @fs = $feat->get_all_tags();
117 # print("These are the seqfeatures:\n");
118 # $dumper->dumpValue(\@fs);
119 # my @tag_values = $feat->get_tag_values('contig');
120 # my $locatable_seq = $feat->get_tag_values('contig');
121 # print("These are the tagged values:\n");
122 # $dumper->dumpValue(\@tag_values);
123 # help bioperlers! how do i not do this:
124 push @features, $feat;
125 $min = &MIN($min,$feat->start());
126 $max = &MAX($max,$feat->end());
127 $feat->display_name($feat->display_name()."(".$feat->start().",".$feat->end().")");
128 }
129 my $panel = Bio::Graphics::Panel->new(
130 -length => 2000,
131 -width => 900,
132 -bgcolor => 'white',
133 -pad_left=> 10,
134 -pad_right=> 10);
135 $panel->add_track('arrow' => Bio::Graphics::Feature->new
136 (-start => 0,
137 -end => $max-$min + 100 ),
138 -bump => 0,
139 -double => 1,
140 -tick => 2,
141 );
142 # my $invisible_track = $panel->add_track(-glyph => '');
143 # $invisible_track->add_feature(new Bio::SeqFeature::Generic(-start => $min-500, -end => $max+500));
144 my $track = $panel->add_track(-glyph => 'generic',-label => 1);
145 foreach my $f ( @features ) {
146 my $newfeat = new Bio::SeqFeature::Generic(-start => $f->start()-$min ,
147 -end => $f->end()-$min,
148 -display_name => $f->display_name());
149 $track->add_feature($newfeat);
150 }
151 if( $out ) {
152 open(OUT,">$out") || die("cannot open $out: $!");
153 binmode(OUT);
154 print OUT $panel->png;
155 close(OUT);
156 } else {
157 open(OUT, ">$out.png") || die("$out: $!");
158 binmode(OUT);
159 print OUT $panel->png;
160 close(OUT);
161 }
162
163 sub MAX {return $_[0] < $_[1] ? $_[1] : $_[0] }
164 sub MIN {return $_[0] > $_[1] ? $_[1] : $_[0] }